apollo集群部署
1. 准备工作
1.1. 服务器准备(配置根据情况调整)
准备好安装apollo的三台服务器
配置4CPU,4G内存,20GB硬盘
假设三台服务器IP为
172.16.10.208
172.16.10.209
172.16.10.210
修改相应hostname
apollo-1
apollo-2
apollo-3
1.2. 安装jdk1.8
rpm -ivh jdk-8u231-linux-x64.rpm
在配置好后,可以通过如下命令检查:
java -version
样例输出:
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
创建安装目录
mkdir -p /opt/server/apollo
3. 初始化MySQL数据
版本要求:5.6.5+
SHOW VARIABLES WHERE Variable_name = 'version';
±--------------±-----------+
| Variable_name | Value |
±--------------±-----------+
| version | 5.7.26-log |
±--------------±-----------+
1 row in set (0.02 sec)
Apollo服务端共需要两个数据库:ApolloPortalDB和ApolloConfigDB,我们把数据库、表的创建和样例数据都分别准备了sql文件,只需要导入数据库即可。
2.1. 创建ApolloPortalDB
source /your_local_path/portaldb/V1.0.0__initialization.sql
2.2. 创建ApolloConfigDB
source /your_local_path/configdb/V1.0.0__initialization.sql
2.3. 调整ApolloConfigDB配置
在ApolloConfigDB.ServerConfig表中设置eureka.service.url为(ip、port根据实际情况填写,注意不要有空格):
http://172.16.10.208:8080/eureka/,http://172.16.10.209:8080/eureka/,http://172.16.10.210:8080/eureka/
3. 下载安装包,修改数据库连接信息
3.1 配置apollo-configservice的数据库连接信息
cd /opt/server/apollo
- 解压
apollo-configservice-
1.5.0`-github.zip```
unzip apollo-configservice-1.5.0-github.zip -d apollo-configservice
- 用程序员专用编辑器(如vim,notepad++,sublime等)打开
config
目录下的application-github.properties
文件 - 填写正确的ApolloConfigDB数据库连接串信息,注意用户名和密码后面不要有空格!
- 修改完的效果如下:
# DataSource
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8
spring.datasource.username = someuser
spring.datasource.password = somepwd
3.2. 配置apollo-adminservice的数据库连接信息
- 解压
apollo-adminservice-
1.5.0`-github.zip```
unzip apollo-adminservice-1.5.0-github.zip -d apollo-adminservice
- 用程序员专用编辑器(如vim,notepad++,sublime等)打开
config
目录下的application-github.properties
文件 - 填写正确的ApolloConfigDB数据库连接串信息,注意用户名和密码后面不要有空格!
- 修改完的效果如下:
# DataSource
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8
spring.datasource.username = someuser
spring.datasource.password = somepwd
3.3. 配置apollo-portal的数据库连接信息
- 解压
apollo-portal-
1.5.0`-github.zip```
unzip apollo-portal-1.5.0-github.zip -d apollo-portal
- 用程序员专用编辑器(如vim,notepad++,sublime等)打开
config
目录下的application-github.properties
文件 - 填写正确的ApolloPortalDB数据库连接串信息,注意用户名和密码后面不要有空格!
- 修改完的效果如下:
# DataSource
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloPortalDB?useSSL=false&characterEncoding=utf8
spring.datasource.username = someuser
spring.datasource.password = somepwd
3.4. 配置apollo-portal的meta service信息
使用程序员专用编辑器(如vim,notepad++,sublime等)打开apollo-portal-1.5.0-github.zip中config目录下的apollo-env.properties文件。
dev.meta=http://apollo.domain.com:8080
4. 部署Apollo服务端**
4.1. 创建安装目录
mkdir -p /opt/server/apollo
4.2. 部署apollo-configservice
将apollo-configservice-1.5.0-github.zip上传到服务器上,解压后执行scripts/startup.sh即可。如需停止服务,执行scripts/shutdown.sh。
cd /opt/server/apollo
unzip apollo-configservice-1.5.0-github.zip
apollo-configservice/scripts/startup.sh
4.3. 部署apollo-adminservice
将apollo-adminservice-1.5.0-github.zip上传到服务器上,解压后执行scripts/startup.sh即可。如需停止服务,执行scripts/shutdown.sh。
cd /opt/server/apollo
unzip apollo-adminservice-1.5.0-github.zip
apollo-adminservice/scripts/startup.sh
4.4. 部署apollo-portal
将apollo-portal-1.5.0-github.zip
上传到服务器上,解压后执行scripts/startup.sh即可。如需停止服务,执行scripts/shutdown.sh。
cd /opt/server/apollo
unzip apollo-portal-1.5.0-github.zip
apollo-portal/scripts/startup.sh
4.5. 配置nginx
在nginx的conf/vhost目录下创建metaservice.conf文件,配置如下内容(ip、port根据实际情况修改):
upstream metaservice {
server 172.16.10.208:8080;
server 172.16.10.209:8080;
server 172.16.10.210:8080;
}
server {
listen 8080;
server_name apollo.domain.com;
location / {
add_header X-Content-Type-Options nosniff;
proxy_set_header X-scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_hide_header X-Powered-By;
proxy_hide_header Vary;
proxy_pass http://metaservice;
}
}
需要访问apollo的客户端,需要配置host指向nginx内网IP(例如nginx内网ip为172.16.10.216)
vim /etc/hosts
172.16.10.216 apollo.domain.com