apollo工作原理
用户通过浏览器登录Portal管理界面 >> 通过Admin server对配置进行修改 >> 应用程序主动向config server配置
注意:Portal与Admin、config的信息都存储在数据库中,Portal单独一个数据库,其他两个共用一个数据库
apollo总体设计
Config Service提供配置的读取、推送等功能,服务对象是Apollo客户端
Admin Service提供配置的修改、发布等功能,服务对象是Apollo Portal(管理界面)
Config Service和Admin Service都是多实例、无状态部署,所以需要将自己注册到Eureka中并保持心跳
在Eureka之上我们架了一层Meta Server用于封装Eureka的服务发现接口
Client通过域名访问Meta Server获取Config Service服务列表(IP+Port),而后直接通过IP+Port访问服务,同时在Client侧会做load balance、错误重试
Portal通过域名访问Meta Server获取Admin Service服务列表(IP+Port),而后直接通过IP+Port访问服务,同时在Portal侧会做load balance、错误重试
为了简化部署,我们实际上会把Config Service、Eureka和Meta Server三个逻辑角色部署在同一个JVM进程中
集群式部署
部署环境
Centos 7.4
mysql 5.7安装并授权
java 1.8+
数据库地址:192.168.1.83(host-3)
Portal地址:192.168.1.142(host-1)
config地址:192.168.1.142
Admin地址:192.168.1.142
apollo下载地址:https://github.com/ctripcorp/apollo/releases/tag/v1.4.0
apollo下载内容:apollo-adminservice-xxx-github.zip、apollo-configservice-xxx-github.zip、apollo-portal-xxx-github.zip、Source code(这个里面主要是存放SQL文件,其他的不重要)
准备相关工具
[root@host-1 ~]# yum -y install wget unzip [root@host-1 ~]# wget https://github.com/ctripcorp/apollo/releases/download/v1.4.0/apollo-adminservice-1.4.0-github.zip -P /opt/ [root@host-1 ~]# wget https://github.com/ctripcorp/apollo/releases/download/v1.4.0/apollo-configservice-1.4.0-github.zip -P /opt/ [root@host-1 ~]# wget https://github.com/ctripcorp/apollo/releases/download/v1.4.0/apollo-portal-1.4.0-github.zip -P /opt/ [root@host-1 ~]# wget https://github.com/ctripcorp/apollo/archive/v1.4.0.tar.gz -P /opt/ [root@host-1 ~]# mkdir -p /opt/{admin,config,Portal} [root@host-1 ~]# unzip /opt/apollo-adminservice-1.4.0-github.zip -d /opt/admin/ [root@host-1 ~]# unzip /opt/apollo-configservice-1.4.0-github.zip -d /opt/config/ [root@host-1 ~]# unzip /opt/apollo-portal-1.4.0-github.zip -d /opt/Portal/ [root@host-1 ~]# mkdir -p /opt/Scode [root@host-1 ~]# tar -zxf /opt/apollo-1.4.0.tar.gz -C /opt/Scode/
数据导入
[root@host-3 ~]# mysql -uroot -p mysql> grant all privileges on *.* to 'root'@'%' identified by '123..com'; mysql> flush privileges; [root@host-1 ~]# mysql -uroot -p -h192.168.1.83 MySQL [(none)]> create database `ApolloPortalDB` default charset utf8; MySQL [(none)]> create database `ApolloConfigDB` default charset utf8; MySQL [(none)]> use ApolloConfigDB; MySQL [ApolloConfigDB]> source /opt/Scode/apollo-1.4.0/scripts/db/migration/configdb/V1.0.0__initialization.sql; MySQL [ApolloConfigDB]> use ApolloPortalDB; MySQL [ApolloPortalDB]> source /opt/Scode/apollo-1.4.0/scripts/db/migration/portaldb/V1.0.0__initialization.sql; 检查导入状况 MySQL [ApolloPortalDB]> select `Id`, `Key`, `Value`, `Comment` from `ApolloPortalDB`.`ServerConfig` limit 1; +----+--------------------+-------+--------------------------+ | Id | Key | Value | Comment | +----+--------------------+-------+--------------------------+ | 1 | apollo.portal.envs | dev | 可支持的环境列表 | +----+--------------------+-------+--------------------------+ MySQL [ApolloPortalDB]> select `Id`, `Key`, `Value`, `Comment` from `ApolloConfigDB`.`ServerConfig` limit 1; +----+--------------------+-------------------------------+------------------------------------------------------+ | Id | Key | Value | Comment | +----+--------------------+-------------------------------+------------------------------------------------------+ | 1 | eureka.service.url | http://localhost:8080/eureka/ | Eureka服务Url,多个service以英文逗号分隔 | +----+--------------------+-------------------------------+------------------------------------------------------+ 具体的参数修改请参考 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#213-%E8%B0%83%E6%95%B4%E6%9C%8D%E5%8A%A1%E7%AB%AF%E9%85%8D%E7%BD%AE
部署服务端
注:客户端就是每一个应用程序主机,apollo是根据ID来进行消息的推送,所以apollo在部署时是没有客户端的安装方式(最主要的是我不会写代码。。)
# 配置apollo-configservice的数据库连接信息,将原有内容修改成如下内容: [root@host-1 ~]# cat /opt/config/config/application-github.properties # DataSource spring.datasource.url = jdbc:mysql://192.168.1.83:3306/ApolloConfigDB?characterEncoding=utf8 spring.datasource.username = root spring.datasource.password = 123..com # 配置apollo-adminservice的数据库连接信息,将原有内容修改成如下内容: [root@host-1 ~]# cat /opt/admin/config/application-github.properties # DataSource spring.datasource.url = jdbc:mysql://192.168.1.83:3306/ApolloConfigDB?characterEncoding=utf8 spring.datasource.username = root spring.datasource.password = 123..com # 配置apollo-portal的数据库连接信息,将原有内容修改成如下内容: [root@host-1 ~]# cat /opt/Portal/config/application-github.properties # DataSource spring.datasource.url = jdbc:mysql://192.168.1.83:3306/ApolloPortalDB?characterEncoding=utf8 spring.datasource.username = root spring.datasource.password = 123..com # 配置apollo-portal的meta service信息,将原有内容修改成如下内容: [root@host-1 ~]# cat /opt/Portal/config/apollo-env.properties dev.meta=http://192.168.1.142:8080
调优启动
# 可以根据自身的硬件资源进行相应的调优 # 修改config配置,将如下配置添加进startup.sh export JAVA_OPTS="-server -Xms6144m -Xmx6144m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=384m -XX:NewSize=4096m -XX:MaxNewSize=4096m -XX:SurvivorRatio=18" # 修改admin配置,将如下配置添加进startup.sh export JAVA_OPTS="-server -Xms2560m -Xmx2560m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=384m -XX:NewSize=1024m -XX:MaxNewSize=1024m -XX:SurvivorRatio=22" # 修改portal配置,将如下配置添加进startup.sh export JAVA_OPTS="-server -Xms4096m -Xmx4096m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=384m -XX:NewSize=1536m -XX:MaxNewSize=1536m -XX:SurvivorRatio=22" # 启动顺序从上至下,停止顺序自下而上 默认登录地址:http://192.168.1.142:8070 默认登录账户:apollo/admin 官网参考地址:https://github.com/ctripcorp/apollo/wiki