简介
Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境、不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限、流程治理等特性,适用于微服务配置管理场景。
服务端基于Spring Boot和Spring Cloud开发,打包后可以直接运行,不需要额外安装Tomcat等应用容器。
Java客户端不依赖任何框架,能够运行于所有Java运行时环境,同时对Spring/Spring Boot环境也有较好的支持。
.Net客户端不依赖任何框架,能够运行于所有.Net运行时环境。
更多产品介绍参见Apollo配置中心介绍
本地快速部署请参见Quick Start
演示环境(Demo):
- 106.54.227.205
- 账号/密码:apollo/admin
如访问github速度缓慢,可以访问gitee镜像,不定期同步
环境准备
- MYSQL 5.7
- MAVEN 3.6
- JDK 1.8
- 注意,三套环境供用一个数据库,使用不同的库而已。
- 仅供参考,根据自己实际环境进行配置。
DEV | 10.10.1.29 | apollo-adminservice,apollo-configservice,apollo-portal,mysql |
UAT | 10.10.1.30 | admin,config |
PRO | 10.10.1.31 | admin,config |
- 安装数据库
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# yum -y install mysql-community-server [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# systemctl start mysqld.service [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# systemctl enable mysqld.service [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# grep "password" /var/log/mysqld.log 2020-08-18T11:24:22.809354Z 1 [Note] A temporary password is generated for root@localhost: kDrBzNp&k53B [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# mysql -uroot -p Enter password: mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'XIAOXIN@root2758'; Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges on *.* to 'root'@'%' identified by 'XIAOXIN@root2758'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
- 安装jdk,三台机器一起
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# tar zxf jdk-8u151-linux-x64.tar.gz [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# rm jdk-8u151-linux-x64.tar.gz [root@iZ2ze2wuri2qoajwrtuzzzZ ~]# mv jdk1.8.0_151 /usr/local/jdk1.8 [root@iZ2ze2wuri2qoajwrtuzzzZ ~]# cat >> /etc/profile<<EOF JAVA_HOME=/usr/local/jdk1.8/ JAVA_BIN=/usr/local/jdk1.8/bin JRE_HOME=/usr/local/jdk1.8/jre PATH=$PATH:/usr/local/jdk1.8/bin:/usr/local/jdk1.8/jre/bin CLASSPATH=/usr/local/jdk1.8/jre/lib:/usr/local/jdk1.8/lib:/usr/local/jdk1.8/jre/lib/charsets.jar EOF [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# source /etc/profile [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# java -version openjdk version "1.8.0_262" OpenJDK Runtime Environment (build 1.8.0_262-b10) OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
- 安装maven,三台一起
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz [root@iZ2ze2wuri2qoajwrtuzzzZ ~]# tar -xvf apache-maven-3.3.9-bin.tar.gz [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# mv -f apache-maven-3.3.9 /usr/local/ [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# vim /etc/profile export MAVEN_HOME=/usr/local/apache-maven-3.3.9 export PATH=${PATH}:${MAVEN_HOME}/bin [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# source /etc/profile [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# mvn -v Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00) Maven home: /usr/local/apache-maven-3.3.9 Java version: 1.8.0_151, vendor: Oracle Corporation Java home: /usr/local/jdk1.8/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-1127.13.1.el7.x86_64", arch: "amd64", family: "unix"
- 三台机器下载源码
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# git clone https://github.com/ctripcorp/apollo
修改配置文件
- DEV节点
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# vim apollo/scripts/build.sh #!/bin/sh # apollo config db info apollo_config_db_url=jdbc:mysql://10.10.1.29:3306/ApolloConfigDB?characterEncoding=utf8 apollo_config_db_username=root apollo_config_db_password=XIAOXIN@root2758 # apollo portal db info apollo_portal_db_url=jdbc:mysql://10.10.1.29:3306/ApolloPortalDB?characterEncoding=utf8 apollo_portal_db_username=root apollo_portal_db_password=XIAOXIN@root2758 # meta server url, different environments should have different meta server addresses dev_meta=http://10.10.1.29:8080 fat_meta=http://fill-in-fat-meta-server:8080 uat_meta=http://10.10.1.30:8080 pro_meta=http://10.10.1.31:8080 META_SERVERS_OPTS="-Ddev_meta=$dev_meta -Dfat_meta=$fat_meta -Duat_meta=$uat_meta -Dpro_meta=$pro_meta"
- UAT节点
[root@iZ2ze2wuri2qoajwrtv000Z ~]# vim apollo/scripts/build.sh #!/bin/sh # apollo config db info apollo_config_db_url=jdbc:mysql://10.10.1.29:3306/UATApolloConfigDB?characterEncoding=utf8 apollo_config_db_username=root apollo_config_db_password=XIAOXIN@root2758 # apollo portal db info apollo_portal_db_url=jdbc:mysql://10.10.1.29:3306/UATApolloPortalDB?characterEncoding=utf8 apollo_portal_db_username=root apollo_portal_db_password=XIAOXIN@root2758 # meta server url, different environments should have different meta server addresses dev_meta=http://fill-in-dev-meta-server:8080 fat_meta=http://fill-in-fat-meta-server:8080 uat_meta=http://10.10.1.30:8080 pro_meta=http://fill-in-pro-meta-server:8080 META_SERVERS_OPTS="-Ddev_meta=$dev_meta -Dfat_meta=$fat_meta -Duat_meta=$uat_meta -Dpro_meta=$pro_meta"
- PRO节点
[root@iZ2ze2wuri2qoajwrtuzzzZ ~]# vim apollo/scripts/build.sh #!/bin/sh # apollo config db info apollo_config_db_url=jdbc:mysql://10.10.1.29:3306/PROApolloConfigDB?characterEncoding=utf8 apollo_config_db_username=root apollo_config_db_password=XIAOXIN@root2758 # apollo portal db info apollo_portal_db_url=jdbc:mysql://10.10.1.29:3306/PROApolloPortalDB?characterEncoding=utf8 apollo_portal_db_username=root apollo_portal_db_password=XIAOXIN@root2758 # meta server url, different environments should have different meta server addresses 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 pro_meta=http://10.10.1.31:8080 META_SERVERS_OPTS="-Ddev_meta=$dev_meta -Dfat_meta=$fat_meta -Duat_meta=$uat_meta -Dpro_meta=$pro_meta"
导入三个环境的数据库配置
- dev使用默认的,直接导入即可。
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# mysql -uroot -pXIAOXIN@root2758 mysql> source /root/apollo/scripts/sql/apolloconfigdb.sql mysql> source /root/apollo/scripts/sql/apolloportaldb.sql
- 导入uat库,修改一下库名
[root@iZ2ze2wuri2qoajwrtuzzyZ sql]# vim apolloconfigdb.sql # Create Database # ------------------------------------------------------------ CREATE DATABASE IF NOT EXISTS UATApolloConfigDB DEFAULT CHARACTER SET = utf8mb4; Use UATApolloConfigDB; mysql> source /root/apollo/scripts/sql/apolloconfigdb.sql
- 导入PRD库,修改一下库名
[root@iZ2ze2wuri2qoajwrtuzzyZ sql]# vim apolloconfigdb.sql # Create Database # ------------------------------------------------------------ CREATE DATABASE IF NOT EXISTS PROApolloConfigDB DEFAULT CHARACTER SET = utf8mb4; Use PROApolloConfigDB; # Dump of table app mysql> source /root/apollo/scripts/sql/apolloconfigdb.sql mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | ApolloConfigDB | | ApolloPortalDB | | PROApolloConfigDB | | UATApolloConfigDB | | mysql | | performance_schema | | sys | +--------------------+ 8 rows in set (0.00 sec)
修改三个环境的网络策略
- 修改dev节点
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# vim apollo/apollo-adminservice/src/main/resources/bootstrap.yml eureka: instance: homePageUrl: http://10.10.1.29:8090 hostname: ${hostname:localhost} preferIpAddress: true status-page-url-path: /info health-check-url-path: /health [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# vim apollo/apollo-configservice/src/main/resources/bootstrap.yml eureka: instance: homePageUrl: http://10.10.1.29:8080 hostname: ${hostname:localhost} preferIpAddress: true status-page-url-path: /info health-check-url-path: /health
- 修改uat节点
[root@iZ2ze2wuri2qoajwrtv000Z ~]# vim apollo/apollo-adminservice/src/main/resources/bootstrap.yml eureka: instance: homePageUrl: http://10.10.1.30:8090 hostname: ${hostname:localhost} preferIpAddress: true status-page-url-path: /info health-check-url-path: /health [root@iZ2ze2wuri2qoajwrtv000Z ~]# vim apollo/apollo-configservice/src/main/resources/bootstrap.yml eureka: instance: homePageUrl: http://10.10.1.30:8080 hostname: ${hostname:localhost} preferIpAddress: true status-page-url-path: /info health-check-url-path: /health
- 修改pro节点
[root@iZ2ze2wuri2qoajwrtuzzzZ ~]# vim apollo/apollo-adminservice/src/main/resources/bootstrap.yml eureka: instance: homePageUrl: http://10.10.1.31:8090 hostname: ${hostname:localhost} preferIpAddress: true status-page-url-path: /info health-check-url-path: /health [root@iZ2ze2wuri2qoajwrtuzzzZ ~]# vim apollo/apollo-configservice/src/main/resources/bootstrap.yml eureka: instance: homePageUrl: http://10.10.1.31:8080 hostname: ${hostname:localhost} preferIpAddress: true status-page-url-path: /info health-check-url-path: /health
修改Eureka服务的URL值
- 修改默认的dev
- 修改UAT
- 修改PRO
- 修改一下设置的环境
mysql> use ApolloPortalDB; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select*from ServerConfig; +----+-------------------------------------+-------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+-----------+----------------------+------------------------+---------------------------+---------------------+ | Id | Key | Value | Comment | IsDeleted | DataChange_CreatedBy | DataChange_CreatedTime | DataChange_LastModifiedBy | DataChange_LastTime | +----+-------------------------------------+-------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+-----------+----------------------+------------------------+---------------------------+---------------------+ | 1 | apollo.portal.envs | dev | 可支持的环境列表 | | default | 2020-08-19 11:01:04 | | 2020-08-19 11:01:04 | | 2 | organizations | [{"orgId":"TEST1","orgName":"样例部门1"},{"orgId":"TEST2","orgName":"样例部门2"}] | 部门列表 | | default | 2020-08-19 11:01:04 | | 2020-08-19 11:01:04 | | 3 | superAdmin | apollo | Portal超级管理员 | | default | 2020-08-19 11:01:04 | | 2020-08-19 11:01:04 | | 4 | api.readTimeout | 10000 | http接口read timeout | | default | 2020-08-19 11:01:04 | | 2020-08-19 11:01:04 | | 5 | consumer.token.salt | someSalt | consumer token salt | | default | 2020-08-19 11:01:04 | | 2020-08-19 11:01:04 | | 6 | admin.createPrivateNamespace.switch | true | 是否允许项目管理员创建私有namespace | | default | 2020-08-19 11:01:04 | | 2020-08-19 11:01:04 | | 7 | configView.memberOnly.envs | pro | 只对项目成员显示配置信息的环境列表,多个env以英文逗号分隔 | | default | 2020-08-19 11:01:04 | | 2020-08-19 11:01:04 | | 8 | apollo.portal.meta.servers | {} | 各环境Meta Service列表 | | default | 2020-08-19 11:01:04 | | 2020-08-19 11:01:04 | +----+-------------------------------------+-------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+-----------+----------------------+------------------------+---------------------------+---------------------+ 8 rows in set (0.00 sec) mysql> update ServerConfig set Value='dev,uat,pro'where id=1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
构建
- 三台一起
[root@iZ2ze2wuri2qoajwrtuzzzZ ~]# ./apollo/scripts/build.sh
- 将构建出来的压缩包,拷贝到指定目录,三台一起操作。(UAT和PRO不需要拷贝apollo-portal包,供用一个portal)
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# mkdir -p /opt/{data,logs} [root@iZ2ze2wuri2qoajwrtuzzyZ data]# chmod 777 /opt/logs [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# cp apollo/apollo-adminservice/target/apollo-adminservice-1.8.0-SNAPSHOT-github.zip /opt/data/ [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# cp apollo/apollo-configservice/target/apollo-configservice-1.8.0-SNAPSHOT-github.zip /opt/data/ [root@iZ2ze2wuri2qoajwrtuzzyZ ~]# cp apollo/apollo-portal/target/apollo-portal-1.8.0-SNAPSHOT-github.zip /opt/data/
解压和启动
- 在dev机器上操作
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# cd /opt/data/ [root@iZ2ze2wuri2qoajwrtuzzyZ data]# ls apollo-adminservice-1.8.0-SNAPSHOT-github.zip apollo-configservice-1.8.0-SNAPSHOT-github.zip apollo-portal-1.8.0-SNAPSHOT-github.zip [root@iZ2ze2wuri2qoajwrtuzzyZ data]# unzip apollo-adminservice-1.8.0-SNAPSHOT-github.zip -d apollo-adminservice Archive: apollo-adminservice-1.8.0-SNAPSHOT-github.zip creating: apollo-adminservice/scripts/ inflating: apollo-adminservice/scripts/startup.sh inflating: apollo-adminservice/config/application-github.properties inflating: apollo-adminservice/apollo-adminservice-1.8.0-SNAPSHOT-sources.jar inflating: apollo-adminservice/scripts/shutdown.sh inflating: apollo-adminservice/config/app.properties inflating: apollo-adminservice/apollo-adminservice.conf inflating: apollo-adminservice/apollo-adminservice-1.8.0-SNAPSHOT.jar [root@iZ2ze2wuri2qoajwrtuzzyZ data]# unzip apollo-configservice-1.8.0-SNAPSHOT-github.zip -d apollo-configservice Archive: apollo-configservice-1.8.0-SNAPSHOT-github.zip creating: apollo-configservice/scripts/ inflating: apollo-configservice/scripts/startup.sh creating: apollo-configservice/config/ inflating: apollo-configservice/config/app.properties inflating: apollo-configservice/apollo-configservice.conf inflating: apollo-configservice/config/application-github.properties inflating: apollo-configservice/apollo-configservice-1.8.0-SNAPSHOT-sources.jar inflating: apollo-configservice/apollo-configservice-1.8.0-SNAPSHOT.jar inflating: apollo-configservice/scripts/shutdown.sh [root@iZ2ze2wuri2qoajwrtuzzyZ data]# unzip apollo-portal-1.8.0-SNAPSHOT-github.zip -d apollo-portal Archive: apollo-portal-1.8.0-SNAPSHOT-github.zip creating: apollo-portal/scripts/ inflating: apollo-portal/scripts/startup.sh creating: apollo-portal/config/ inflating: apollo-portal/config/app.properties inflating: apollo-portal/apollo-portal.conf inflating: apollo-portal/config/apollo-env.properties inflating: apollo-portal/config/application-github.properties inflating: apollo-portal/apollo-portal-1.8.0-SNAPSHOT-sources.jar inflating: apollo-portal/scripts/shutdown.sh inflating: apollo-portal/apollo-portal-1.8.0-SNAPSHOT.jar [root@iZ2ze2wuri2qoajwrtuzzyZ data]# ll total 150428 drwxr-xr-x 4 root root 4096 Aug 19 14:18 apollo-adminservice -rw-r--r-- 1 root root 54498833 Aug 19 13:52 apollo-adminservice-1.8.0-SNAPSHOT-github.zip drwxr-xr-x 4 root root 4096 Aug 19 14:18 apollo-configservice -rw-r--r-- 1 root root 57809474 Aug 19 14:07 apollo-configservice-1.8.0-SNAPSHOT-github.zip drwxr-xr-x 4 root root 4096 Aug 19 14:19 apollo-portal -rw-r--r-- 1 root root 41712306 Aug 19 14:08 apollo-portal-1.8.0-SNAPSHOT-github.zip [root@iZ2ze2wuri2qoajwrtuzzyZ data]# ./apollo-adminservice/scripts/startup.sh Wed Aug 19 14:20:13 CST 2020 ==== Starting ==== Started [23061] Waiting for server startup../apo.... . Wed Aug 19 14:20:44 CST 2020 Server started in 30 seconds! [root@iZ2ze2wuri2qoajwrtuzzyZ data]# ./apollo-portal/scripts/startup.sh Wed Aug 19 14:21:04 CST 2020 ==== Starting ==== Started [23292] Waiting for server startup.... Wed Aug 19 14:21:24 CST 2020 Server started in 20 seconds! [root@iZ2ze2wuri2qoajwrtuzzyZ data]# ./apollo-configservice/scripts/startup.sh Wed Aug 19 14:21:43 CST 2020 ==== Starting ==== Started [23478] Waiting for server startup...... Wed Aug 19 14:22:14 CST 2020 Server started in 30 seconds!
- 在uat机器上操作
[root@iZ2ze2wuri2qoajwrtuzzzZ data]# cd /opt/data/ [root@iZ2ze2wuri2qoajwrtuzzzZ data]# unzip apollo-adminservice-1.8.0-SNAPSHOT-github.zip -d apollo-adminservice Archive: apollo-adminservice-1.8.0-SNAPSHOT-github.zip creating: apollo-adminservice/scripts/ inflating: apollo-adminservice/scripts/startup.sh creating: apollo-adminservice/config/ inflating: apollo-adminservice/config/app.properties inflating: apollo-adminservice/config/application-github.properties inflating: apollo-adminservice/apollo-adminservice-1.8.0-SNAPSHOT-sources.jar inflating: apollo-adminservice/scripts/shutdown.sh inflating: apollo-adminservice/apollo-adminservice.conf inflating: apollo-adminservice/apollo-adminservice-1.8.0-SNAPSHOT.jar [root@iZ2ze2wuri2qoajwrtuzzzZ data]# unzip apollo-configservice-1.8.0-SNAPSHOT-github.zip -d apollo-configservice Archive: apollo-configservice-1.8.0-SNAPSHOT-github.zip inflating: apollo-configservice/scripts/shutdown.sh creating: apollo-configservice/config/ inflating: apollo-configservice/config/app.properties inflating: apollo-configservice/config/application-github.properties inflating: apollo-configservice/apollo-configservice-1.8.0-SNAPSHOT.jar inflating: apollo-configservice/scripts/startup.sh inflating: apollo-configservice/apollo-configservice.conf inflating: apollo-configservice/apollo-configservice-1.8.0-SNAPSHOT-sources.jar [root@iZ2ze2wuri2qoajwrtuzzzZ data]# ./apollo-adminservice/scripts/startup.sh Wed Aug 19 14:24:42 CST 2020 ==== Starting ==== Started [12853] Waiting for server startup...... Wed Aug 19 14:25:13 CST 2020 Server started in 30 seconds! [root@iZ2ze2wuri2qoajwrtuzzzZ data]# ./apollo-configservice/scripts/startup.sh Wed Aug 19 14:25:25 CST 2020 ==== Starting ==== Started [13014] Waiting for server startup...... Wed Aug 19 14:25:56 CST 2020 Server started in 30 seconds!
- 在pro机器上操作
[root@iZ2ze2wuri2qoajwrtv000Z ~]# cd /opt/data/ [root@iZ2ze2wuri2qoajwrtv000Z data]# unzip apollo-adminservice-1.8.0-SNAPSHOT-github.zip -d apollo-adminservice Archive: apollo-adminservice-1.8.0-SNAPSHOT-github.zip creating: apollo-adminservice/scripts/ inflating: apollo-adminservice/scripts/startup.sh creating: apollo-adminservice/config/ inflating: apollo-adminservice/config/app.properties inflating: apollo-adminservice/apollo-adminservice.conf inflating: apollo-adminservice/config/application-github.properties inflating: apollo-adminservice/apollo-adminservice-1.8.0-SNAPSHOT.jar inflating: apollo-adminservice/scripts/shutdown.sh inflating: apollo-adminservice/apollo-adminservice-1.8.0-SNAPSHOT-sources.jar [root@iZ2ze2wuri2qoajwrtv000Z data]# unzip apollo-configservice-1.8.0-SNAPSHOT-github.zip -d apollo-configservice Archive: apollo-configservice-1.8.0-SNAPSHOT-github.zip creating: apollo-configservice/scripts/ inflating: apollo-configservice/scripts/startup.sh creating: apollo-configservice/config/ inflating: apollo-configservice/config/app.properties inflating: apollo-configservice/config/application-github.properties inflating: apollo-configservice/apollo-configservice-1.8.0-SNAPSHOT.jar inflating: apollo-configservice/scripts/shutdown.sh inflating: apollo-configservice/apollo-configservice.conf inflating: apollo-configservice/apollo-configservice-1.8.0-SNAPSHOT-sources.jar [root@iZ2ze2wuri2qoajwrtv000Z data]# ./apollo-adminservice/scripts/startup.sh Wed Aug 19 14:27:22 CST 2020 ==== Starting ==== Started [12858] Waiting for server startup...... Wed Aug 19 14:27:53 CST 2020 Server started in 30 seconds! [root@iZ2ze2wuri2qoajwrtv000Z data]# ./apollo-configservice/scripts/startup.sh Wed Aug 19 14:28:05 CST 2020 ==== Starting ==== Started [13019] Waiting for server startup...... Wed Aug 19 14:28:36 CST 2020 Server started in 30 seconds!
到此为止,集群已安装完成。
验证
- 先看Eureka
- 验证admin
- 验证apollo
- 账号/密码:apollo/admin
继续阅读
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论