目前市面上流行的三大配置中心框架:Spring CLoud Config 、Alibaba Nacos 以及携程apollo, 我们相应架构组号召,就使用Apollo吧。
Work Flow简单解释:
上图中有三套环境FAT、UAT和PROD,每一套环境都部署了2套Configservice 和 Adminservice.使用统一的Portal Server Cluster对所有环境进行配置管理。如我们自己的配置环境:
Meta-Server(Configservice)说白一点,就是Eureka discovery,每一套环境对应不同的一套meta server,以此来实现环境隔离,如下图:
如图2所示。
Configure Serverapollo 服务端主要有三个Spring Boot项目 和两个数据库组成:
apollo-configservice(默认端口:8080)
提供配置的读取、推送等功能,服务对象是Apollo客户端
apollo-adminservice(默认端口:8090)
提供配置的修改、发布等功能,服务对象是Apollo Portal(管理界面)
apollo-portal(默认端口:8070)
通过域名访问Meta Server获取Admin Service服务列表(IP+Port),而后直接通过IP+Port访问服务,同时在Portal侧会做load balance、错误重试
apolloportaldb
apolloconfigdb
因为Apollo官方文档足够详细,想要了解的同学直接Apollo官网传送门
但是又因为官方文档太过详细,以至于如果只想部署的同学可能觉得稍显繁琐,因此,我这里直接开始部署服务端,就废话少说了。
第一步,下载https://github.com/ctripcorp/apollo/releases
第二步,下载adminservice、configservice和portal三个zip包之后,上传到服务器。
第三部,在服务器中安装mysql,并创建数据库,脚本传送门
第四步,分别配置三个Springboot服务并启动,主要配置点有3处:
数据库配置
1 # DataSource 2 spring.datasource.url = jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8 3 spring.datasource.username = wr 4 spring.datasource.password = wr日志路径
(/根路径/apollo-xxxx.conf)
properties
1 MODE=service
2 PID_FOLDER=.
# 这里
3 LOG_FOLDER=http://www.likecs.com/home/jing/software/apollo-portal-1.5.1/logs/100003173/
/script/startup.sh
1 #!/bin/bash 2 SERVICE_NAME=apollo-portal 3 ## Adjust log dir if necessary #这里 4 LOG_DIR=http://www.likecs.com/home/jing/software/apollo-portal-1.5.1/logs/100003173 5 ## Adjust server port if necessary 6 SERVER_PORT=${SERVER_PORT:=8070}
配置apollo-portal的meta service信息
local.meta=http://localhost:8080 2 dev.meta=http://localhost:8080 4 uat.meta=http://localhost:8080 6 pro.meta=http://localhost:8080这里也得修改apolloconfigdb数据库中的表serverconfig中 apollo.portal.envs的配置为:dev,uat,prod
然后apollo server就配置好了,分别启动三个服务即可!访问:8070/
jing@sysdep:~/software/apollo-adminservice-1.5.1$ ps -ef|grep apollo jing 25348 1 19 08:12 pts/2 00:01:31 /home/jing/.jenv/versions/1.8/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -XX:ParallelGCThreads=4 -XX:MaxTenuringThreshold=9 -XX:+DisableExplicitGC -XX:+ScavengeBeforeFullGC -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Duser.timezone=Asia/Shanghai -Dclient.encoding.override=UTF-8 -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom -Dserver.port=8080 -Dlogging.file=http://www.likecs.com/home/jing/software/apollo-configservice-1.5.1/logs/100003171/apollo-configservice.log -XX:HeapDumpPath=http://www.likecs.com/home/jing/software/apollo-configservice-1.5.1/logs/100003171/HeapDumpOnOutOfMemoryError/ -XX:+UseParNewGC -Xloggc:/home/jing/software/apollo-configservice-1.5.1/logs/100003171/gc.log -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=60 -XX:+CMSClassUnloadingEnabled -XX:+CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=9 -XX:+CMSClassUnloadingEnabled -XX:+PrintGCDateStamps -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=5M -jar /home/jing/software/apollo-configservice-1.5.1/apollo-configservice.jar jing 27274 1 37 08:17 pts/2 00:01:23 /home/jing/.jenv/versions/1.8/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -XX:ParallelGCThreads=4 -XX:MaxTenuringThreshold=9 -XX:+DisableExplicitGC -XX:+ScavengeBeforeFullGC -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Duser.timezone=Asia/Shanghai -Dclient.encoding.override=UTF-8 -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom -Dserver.port=8090 -Dlogging.file=http://www.likecs.com/home/jing/software/apollo-adminservice-1.5.1/logs/100003172/apollo-adminservice.log -XX:HeapDumpPath=http://www.likecs.com/home/jing/software/apollo-adminservice-1.5.1/logs/100003172/HeapDumpOnOutOfMemoryError/ -XX:+UseParNewGC -Xloggc:/home/jing/software/apollo-adminservice-1.5.1/logs/100003172/gc.log -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=60 -XX:+CMSClassUnloadingEnabled -XX:+CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=9 -XX:+CMSClassUnloadingEnabled -XX:+PrintGCDateStamps -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=5M -jar /home/jing/software/apollo-adminservice-1.5.1/apollo-adminservice.jar jing 28964 1 99 08:19 pts/3 00:01:00 /home/jing/.jenv/versions/1.8/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -XX:ParallelGCThreads=4 -XX:MaxTenuringThreshold=9 -XX:+DisableExplicitGC -XX:+ScavengeBeforeFullGC -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Duser.timezone=Asia/Shanghai -Dclient.encoding.override=UTF-8 -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom -Dserver.port=8070 -Dlogging.file=http://www.likecs.com/home/jing/software/apollo-portal-1.5.1/logs/100003173/apollo-portal.log -XX:HeapDumpPath=http://www.likecs.com/home/jing/software/apollo-portal-1.5.1/logs/100003173/HeapDumpOnOutOfMemoryError/ -XX:+UseParNewGC -Xloggc:/home/jing/software/apollo-portal-1.5.1/logs/100003173/gc.log -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=60 -XX:+CMSClassUnloadingEnabled -XX:+CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=9 -XX:+CMSClassUnloadingEnabled -XX:+PrintGCDateStamps -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=5M -jar /home/jing/software/apollo-portal-1.5.1/apollo-portal.jar Configure Client