apollo 分布式配置中心部署手册

一. 服务组成

apollo 主要由以下几个角色组成

  • 架构图

  • Config Service

    • 提供配置的读取、推送等功能,服务对象是 Apollo 客户端
  • Meta Server
    • Eureka 之上我们架了一层 Meta Server 用于封装 Eureka 的服务发现接口(这是为了支持 JAVA 意外的客户端, 支持服务发现)
    • 为了简化部署,我们实际上会把 Config Service、Eureka 和 Meta Server 三个逻辑角色部署在同一个 JVM 进程中
  • Admin Service
    • 提供配置的修改、发布等功能
    • Portal 通过域名访问 Meta Server 获取 Admin Service 服务列表(IP+Port),而后直接通过 IP+Port 访问服务,同时在 Portal 侧会做 load balance、错误重试
  • Portal
    • 配置管理、发布修改、组织架构权限等操作

二. 部署手册

1. 准备环境

  • MySQL 5.6 +

    • 参数: 不区分大小写 lower_case_table_names = 1
  • JDK 1.8

2. 编译版本和修改配置

2.1 下载脚本修改配置

  1. # 下载脚本
  2. git clone git@gitee.com:java-project/apollo.git
  3. git fetch origin feature-v1.2.0:feature-v1.2.0
  4. git checkout feature-v1.2.0

2.2 打开 ide 导入项目, 修改相关配置(使用了 feature-v1.2.0 这个版本则不需要修改)

  1. 1. apollo-configservice 项目修改日志地址、端口、脚本
  2. conf/
  3. apollo-configservice.conf
  4. LOG_FOLDER=/opt/logs/service/apollo/configservice/
  5. resources/
  6. application.yml
  7. logging:
  8. file: /opt/logs/service/apollo/configservice/apollo-configservice.log
  9. server:
  10. port: 20101 (old: 8080)
  11. configservice.properties
  12. logging.file= /opt/logs/service/apollo/configservice/apollo-configservice.log
  13. server.port= 20101
  14. scripts/
  15. startup.sh
  16. LOG_DIR=/opt/logs/service/apollo/configservice
  17. SERVER_PORT=20101
  18. 2. apollo-adminservice 项目修改日志地址、端口、脚本
  19. conf/
  20. apollo-adminservice.conf
  21. LOG_FOLDER=/opt/logs/service/apollo/adminservice/
  22. resources/
  23. application.yml
  24. logging:
  25. file: /opt/logs/service/apollo/adminservice/apollo-adminservice.log
  26. server:
  27. port: 20102 (old: 8090)
  28. configservice.properties
  29. logging.file= /opt/logs/service/apollo/adminservice/apollo-adminservice.log
  30. server.port= 20102
  31. scripts/
  32. startup.sh
  33. LOG_DIR=/opt/logs/service/apollo/adminservice
  34. SERVER_PORT=20102
  35. 3. apollo-portal 项目修改日志地址、端口、脚本
  36. conf/
  37. apollo-portal.conf
  38. LOG_FOLDER=/opt/logs/service/apollo/portal/
  39. resources/
  40. application.yml
  41. logging:
  42. file: /opt/logs/service/apollo/portal/apollo-portal.log
  43. server:
  44. port: 20100 (old: 8070)
  45. scripts/
  46. startup.sh
  47. LOG_DIR= /opt/logs/service/apollo/portal
  48. SERVER_PORT=20100

2.3 编译脚本

  1. # 编译脚本
  2. apollo/scripts/build.sh
  3. 编译完成后会有 3 个包 zip 压缩包, apollo-portalapollo-adminserviceapollo-portal, 目录如下
  4. apollo/apollo-configservice/target/apollo-configservice-1.2.0-SNAPSHOT-github.zip
  5. apollo/apollo-adminservice/target/apollo-adminservice-1.2.0-SNAPSHOT-github.zip
  6. apollo/apollo-portal/target/apollo-portal-1.2.0-SNAPSHOT-github.zip

二. 部署流程

  • 部署的顺序为 configservice > adminservice > portal

  • 需要注意的是

    • configservice 和 adminservice 需要组合部署的
    • 例如在 DEV 环境要部署一套, PRO 环境要部署一套
    • 环境有 (DEV/FAT/UAT/PRO)

1. 部署 Config Service 和 Meta Server

  • Config Service 中包含了(Config Service、Meta Server、Eureka) 所以启动了 Config Service, 这 3 个服务全部启动

  • 导入 Config Service 表到数据库中

  1. 1. 创建 apollo_config_db 数据库
  2. # 创建数据库
  3. CREATE DATABASE IF NOT EXISTS apollo_config_db DEFAULT CHARACTER SET = utf8mb4;
  4. # 授权用户
  5. GRANT ALL PRIVILEGES ON apollo_config_db.* TO 'apollo'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION ;
  6. 2. 导入数据文件 apollo/scripts/sql/apolloconfigdb.sql apollo_config_db
  • 启动脚本
  1. # 解压
  2. unzip -o apollo/apollo-configservice/target/apollo-configservice-1.2.0-SNAPSHOT-github.zip
  3. 1. 修改 application-github.properties 配置
  4. # 修改数据库配置
  5. vim config/application-github.properties
  6. # DataSource
  7. spring.datasource.url = jdbc:mysql://{your_db_host}:3306/apollo_config_db?characterEncoding=utf8
  8. spring.datasource.username = apollo
  9. spring.datasource.password = {your_password}
  10. 2. 修改系统表 apollo_config_db.serverconfig 参数
  11. # 设置 apollo-configservice 部署的 ip 和 port
  12. eureka.service.url http://hostname-1:20101/eureka/,http://hostname-2:20101/eureka/,http://hostname-3:20101/eureka/
  13. 3. 启动和关闭
  14. # 创建日志目录
  15. mkdir -p /opt/logs/service/apollo/configservice
  16. # 关闭
  17. scripts/shutdown.sh
  18. # 启动
  19. scripts/startup.sh
  20. 4. 启动成功
  21. netstat -tunlp | grep 20101 有数据表示启动成功

2. 部署 Admin Service

  • 使用以上 Config Service 的数据库 apollo_config_db

  • 启动脚本

  1. # 解压
  2. unzip -o apollo/apollo-adminservice/target/apollo-adminservice-1.2.0-SNAPSHOT-github.zip
  3. 1. 修改 application-github.properties 配置
  4. # 修改数据库配置
  5. vim config/application-github.properties
  6. # DataSource (使用 Config Service 中 apollo_config_db 同样的数据库配置)
  7. spring.datasource.url = jdbc:mysql://{your_db_host}:3306/apollo_config_db?characterEncoding=utf8
  8. spring.datasource.username = apollo
  9. spring.datasource.password = {your_password}
  10. 2. 启动和关闭
  11. # 创建日志目录
  12. mkdir -p /opt/logs/service/apollo/adminservice
  13. # 关闭
  14. scripts/shutdown.sh
  15. # 启动
  16. scripts/startup.sh
  17. 3. 启动成功
  18. netstat -tunlp | grep 20102 有数据表示启动成功

3. 部署 Portal

  • Portal 界面需要连接不同环境的 Meta Server(跟 Config Service 部署在一起的角色)

  • 导入 Portal 表到数据库中

  1. 1. 创建 apollo_portal_db 数据库
  2. # 创建数据库
  3. CREATE DATABASE IF NOT EXISTS apollo_portal_db DEFAULT CHARACTER SET = utf8mb4;
  4. # 授权用户
  5. GRANT ALL PRIVILEGES ON apollo_portal_db.* TO 'apollo'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION ;
  6. 2. 导入数据文件 apollo/scripts/sql/apolloportaldb.sql apollo_portal_db
  • 启动脚本
  1. # 解压
  2. unzip -o apollo/apollo-portal/target/apollo-portal-1.2.0-SNAPSHOT-github.zip
  3. 1. 设置 Portal 支持环境属性 (DEV/FAT/UAT/PRO)
  4. a) 修改 config/apollo-env.properties 设置已经有的环境(必须基于已经配置好的 Config Service Admin Service 的环境)
  5. #local.meta=http://localhost:20101
  6. #dev.meta=http://apollo-dev-meta-server:20102
  7. #fat.meta=http://apollo-fat-meta-server:20101
  8. #uat.meta=http://apollo-uat-meta-server:20101
  9. #lpt.meta=${lpt_meta}
  10. # 为已有的环境配置 Meta Server 地址
  11. # 多个使用逗号分隔, 但是建议使用 nginx slb 软负载, 只填写一个 host 地址
  12. pro.meta=http://log1:20101,http://log2:20101,http://log3:20101
  13. b) 修改系统表 apollo_config_db.serverconfig 参数
  14. # 设置目前支持的环境, 没有的环境注释掉不要填写, 不然启动会报错
  15. apollo.portal.envs PRO
  16. 2. 修改 application-github.properties 配置
  17. # 修改数据库配置
  18. vim config/application-github.properties
  19. # DataSource
  20. spring.datasource.url = jdbc:mysql://app1:3306/apollo_portal_db?characterEncoding=utf8
  21. spring.datasource.username = apollo
  22. spring.datasource.password = apollo_818
  23. 3. 启动和关闭
  24. # 创建日志目录
  25. mkdir -p /opt/logs/service/apollo/portal
  26. # 关闭
  27. scripts/shutdown.sh
  28. # 启动
  29. scripts/startup.sh
  30. 4. 启动成功
  31. netstat -tunlp | grep 20100 有数据表示启动成功
  32. 5. 问题
  33. a) 启动的时候如果报错
  34. [Apollo-ServiceLocator-1] c.c.f.a.p.c.AdminServiceAddressLocator : Get admin server address from meta server failed. env: DEV, meta server address:http://apollo.meta
  35. 详见: https://github.com/ctripcorp/apollo/issues/1743
  36. b) 如果出现网络超时, 设置
  37. 修改 scripts/startup.sh 脚本, 添加 eureka 指定注册地址
  38. -Deureka.instance.ip-address=xxx.xxx.com
  39. 例如:
  40. export JAVA_OPTS="$JAVA_OPTS -Deureka.instance.ip-address=xxx.xxx.com -Dserver.port=$SERVER_PORT -Dlogging.file=$LOG_DIR/$SERVICE_NAME.log -Xloggc:$LOG_DIR/gc.log -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=5M -XX:HeapDumpPath=$LOG_DIR/HeapDumpOnOutOfMemoryError/"