Apollo分布式部署

Apollo基本概念请参考Apollo配置中心介绍


环境:

PRO: Server1:172.16.2.16      服务:  apollo-configservice | apollo-adminservice | applo-portal

FAT:  Server2:172.16.2.17     服务:  apollo-configservice | apollo-adminservice

UAT: Server3:172.16.2.18     服务:   apollo-configservice | apollo-adminservice


每个环境都要部署独立的mysql数据库,不同的数据库用于存放不同环境的同一个KEY的值。每台服务器上都要configservice和adminservice。configservice用于数据的配置管理,adminservice用于和客户端通讯,将key的值发布到客户端上


准备:

三台服务器分别安装JDK1.8,Maven3.5.0,Mysql5.7 Git1.7.1


安装:configservice和adminservice,三台服务器上都需要安装


1
2
cd  /opt 
git clone


修改build.sh脚本

Server1配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
###修改build.sh脚本,修改数据库地址和账号密码。
vim   /opt/apollo/scripts/build .sh
apollo_config_db_url=jdbc:mysql: //127 .0.0.1:3306 /ApolloConfigDB ?characterEncoding=utf8
apollo_config_db_username=root
apollo_config_db_password=123456
# apollo portal db info
apollo_portal_db_url=jdbc:mysql: //127 .0.0.1:3306 /ApolloPortalDB ?characterEncoding=utf8
apollo_portal_db_username=root
apollo_portal_db_password=123456
 
##修改三个环境的apollo服务器configservice地址
# meta server url, different environments should have different meta server addresses
dev_meta=http: //localhost :8080
fat_meta=http: //172 .16.0.17:8080
uat_meta=http: //172 .16.0.18:8080
pro_meta=http: //172 .16.0.16:8080

注意:只有部署了apollo-portal服务的服务器上需要将所有环境的地址写上去,其他环境的不用,比如


Server2的配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
apollo_config_db_url=jdbc:mysql: //127 .0.0.1:3306 /ApolloConfigDB ?characterEncoding=utf8
apollo_config_db_username=root
apollo_config_db_password=123456
 
# apollo portal db info
apollo_portal_db_url=jdbc:mysql: //127 .0.0.1:3306 /ApolloPortalDB ?characterEncoding=utf8
apollo_portal_db_username=root
apollo_portal_db_password=123456
 
# meta server url, different environments should have different meta server addresses
dev_meta=http: //localhost :8080
fat_meta=http: //172 .16.2.17:8080
uat_meta=http: //anotherIp :8080
pro_meta=http: //yetAnotherIp :8080


Server3的配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
apollo_config_db_url=jdbc:mysql: //127 .0.0.1:3306 /ApolloConfigDB ?characterEncoding=utf8
apollo_config_db_username=root
apollo_config_db_password=123456
 
# apollo portal db info
apollo_portal_db_url=jdbc:mysql: //127 .0.0.1:3306 /ApolloPortalDB ?characterEncoding=utf8
apollo_portal_db_username=root
apollo_portal_db_password=123456
 
# meta server url, different environments should have different meta server addresses
dev_meta=http: //localhost :8080
fat_meta=http: //someIp :8080
uat_meta=http: //172 .16.2.18:8080
pro_meta=http: //yetAnotherIp :8080

apollo-portal是一个web控制台,用来做配置管理的。 服务是用来管理不同环境下的admin



apollo-configservice和apollo-adminservice:

需要把自己的IP和端口注册到Meta Server(apollo-configservice本身)

1、修改apollo-adminservice或apollo-configservice 的bootstrap.yml文件,加入以下配置

1
2
3
4
eureka:
   instance:
     homePageUrl: http: // ${指定的IP}:${指定的Port}
     preferIpAddress:  false

Server1的apollo-configservice/src/main/resources/bootstrap.yml文件配置:

1
2
3
4
5
eureka:
   instance:
     home-page-url: http: //172 .16.0.16:8080
     hostname : ${ hostname :localhost}
     preferIpAddress:  true

Server1的apollo-adminservice/src/main/resources/bootstrap.yml文件配置:

1
2
3
4
5
eureka:
   instance:
     home-page-url: http: //172 .16.0.16:8090
     hostname : ${ hostname :localhost}
     preferIpAddress:  true


Server2和Server3只需要将上面两个文件的中home-page-url的地址改成自己的IP即可。



导入apolloconfigdb.sql文件到数据库,并修改Eureka服务Url的值

先登录到数据库,然后执行

1
source  /opt/apollo/scripts/sql/apolloconfigdb .sql;

修改数据库ApolloConfigDB中ServerConfig表Eureka服务Url的值

1
2
3
4
use  ApolloConfigDB;
show tables;
select  * from  ServerConfig;
update ServerConfig  set  Value= 'http://172.16.2.16:8080/eureka/'  where Id=1;

以上操作三台服务器上都要做,Eureka服务Url的值的改成各自的IP地址


Server1上导入apolloportaldb.sql 文件到数据库,并修改部门

先登录到数据库,然后执行:

1
source  /opt/apollo/scripts/sql/apolloportaldb .sql;


修改环境为pro,uat,fat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use ApolloPortalDB;
mysql> show tables;
+--------------------------+
| Tables_in_ApolloPortalDB |
+--------------------------+
| App                      |
| AppNamespace             |
| Authorities              |
| Consumer                 |
| ConsumerAudit            |
| ConsumerRole             |
| ConsumerToken            |
| Favorite                 |
| Permission               |
| Role                     |
| RolePermission           |
| ServerConfig             |
| UserRole                 |
| Users                    |
+--------------------------+
14 rows  in  set  (0.00 sec)
  select  * from ServerConfig;
update ServerConfig  set  Value= 'fat,uat,pro'  where Id=1;


构建

分别在三台服务器上执行./build.sh

将构建生成的压缩包拷贝到/data/目录下 解压缩后,启动服务


Server1

1
2
3
4
5
6
7
cp  /opt/apollo/apollo-configservice/target/apollo-configservice-0 .9.1-SNAPSHOT-github.zip   /data
cp  /opt/apollo/apollo-adminservice/target/apollo-adminservice-0 .9.1-SNAPSHOT-github.zip  /data
cp  /opt/apollo/apollo-portal/target/apollo-portal-0 .9.1-SNAPSHOT-github.zip   /data
cd  /data
unzip apollo-adminservice-0.9.1-SNAPSHOT-github.zip -d apollo-adminservice
unzip apollo-configservice-0.9.1-SNAPSHOT-github.zip -d apollo-configservice
unzip apollo-portal-0.9.1-SNAPSHOT-github.zip -d apollo-portal


创建log路径, apollo三个服务日志路径是固定的/opt/logs/下的100003171  100003172  100003173三个目录100003173是portal服务的log目录,所以不安装portal服务的机器上不用创建该目录

1
mkdir  -p  /opt/logs/ {100003171,100003172,100003173}

修改权限为777

1
chmod  777  /opt/logs/ *

我的机器上由于/data目录挂载的是数据盘,空间大,所以是将/opt/logs下的三个目录软连接到/data/logs/目录下的

1
2
3
ln  -s  /data/logs/100003171  /opt/logs/100003171
ln  -s  /data/logs/100003172  /opt/logs/100003172
ln  -s  /data/logs/100003173  /opt/logs/100003173


修改portal服务启动脚本中的服务端口,默认我8080,修改为8070,否则和configservice服务端口冲突。 

然后分别启动portal、configservice、adminservice服务。启动脚本位于zip包加压缩后的目录下的scripts目录下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
ll  /data/apollo-adminservice/scripts/
total 8
-rwxr-xr-x 1 root root  339 Dec 13 15:57  shutdown .sh
-rwxr-xr-x 1 root root 3906 Dec 13 15:57 startup.sh
 
ll  /data/apollo-configservice/scripts/
total 8
-rwxr-xr-x 1 root root  340 Dec 13 15:57  shutdown .sh
-rwxr-xr-x 1 root root 3907 Dec 13 15:57 startup.sh
 
ll  /data/apollo-portal/scripts/
total 8
-rwxr-xr-x 1 root root  333 Dec 13 15:57  shutdown .sh
-rwxr-xr-x 1 root root 3900 Dec 13 17:12 startup.sh











本文转自 曾哥最爱 51CTO博客,原文链接:http://blog.51cto.com/zengestudy/2050628,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值