apolloconfig搭建

前言

apollo(阿波罗)是一款可靠的分布式配置管理中心,诞生于携程框架研发部,能够集中化管理应用不同环境、不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限、流程治理等特性,适用于微服务配置管理场景。

apollo的官方文档很详细,但是有点过于详细和全面了,对于想快速搭建apollo环境试用的人来说,干扰信息太多。为了给后来者参考,也作为自己部署apollo的笔记,故写下这篇文章。

本文记录从源码编译开始,在单机上以分布式部署的方式,部署单环境单实例apollo服务,以及多环境多实例的apollo服务的过程,并附上简单的使用示例。

编译及运行环境

  • 系统版本:Windows 10

  • apollo版本:2.0.1

  • MySQL版本:5.7.20

  • Java版本:1.8.0_101

  • Git Bash:2.12.0.windows.1


单机部署单环境单实例

  • 本次部署除MySQL配置外,其它均使用默认配置,需要使用以下三个端口:8070、8080、8090

1.下载代码

github地址:https://github.com/apolloconfig/apollo/tree/v2.0.1

2.数据准备

执行apollo-2.0.1/scripts/sql目录下的两个sql文件:apolloconfigdb.sqlapolloportaldb.sql

3.修改apollo-2.0.1/scripts/build.bat文件(如果是Linux系统,请修改apollo-2.0.1/scripts/build.sh

3.1.修改数据库连接信息
rem apollo config db info
set apollo_config_db_url="jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8"
set apollo_config_db_username="root"
set apollo_config_db_password="root"rem apollo portal db info
set apollo_portal_db_url="jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8"
set apollo_portal_db_username="root"
set apollo_portal_db_password="root"
3.2.修改meta service信息

(本次部署使用默认配置, 默认环境为dev,此处可以跳过)

rem meta server url, different environments should have different meta server addresses
set dev_meta="http://localhost:8080"
set fat_meta="http://someIp:8080"
set uat_meta="http://anotherIp:8080"
set pro_meta="http://yetAnotherIp:8080"

4.执行apollo-2.0.1/scripts/build.bat,执行完毕后获取以下文件,并拷贝到安装目录

apollo-2.0.1/apollo-adminservice/target/apollo-adminservice-2.0.1-github.zip
apollo-2.0.1/apollo-configservice/target/apollo-configservice-2.0.1-github.zip
apollo-2.0.1/apollo-portal/target/apollo-portal-2.0.1-github.zip

5.解压并启动

进入安装目录,解压:

unzip apollo-adminservice-2.0.1-github.zip -d apollo-adminservice-2.0.1-github
unzip apollo-configservice-2.0.1-github.zip -d apollo-configservice-2.0.1-github
unzip apollo-portal-2.0.1-github.zip -d apollo-portal-2.0.1-github

configservice -> adminservice -> portal的顺序依次启动服务,可以使用以下脚本启动:

sh apollo-configservice-2.0.1-github/scripts/startup.sh
sh apollo-adminservice-2.0.1-github/scripts/startup.sh
sh apollo-portal-2.0.1-github/scripts/startup.sh

6.访问apollo

地址:http://localhost:8070

用户名:apollo

密码:admin

7.停止apollo

sh apollo-portal-2.0.1-github/scripts/shutdown.sh
sh apollo-adminservice-2.0.1-github/scripts/shutdown.sh
sh apollo-configservice-2.0.1-github/scripts/shutdown.sh

8.修改部门(无特殊说明则修改完一分钟内实时生效)

方式一:在apollo页面,依次点击 管理员工具 -> 系统参数 -> 在Key中填入organizations,点击查询 -> 修改Value的Json字符串,点击保存

方式二:直接修改数据库数据,修改ApolloPortalDB.ServerConfig表中Key='organizations'的数据对应的Value值

9.修改启动端口(重启后生效)

9.1.修改configservice端口

configservice和meta service在同一个服务中,共用一个端口,所以修改configservice的端口后,也要将meta service信息进行更新

  • 修改apollo-configservice-2.0.1-github/scripts/startup.sh中的SERVER_PORT

  • 修改meta service信息,包括以下两个内容:

    • 修改apollo-portal-2.0.1-github/config/apollo-env.properties中的meta service地址的端口为configservice的端口

    • 修改ApolloConfigDB.ServerConfig表中Key='eureka.service.url'的数据对应的Value值,修改端口为configservice的端口

9.2.修改adminservice端口
  • 修改apollo-adminservice-2.0.1-github/scripts/startup.sh中的SERVER_PORT即可
9.3.修改portal端口
  • 修改apollo-portal-2.0.1-github/scripts/startup.sh中的SERVER_PORT即可

10.添加环境(重启后生效)

步骤一:在apollo-portal-2.0.1-github/config/apollo-env.properties中添加meta service地址,环境名以.meta结尾

步骤二:修改支持的环境列表(以下方式任选一种即可)

  • 方式一:在ApolloPortalDB.ServerConfig表中Key='apollo.portal.envs'的数据对应的Value值中添加环境名,多个环境间以英文逗号分隔

  • 方式二:在apollo页面,依次点击 管理员工具 -> 系统参数 -> 在Key中填入apollo.portal.envs,点击查询 -> 在Value中添加环境名,多个环境间以英文逗号分隔,点击保存


单机部署多环境多实例

  • 多个环境的情况下,portal只需要部署一套即可,但configservice和adminservice需要每个环境部署一套,每个环境也需要一个对应的ApolloConfigDB数据库

  • 本次部署test和production两个环境,其中:

    • portal部署两个实例,所有环境共用这两个portal,访问其中任一portal即可

    • configservice和adminservice在test环境部署单实例,production环境部署两个实例

  • 各服务实例的端口占用如下:

portal1:11000
portal2:11001
configservice(test):11002
adminservice(test):11003
configservice1(production):11004
configservice2(production):11005
adminservice1(production):11006
adminservice2(production):11007

1.下载代码

github地址:https://github.com/apolloconfig/apollo/tree/v2.0.1

2.数据准备

2.1.准备ApolloPortalDB数据

直接执行apollo-2.0.1/scripts/sql/apolloportaldb.sql

2.2.准备ApolloConfigDB数据

复制apollo-2.0.1/scripts/sql/apolloportaldb.sqlapollo-2.0.1/scripts/sql/apolloportaldb-test.sqlapollo-2.0.1/scripts/sql/apolloportaldb-production.sql

apollo-2.0.1/scripts/sql/apolloportaldb-test.sql中的数据库改为ApolloConfigDBTest,包括创建和使用数据库的两条语句,然后执行该sql文件

apollo-2.0.1/scripts/sql/apolloportaldb-production.sql中的数据库改为ApolloConfigDBProduction,包括创建和使用数据库的两条语句,然后执行该sql文件

3.删除默认配置

3.1.删除打包脚本apollo-2.0.1/scripts/build.bat中关于数据库的内容,被删除部分示例:
rem apollo config db info
set apollo_config_db_url="jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8"
set apollo_config_db_username="root"
set apollo_config_db_password=""rem apollo portal db info
set apollo_portal_db_url="jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8"
set apollo_portal_db_username="root"
set apollo_portal_db_password=""
3.2.删除meta service配置

通过打包脚本传入的环境变量,其优先级高于我们后面要修改的配置文件,所以先删掉这部分内容(apollo加载meta service配置的源码位于com.ctrip.framework.apollo.portal.environment.DefaultPortalMetaServerProvider#initializeDomains

被删除部分示例:

rem meta server url, different environments should have different meta server addresses
set dev_meta="http://localhost:8080"
set fat_meta="http://someIp:8080"
set uat_meta="http://anotherIp:8080"
set pro_meta="http://yetAnotherIp:8080"set META_SERVERS_OPTS=-Ddev_meta=%dev_meta% -Dfat_meta=%fat_meta% -Duat_meta=%uat_meta% -Dpro_meta=%pro_meta%

并删除后面maven打包时使用到META_SERVERS_OPTS变量的地方

4.执行apollo-2.0.1/scripts/build.bat,执行完毕后获取以下文件,并拷贝到安装目录

apollo-2.0.1/apollo-adminservice/target/apollo-adminservice-2.0.1-github.zip
apollo-2.0.1/apollo-configservice/target/apollo-configservice-2.0.1-github.zip
apollo-2.0.1/apollo-portal/target/apollo-portal-2.0.1-github.zip

5.解压文件到对应目录,可参考如下脚本

# 创建文件夹
mkdir -p portal/portal1
mkdir -p portal/portal2
mkdir -p test/configservice
mkdir -p test/adminservice
mkdir -p production/configservice1
mkdir -p production/configservice2
mkdir -p production/adminservice1
mkdir -p production/adminservice2# 解压
unzip apollo-portal-2.0.1-github.zip -d portal/portal1/
unzip apollo-portal-2.0.1-github.zip -d portal/portal2/
unzip apollo-configservice-2.0.1-github.zip -d test/configservice/
unzip apollo-configservice-2.0.1-github.zip -d production/configservice1/
unzip apollo-configservice-2.0.1-github.zip -d production/configservice2/
unzip apollo-adminservice-2.0.1-github.zip -d test/adminservice/
unzip apollo-adminservice-2.0.1-github.zip -d production/adminservice1/
unzip apollo-adminservice-2.0.1-github.zip -d production/adminservice2/

6.修改端口、数据库连接信息、meta service服务地址等

6.1.修改test环境中configservice和adminservice配置

修改端口

  • 修改test/configservice/scripts/startup.shSERVER_PORT为11002

  • 修改test/adminservice/scripts/startup.shSERVER_PORT为11003

添加数据库连接信息

以上两个文件,在JAVA_OPTS变量被定义后,被使用前,添加如下代码(启动时,JAVA_OPTS参数被放在-jar之前,所以此处需要用-D传参,而不能用--。下同)

# 数据库连接信息
apollo_config_db_url='jdbc:mysql://localhost:3306/ApolloConfigDBTest?characterEncoding=utf8'
apollo_config_db_username='root'
apollo_config_db_password='root'JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.url=$apollo_config_db_url -Dspring.datasource.username=$apollo_config_db_username -Dspring.datasource.password=$apollo_config_db_password"
6.2.修改production环境中configservice和adminservice配置

修改端口

  • 修改production/configservice1/scripts/startup.shSERVER_PORT为11004

  • 修改production/configservice2/scripts/startup.shSERVER_PORT为11005

  • 修改production/adminservice1/scripts/startup.shSERVER_PORT为11006

  • 修改production/adminservice2/scripts/startup.shSERVER_PORT为11007

添加数据库连接信息

以上四个文件,在JAVA_OPTS变量被定义后,被使用前,添加如下代码

# 数据库连接信息
apollo_config_db_url='jdbc:mysql://localhost:3306/ApolloConfigDBProduction?characterEncoding=utf8'
apollo_config_db_username='root'
apollo_config_db_password='root'JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.url=$apollo_config_db_url -Dspring.datasource.username=$apollo_config_db_username -Dspring.datasource.password=$apollo_config_db_password"
6.3.修改portal配置

修改端口

  • 修改portal/portal1/scripts/startup.shSERVER_PORT为11000

  • 修改portal/portal2/scripts/startup.shSERVER_PORT为11001

添加数据库连接信息

以上两个文件,在JAVA_OPTS变量被定义后,被使用前,添加如下代码

# 数据库连接信息
apollo_portal_db_url='jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8'
apollo_portal_db_username='root'
apollo_portal_db_password='root'JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.url=$apollo_portal_db_url -Dspring.datasource.username=$apollo_portal_db_username -Dspring.datasource.password=$apollo_portal_db_password"

添加环境信息

portal/portal1/config/apollo-env.propertiesportal/portal2/config/apollo-env.properties的内容清空,然后添加如下内容

test.meta=http://localhost:11002
production.meta=http://localhost:11004,http://localhost:11005

修改数据库中的配置

  • 修改ApolloConfigDBTest.ServerConfigKey=eureka.service.url的数据,将对应的Value改为http://localhost:11002/eureka/

  • 修改ApolloConfigDBProduction.ServerConfigKey=eureka.service.url的数据,将对应的Value改为http://localhost:11004/eureka/,http://localhost:11005/eureka/

  • 修改ApolloPortalDB.ServerConfigKey=apollo.portal.envs的数据,将对应的Value改为test,production

7.启动apollo

依次启动各个环境的configservice、adminservice,最后启动portal,可参考如下脚本

sh test/configservice/scripts/startup.sh
sh test/adminservice/scripts/startup.sh
sh production/configservice1/scripts/startup.sh
sh production/configservice2/scripts/startup.sh
sh production/adminservice1/scripts/startup.sh
sh production/adminservice2/scripts/startup.sh
sh portal/portal1/scripts/startup.sh
sh portal/portal2/scripts/startup.sh

8.访问apollo

由于启动了两个portal服务,所以以下两个地址都可以访问

  • 地址一:

    • 地址:http://localhost:11000

    • 用户名:apollo

    • 密码:admin

  • 地址二:

    • 地址:http://localhost:11001

    • 用户名:apollo

    • 密码:admin

9.停止apollo

可参考如下脚本

sh portal/portal1/scripts/shutdown.sh
sh portal/portal2/scripts/shutdown.sh
sh production/adminservice1/scripts/shutdown.sh
sh production/adminservice2/scripts/shutdown.sh
sh production/configservice1/scripts/shutdown.sh
sh production/configservice2/scripts/shutdown.sh
sh test/adminservice/scripts/shutdown.sh
sh test/configservice/scripts/shutdown.sh

apollo的使用

1.在pom.xml中添加maven依赖

        <dependency><groupId>com.ctrip.framework.apollo</groupId><artifactId>apollo-client-config-data</artifactId><version>2.0.1</version></dependency>

2.在application.properties中添加如下配置

# app id
app.id=001
# meta service服务地址,多个地址用英文逗号隔开
apollo.meta=http://localhost:11004,http://localhost:11005
apollo.bootstrap.enabled=true
# 多个namespace有相同的key时,从左到右优先级从高到低
apollo.bootstrap.namespace=application,local

3.启动应用后即可接入apolloconfig

apolloconfig分布式部署相关推荐

  1. Apollo 分布式部署指南

    目录 一.准备工作 1.1 运行时环境 1.1.1 OS 1.1.2 Java 1.2 MySQL 1.3 环境 1.4 网络策略 二.部署步骤 2.1 创建数据库 2.1.1 创建ApolloPor ...

  2. 大数据之---Yarn伪分布式部署和MapReduce案例

    1.软件环境 RHEL6 角色 jdk-8u45 hadoop-2.8.1.tar.gz   ssh xx.xx.xx.xx ip地址 NN hadoop01 xx.xx.xx.xx ip地址 DN ...

  3. Hadoop1 Centos伪分布式部署

    前言:       毕业两年了,之前的工作一直没有接触过大数据的东西,对hadoop等比较陌生,所以最近开始学习了.对于我这样第一次学的人,过程还是充满了很多疑惑和不解的,不过我采取的策略是还是先让环 ...

  4. 完全分布式部署Hadoop

    完全分布式部署 Hadoop 分析: 1)准备 3 台客户机(关闭防火墙.静态 ip.主机名称) 2)安装 jdk 3)配置环境变量 4)安装 hadoop 5)配置环境变量 6)安装 ssh 7)配 ...

  5. .net Forms身份验证不能用在应用的分布式部署中吗?

    参照网上的一些方法,使用Forms身份验证对应用进行分布式部署,发现没有成功. 应用部署的两台内网服务器:192.168.1.19,192.168.1.87,使用Nginx做负载分配,配置完全相同:每 ...

  6. SCOM 2012知识分享-26:分布式部署要点总结

    适应平台:System Center 2012 R2 Operations Manager+Windows Server 2012 R2 Update+SQL Server 2012 SP1 ---- ...

  7. 白话tensorflow分布式部署和开发

    2019独角兽企业重金招聘Python工程师标准>>> 白话tensorflow分布式部署和开发 博客分类: 深度学习 关于tensorflow的分布式训练和部署, 官方有个英文的文 ...

  8. Redis分布式部署,一致性hash

    一致性哈希 由于hash算法结果一般为unsigned int型,因此对于hash函数的结果应该均匀分布在[0,2^32-1]区间,如果我们把一个圆环用2^32 个点来进行均匀切割,首先按照hash( ...

  9. Apache Spark探秘:三种分布式部署方式比较

    2019独角兽企业重金招聘Python工程师标准>>> 目前Apache Spark支持三种分布式部署方式,分别是standalone.spark on mesos和 spark o ...

最新文章

  1. ATS中的RAM缓存简介
  2. 给kali的metasploit下添加一个新的exploit
  3. 如何修改MySQL8.0.5以上版本root密码
  4. CentOS7安装ipython
  5. Redis:16---常用功能之(慢查询日志)
  6. 职高计算机word教学视频,职高计算机专业Word范例教学三例.doc
  7. 月均数据_数据|| 焊接不锈钢管、卷板、棒相继被调查,出口印度的量逐年降!...
  8. 超全面的的常用RAID详解
  9. 每周一个设计模式之工厂方法与抽象工厂
  10. 程序清单 8-8 exec函数实例,a.out是程序8-9产生的可执行程序
  11. CMS 系统之 iframe 结构
  12. 19.SimLogin_case01
  13. pip下载速度慢的解决办法
  14. 解决git clone出现“error: RPC failed; result= 18,HTTP code = 20018. 00 KiB/s”报错的五个网址(个人用)
  15. 神兽传说JAVA下载_神兽传说3-救赎大陆
  16. C语言IDE和编辑器比较
  17. linux编译gdal geos,GDAL编译支持GEOS
  18. windows下安装设置redis
  19. 计算机网络--DHCP分析实验
  20. 13. Linux权限管理命令

热门文章

  1. 略谈UPS及其技术发历程(二)
  2. SpringMVC 解析(二)DispatcherServlet
  3. 会话描述协议---SDP协议【详解】
  4. 桌面虚拟现实系统是一种以计算机为基础,虚拟现实与增强现实
  5. keepalived主备切换后虚拟IP漂移慢的解决方法
  6. 位(bit)、字节(Byte)、KB、MB、GB、TB之间的换算关系
  7. 20200823-第三十四周-湖有涟漪
  8. 【翻译论文】Object-based land cover classification using airborne LiDAR(2008)
  9. 深度神经网络之tensorflow初体验
  10. serverlet java_IDEA2019 JavaWeb Serverlet 基础