理論指導:
- apollo-configservice:提供配置獲取接口,提供配置更新推送接口,接口服務對象為Apollo客戶端
- apollo-adminservice:提供配置管理接口,提供配置修改、發布等接口,接口服務對象為Portal,以及Eureka
- apollo-portal:提供Web界面供用戶管理配置
- apollo-client:Apollo提供的客戶端程序,為應用提供配置獲取、實時更新等功能
開始部署:
https://github.com/ctripcorp/apollo
基於docker部署apollo分布式配置中心服務
部署節點,所需的tar包應用包,在apollo的github上下載
test1,192.168.0.133 ,dev
test2,192.168.0.134 ,fat
部署步驟
創建ApolloPortalDB數據庫
在test-01部署
docker run --restart always -d --name ApolloPortalDB --network yapi_net --ip 172.30.0.21 -v /opt/ApolloPortalDB/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD='aaaaaa' -p 3307:3306 docker.io/mysql 進入ApolloPortalDB數據庫容器,命令行連接數據庫,導入初始數據1 mysql -uroot -p123qqq...A < /var/lib/mysql/portaldb.sql
update ServerConfig set Value='DEV,FAT' where id=1;添加可支持的環境列表
創建ApolloConfigDB數據庫
分別在test-01和test-02上部署,步驟一樣
docker run --restart always -d --name ApolloConfigDB --network yapi_net --ip 172.30.0.22 -v /opt/ApolloConfigDB/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD='aaaaaa' -p 3308:3306 docker.io/mysql 進入ApolloConfigDB數據庫容器,命令行連接數據庫,導入初始數據2 mysql -uroot -p123qqq...A < /var/lib/mysql/configdb.sql
調整ApolloConfigDB配置,告訴admin 注冊中心在哪里
test-01上執行
進入ApolloConfigDB數據庫容器,連接數據庫update ServerConfig set Value='http://192.168.0.133:8080/eureka/' where id=1;
test-02上執行
進入ApolloConfigDB數據庫容器,連接數據庫
update ServerConfig set Value='http://192.168.0.134:8080/eureka/' where id=1;
部署apollo-configservice
分別在test-01和test-02上部署,步驟一樣
用Dockerfile創建鏡像apollo-configservice,將下載好的tar包放在當前文件夾下,docker build -t apollo-configservice .
# Dockerfile for apollo-configservice # 1. Copy apollo-configservice-${VERSION}-github.zip to current directory # 2. Build with: docker build -t apollo-configservice . # 3. Run with: docker run -p 8080:8080 -d -v /tmp/logs:/opt/logs --name apollo-configservice apollo-configservice FROM openjdk:8-jre-alpine MAINTAINER ameizi <sxyx2008@163.com> ENV VERSION=1.4.0 \ MYSQLPASSWD=aaaaaa \ ApolloConfigDB_IP=172.16.0.1 RUN echo "http://mirrors.aliyun.com/alpine/v3.8/main" > /etc/apk/repositories \ && echo "http://mirrors.aliyun.com/alpine/v3.8/community" >> /etc/apk/repositories \ && apk update upgrade \ && apk add --no-cache procps unzip curl bash tzdata \ && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo "Asia/Shanghai" > /etc/timezone ADD apollo-configservice-${VERSION}-github.zip /apollo-configservice/apollo-configservice-${VERSION}-github.zip RUN unzip /apollo-configservice/apollo-configservice-${VERSION}-github.zip -d /apollo-configservice \ && rm -rf /apollo-configservice/apollo-configservice-${VERSION}-github.zip \ && sed -i '$d' /apollo-configservice/scripts/startup.sh \ # && sed -ir "s/fill-in-the-correct-server/${ApolloConfigDB_IP}/" apollo-configservice/config/application-github.properties \ # && sed -ir "s/FillInCorrectUser/root/" apollo-configservice/config/application-github.properties \ # && sed -ir "s/FillInCorrectPassword/${MYSQLPASSWD}/" apollo-configservice/config/application-github.properties \ && echo "tail -f /dev/null" >> /apollo-configservice/scripts/startup.sh \ && sed -ri '1a sed -ir "s/fill-in-the-correct-server/${ApolloConfigDB_IP}/" apollo-configservice/config/application-github.properties\nsed -ir "s/FillInCorrectUser/root/" apollo-configservice/config/application-github.properties\nsed -ir "s/FillInCorrectPassword/${MYSQLPASSWD}/" apollo-configservice/config/application-github.properties' /apollo-configservice/scripts/startup.sh EXPOSE 8080 CMD ["/apollo-configservice/scripts/startup.sh"]
啟動容器docker run --restart always -d --name apollo-configservice --network host -e MYSQLPASSWD='aaaaaa' -p 8080:8080 -e ApolloConfigDB_IP='172.30.0.22' apollo-configservice
部署apollo-adminservice
分別在test-01和test-02上部署,步驟一樣
用Dockerfile創建鏡像apollo-adminservice
# Dockerfile for apollo-adminservice # 1. Copy apollo-adminservice-${VERSION}-github.zip to current directory # 2. Build with: docker build -t apollo-adminservice . # 3. Run with: docker run -p 8090:8090 -d -v /tmp/logs:/opt/logs --name apollo-adminservice apollo-adminservice FROM openjdk:8-jre-alpine MAINTAINER ameizi <sxyx2008@163.com> ENV VERSION=1.4.0 \ MYSQLPASSWD=aaaaaa \ ApolloConfigDB_IP=172.16.0.1 RUN echo "http://mirrors.aliyun.com/alpine/v3.8/main" > /etc/apk/repositories \ && echo "http://mirrors.aliyun.com/alpine/v3.8/community" >> /etc/apk/repositories \ && apk update upgrade \ && apk add --no-cache procps unzip curl bash tzdata \ && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo "Asia/Shanghai" > /etc/timezone ADD apollo-adminservice-${VERSION}-github.zip /apollo-adminservice/apollo-adminservice-${VERSION}-github.zip RUN unzip /apollo-adminservice/apollo-adminservice-${VERSION}-github.zip -d /apollo-adminservice \ && rm -rf /apollo-adminservice/apollo-adminservice-${VERSION}-github.zip \ && sed -i '$d' /apollo-adminservice/scripts/startup.sh \ # && sed -ir "s/fill-in-the-correct-server/${ApolloConfigDB_IP}/" /apollo-adminservice/config/application-github.properties \ # && sed -ir "s/FillInCorrectUser/root/" /apollo-adminservice/config/application-github.properties \ # && sed -ir "s/FillInCorrectPassword/${MYSQLPASSWD}/" /apollo-adminservice/config/application-github.properties \ && echo "tail -f /dev/null" >> /apollo-adminservice/scripts/startup.sh \ && sed -ri '1a sed -ir "s/fill-in-the-correct-server/${ApolloConfigDB_IP}/" /apollo-adminservice/config/application-github.properties\nsed -ir "s/FillInCorrectUser/root/" /apollo-adminservice/config/application-github.properties\nsed -ir "s/FillInCorrectPassword/${MYSQLPASSWD}/" /apollo-adminservice/config/application-github.properties' /apollo-adminservice/scripts/startup.sh EXPOSE 8090 CMD ["/apollo-adminservice/scripts/startup.sh"]
啟動容器docker run --restart always -d --name apollo-adminservice --network host -e MYSQLPASSWD='aaaaaa' -p 8090:8090 -e ApolloConfigDB_IP='172.30.0.22' apollo-adminservice
部署apollo-portal
在test-01上執行
用Dockerfile創建鏡像apollo-portal
# Dockerfile for apollo-portal # 1. Copy apollo-portal-${VERSION}-github.zip to current directory # 2. Build with: docker build -t apollo-portal . # 3. Run with: docker run -p 8070:8070 -d -v /tmp/logs:/opt/logs --name apollo-portal apollo-portal FROM openjdk:8-jre-alpine MAINTAINER ameizi <sxyx2008@163.com> ENV VERSION=1.4.0 \ ApolloPortalDB_IP=172.16.0.2 \ MYSQLPASSWD=aaaaaa \ DEVMetaIp=172.30.0.61 RUN echo "http://mirrors.aliyun.com/alpine/v3.8/main" > /etc/apk/repositories \ && echo "http://mirrors.aliyun.com/alpine/v3.8/community" >> /etc/apk/repositories \ && apk update upgrade \ && apk add --no-cache procps unzip curl bash tzdata \ && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo "Asia/Shanghai" > /etc/timezone ADD apollo-portal-${VERSION}-github.zip /apollo-portal/apollo-portal-${VERSION}-github.zip RUN unzip /apollo-portal/apollo-portal-${VERSION}-github.zip -d /apollo-portal \ && rm -rf /apollo-portal/apollo-portal-${VERSION}-github.zip \ && sed -i '$d' /apollo-portal/scripts/startup.sh \ # && sed -ir "s/fill-in-the-correct-server/${ApolloPortalDB_IP}/" /apollo-portal/config/application-github.properties \ # && sed -ir "s/FillInCorrectUser/root/" /apollo-portal/config/application-github.properties \ # && sed -ir "s/FillInCorrectPassword/${MYSQLPASSWD}/" /apollo-portal/config/application-github.properties \ && echo "tail -f /dev/null" >> /apollo-portal/scripts/startup.sh \ && sed -ri '1a sed -ir "s/fill-in-the-correct-server/${ApolloPortalDB_IP}/" /apollo-portal/config/application-github.properties\nsed -ir "s/FillInCorrectUser/root/" /apollo-portal/config/application-github.properties\nsed -ir "s/FillInCorrectPassword/${MYSQLPASSWD}/" /apollo-portal/config/application-github.properties' /apollo-portal/scripts/startup.sh \ # local.meta=http://localhost:8080 # dev.meta=http://fill-in-dev-meta-server:8080 # fat.meta=http://fill-in-fat-meta-server:8080 # uat.meta=http://fill-in-uat-meta-server:8080 # lpt.meta=${lpt_meta} # pro.meta=http://fill-in-pro-meta-server:8080 && echo -e "dev.meta=http://${DEVMetaIp}:8080" > /apollo-portal/config/apollo-env.properties EXPOSE 8070 CMD ["/apollo-portal/scripts/startup.sh"]
啟動容器docker run --restart always -d --name apollo-portal --network host -e MYSQLPASSWD='aaaaaa' -p 8070:8070 -e ApolloPortalDB_IP='172.30.0.21' apollo-portal
進入容器更改meta service地址
cat apollo-portal/config/apollo-env.properties
dev_meta=http://192.168.0.133:8080
fat_meta=http://192.168.0.134:8080
重啟容器即可
部署完畢
訪問驗證:真機ip:8070
---------------------------------------------------------------------------------------------------------------
修改管理員賬號及密碼:在網頁上添加用戶及密碼,然后在數據庫里修改即可
補充:
當Apollo部署在雲上時,本地要獲取Apollo的配置內容,所以不能讓自動注冊自己的ip(內網ip),要制定自己的公網ip;
進入容器內,修改
startup.sh文件,加上
-Deureka.instance.ip-address=${指定的IP} ,這樣可以修改 jar的運行參數java -.....