1、前置环境
要求环境包含JDK 1.8+和MySQ 5.6.5+
下载Apollo包(Releases · apolloconfig/apollo · GitHub)包含三个模块
adminservice :端口是8090,使用了ConfigDB
configservice:端口是8080,里面包含Meta Server,Eureka,Config Service,其中Config Service又使用了ConfigDB
portal:端口是8070,使用了PortalDB
2、部署顺序是
configservice → adminservice → portal
下图是模块间的依赖关系(网上图片):
3、创建数据库
执行Github - apolloconfigdb.sql来创建配置中心服务(Config Service)和配置管理服务(Admin Service)共用的的数据库ApolloConfigDB,并创建表以及数据。
执行Github - apolloportaldb.sql来创建管理界面服务(Portal Service)需要的数据库ApolloPortalDB,并创建表以及数据
4、创建数据库
执行Github - apolloconfigdb.sql来创建配置中心服务(Config Service)和配置管理服务(Admin Service)共用的的数据库ApolloConfigDB,并创建表以及数据。
执行Github - apolloportaldb.sql来创建管理界面服务(Portal Service)需要的数据库ApolloPortalDB,并创建表以及数据。
5、部署Config Service
- 下载、解压
echo "下载configservice" > /dev/null
wget -P ~/soft/apollo https://github.com/apolloconfig/apollo/releases/download/v1.9.1/apollo-configservice-1.9.1-github.zip
echo "创建解压目录" > /dev/null
mkdir -p /opt/soft/apollo
echo "解压到/opt/soft目录下" > /dev/null
unzip ~/soft/apollo/apollo-configservice-1.9.1-github.zip -d /opt/soft/apollo/configservice
- 修改数据库地址为ApolloConfigDB
vim /opt/soft/apollo/configservice/config/application-github.properties
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = 666666
- 启动、停止
# 启动
/opt/soft/apollo/configservice/scripts/startup.sh
# 停止
/opt/soft/apollo/configservice/scripts/shutdown.sh
6、部署Admin Service
- 下载、解压
echo "下载adminservice" > /dev/null
wget -P ~/soft/apollo https://github.com/apolloconfig/apollo/releases/download/v1.9.1/apollo-adminservice-1.9.1-github.zip
echo "创建解压目录" > /dev/null
mkdir -p /opt/soft/apollo
echo "解压到/opt/soft目录下" > /dev/null
unzip ~/soft/apollo/apollo-adminservice-1.9.1-github.zip -d /opt/soft/apollo/adminservice
- 修改数据库地址为ApolloConfigDB
vim /opt/soft/apollo/adminservice/config/application-github.properties
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = 666666
- 启动、停止
# 启动
/opt/soft/apollo/adminservice/scripts/startup.sh
# 停止
/opt/soft/apollo/adminservice/scripts/shutdown.sh
7、部署Portal Service
- 下载、解压
echo "下载portal" > /dev/null
wget -P ~/soft/apollo https://github.com/apolloconfig/apollo/releases/download/v1.9.1/apollo-portal-1.9.1-github.zip
echo "创建解压目录" > /dev/null
mkdir -p /opt/soft/apollo
echo "解压到/opt/soft目录下" > /dev/null
unzip ~/soft/apollo/apollo-portal-1.9.1-github.zip -d /opt/soft/apollo/portal
- 修改数据库地址为ApolloPortalDB
vim /opt/soft/apollo/portal/config/application-github.properties
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloPortalDB?useSSL=false&characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = 666666
- 编辑环境配置,指定某个环境地址
vim /opt/soft/apollo/portal/config/apollo-env.properties
将dev环境地址指向指定Config Service地址。
dev.meta=http://fill-in-dev-meta-server:8080
- 启动、停止
# 启动
/opt/soft/apollo/portal/scripts/startup.sh
# 停止
/opt/soft/apollo/portal/scripts/shutdown.sh
8、访问测试
通过HTTP请求http://IP:8070
来访问管理界面,默认用户名密码分别为apollo
和admin
9、多环境方案
参考服务端配置说明。配置项统一存储在ApolloPortalDB.ServerConfig表中,也可以通过管理员工具 - 系统参数
页面进行配置,无特殊说明则修改完一分钟实时生效,但是修改环境得重启Portal Service。
每个环境需要按上面的步骤各自搭建一套独立的Config Service和Admin Service,并使用独立的ConfigDB。最后再配置下面两个关键参数。
- 可支持的环境列表(apollo.portal.envs)
默认值是dev,如果portal需要管理多个环境的话,以逗号分隔即可(大小写不敏感),如:
DEV,FAT,UAT,PRO
- 各环境Meta Service列表(apollo.portal.meta.servers)
Apollo Portal需要在不同的环境访问不同的meta service(apollo-configservice)地址,所以我们需要在配置中提供这些信息。默认情况下,meta service和config service是部署在同一个JVM进程,所以meta service的地址就是config service的地址。如:
{
"DEV":"http://1.1.1.1:8080",
"FAT":"http://apollo.fat.xxx.com",
"UAT":"http://apollo.uat.xxx.com",
"PRO":"http://apollo.xxx.com"
}
10、高可用方案
搭建多套加独立的Config Service和Admin Service使用同一个ConfigDB。
在填写环境Meta Service地址的时候填多个用逗号分隔就行(如:http://IP1:8080,http://IP2:8080),但推荐通过SLB(Service Load Balancer)做动态负载均衡。
11、修改端口号和日志目录
在各模块的启动脚本(startup.sh)可以指定服务日志生成目录,和使用的端口。