一、环境准备
操作系统:CentOS release 7.5 (启动脚本理论上支持所有Linux发行版,建议CentOS 7)
JDK :jdk1.8.0_162 (建议安装Java 1.8+)
MySQL:5.7.26 (Apollo的表结构对timestamp
使用了多个default声明,所以需要5.6.5以上版本)
架构:(官方默认支持DEV(开发环境)、FAT(功能测试)、UAT(回归测试)、PRO(生产环境),由于机器有限,只部署Dev,Pro)
Portal service: 172.16.150.131
Dev config&& admin 172.16.150.132
Pro config && admin 172.16.150.133
#自定义环境参考:https://github.com/ctripcorp/apollo/wiki/%E9%83%A8%E7%BD%B2&%E5%BC%80%E5%8F%91%E9%81%87%E5%88%B0%E7%9A%84%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98#42-%E6%B7%BB%E5%8A%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E7%8E%AF%E5%A2%83
关闭防火墙
同步时间
#注意事项:
如果实际部署的机器有多块网卡(如docker),或者存在某些网卡的IP是Apollo客户端和Portal无法访问的(如网络安全限制),那么我们就需要在apollo-configservice
和apollo-adminservice
中做相关限制以避免Eureka将这些网卡的IP注册到Meta Server。
参考地址:https://github.com/ctripcorp/apollo/wiki/%E5%88%86%E5%B8%83%E5%BC%8F%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97#14%E7%BD%91%E7%BB%9C%E7%AD%96%E7%95%A5
二、服搭建数据库服务及创建相关库
1.搭建MySQL
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
vim mysql-community.repo #启动5.7,禁用8.0
yum clean all && yum makecache
yum install mysql-community-server -y
systemctl start mysqld
grep "temporary password" /var/log/mysqld.log #获取MySQL初始化密码
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 152
Server version: 5.7.26 MySQL Community Server (GPL) #MySQL版本号
...
mysql> \q
Bye
#以上操作在三台服务器都需要执行
2.创建Apollo PortalDB数据库(在Portal service:172.16.150.131服务器上操作)
wget https://raw.githubusercontent.com/ctripcorp/apollo/master/scripts/db/migration/portaldb/V1.0.0__initialization.sql #下载官方提供的SQL文件
mysql -uroot -p
mysql> source /root/V1.0.0__initialization.sql #手动导入
show databases;
use ApolloPortalDB;
show tables;
select `Id`, `Key`, `Value`, `Comment` from `ApolloPortalDB`.`ServerConfig` limit 1;
3.创建ApolloConfigDB数据库(172.16.150.132、172.16.150.133上部署)
wget https://raw.githubusercontent.com/ctripcorp/apollo/master/scripts/db/migration/configdb/V1.0.0__initialization.sql
source /root/V1.0.0__initialization.sql
select `Id`, `Key`, `Value`, `Comment` from `ApolloConfigDB`.`ServerConfig` limit 1;
三、安装Apollo服务
1.安装apollo-portal 服务(在Portal service:172.16.150.131服务器上执行)
https://github.com/ctripcorp/apollo/releases/download/v1.4.0/apollo-portal-1.4.0-wget github.zip
unzip apollo-portal-1.4.0-github.zip
cd apollo-portal/
cat config/application-github.properties #ApolloPortalDB数据库连接串信息
# DataSource
spring.datasource.url = jdbc:mysql://172.16.150.131:3306/ApolloPortalDB?characterEncoding=utf8
spring.datasource.username = xxxx
spring.datasource.password = xxx
cat config/apollo-env.properties #配置apollo-portal的meta service信息
dev.meta=http://172.16.150.132:8080
pro.meta=http://172.16.150.133:8080
修改Apollo-portal启动脚本
[root@localhost ~]# grep "^export JAVA_OPTS" apollo-portal/scripts/startup.sh #根据实际情况修改相应的值
export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=8"
2.配置apollo-configservice、apollo-adminservice(172.16.150.132、172.16.150.133上操作)
https://github.com/ctripcorp/apollo/releases/download/v1.4.0/apollo-adminservice-1.4.0-github.zip
https://github.com/ctripcorp/apollo/releases/download/v1.4.0/apollo-configservice-1.4.0-github.zip
unzip apollo-adminservice-1.4.0-github.zip
unzip apollo-configservice-1.4.0-github.zip
[root@localhost ~]# cat apollo-adminservice/config/application-github.properties
# DataSource
spring.datasource.url = jdbc:mysql://172.16.150.132:3306/ApolloConfigDB?characterEncoding=utf8 #注意修改MySQL连接地址
spring.datasource.username = root
spring.datasource.password = xxxx
[root@localhost ~]# cat apollo-configservice/config/application-github.properties #注意修改MySQL连接地址
# DataSource
spring.datasource.url = jdbc:mysql://172.16.150.132:3306/ApolloConfigDB?characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = xxx
修改apollo-configservice、apollo-adminservice启动脚本
[root@localhost ~]# grep "^export JAVA_OPTS" apollo-configservice/scripts/startup.sh #根据实际情况修改相应的值
export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=8"
[root@localhost ~]# grep "^export JAVA_OPTS" apollo-adminservice/scripts/startup.sh
export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=8"
3.启动服务
#要先启动apollo-configservice再启动apollo-adminservice等所有apollo-configservice和apollo-adminservice启动完成后再启动apollo-portal
scripts/startup.sh #启动
scripts/shutdown.sh #关闭服务
日志文件查看
apollo-configservice /opt/logs/100003171/ #日志路径启动脚本中可定义路径
apollo-adminservice /opt/logs/100003172
apollo-portal /opt/logs/100003173
登录Apollo,浏览器访问apollo-portal服务,端口8070,初始用户名是apollo,密码是admin