zoukankan      html  css  js  c++  java
  • 携程Apollo分布式配置中心部署以及使用

    理论指导:

    参考1

      • apollo-configservice:提供配置获取接口,提供配置更新推送接口,接口服务对象为Apollo客户端
      • apollo-adminservice:提供配置管理接口,提供配置修改、发布等接口,接口服务对象为Portal,以及Eureka
      • apollo-portal:提供Web界面供用户管理配置
      • apollo-client:Apollo提供的客户端程序,为应用提供配置获取、实时更新等功能

    参考2

    架构剖析 1

    架构清晰剖析2

    开始部署:

    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

    ConfigDB初始数据tar包里有,github也有

    调整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
    sed -ir "s/FillInCorrectUser/root/" apollo-configservice/config/application-github.properties
    sed -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
    sed -ir "s/FillInCorrectUser/root/" /apollo-adminservice/config/application-github.properties
    sed -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
    sed -ir "s/FillInCorrectUser/root/" /apollo-portal/config/application-github.properties
    sed -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 -.....

    自定义环境

  • 相关阅读:
    spring boot.定时任务问题记录(TaskScheduler/ScheduledExecutorService异常)
    网站配置https(腾讯云域名操作)
    Java web如何定位工程路径
    centos7安装nginx
    个人博客搭建----基于solo
    velocity学习总结
    第四篇:用IntelliJ IDEA 搭建基于jersey的RESTful api
    Python 包批量升级
    Linux 常用命令更新汇总
    ubuntu 18.04 +firefox + selenium + python
  • 原文地址:https://www.cnblogs.com/fanever/p/10838832.html
Copyright © 2011-2022 走看看