简介

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

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

进入apollo容器命令 apollo console_sql

 

上图简要描述了配置发布的大致过程:

  • 用户在Portal操作配置发布
  • Portal调用Admin Service的接口操作发布
  • Admin Service发布配置后,发送ReleaseMessage给各个Config Service
  • Config Service收到ReleaseMessage后,通知对应的客户端

 

安装部署

docker安装

#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state
#关闭selinux
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config && setenforce 0
#安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce-19.03.5 -y
#启动docker并设置开机自启
systemctl start docker && systemctl enable docker
#docker-compose编排工具安装方式
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose && ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose 
#查看版本
docker version && docker-compose --version
#设置容器镜像加速器
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://zx28up8j.mirror.aliyuncs.com"]
}
EOF
#重载配置并重启docker
systemctl daemon-reload && systemctl restart docker

apollo安装

cd /usr/local/src
git clone -b 1.5.1 https://github.com/ctripcorp/apollo.git 或者 wget https://github.com/ctripcorp/apollo/archive/v1.5.1.tar.gz #解压后更改目录名为apollo
mkdir -p apollo-adminservice apollo-portal apollo-configservice portal-sql config-sql
cp apollo/scripts/docker-quick-start/sql/apolloconfigdb.sql config-sql/
cp apollo/scripts/docker-quick-start/sql/apolloportaldb.sql portal-sql/
#防止容器ip注册到Eureka的方案有:
#方案一:把docker0和veth.*的网卡在注册到Eureka时忽略掉(用此方案就行)
sed -i '/active:/a\  cloud:\
    inetutils:\
      ignoredInterfaces:\
        - docker0\
        - veth.*' apollo/{apollo-adminservice,apollo-configservice}/src/main/resources/application.yml
#方案二:强制指定admin server和config server向eureka注册的IP
#sed -i '/instance:/a\    ip-address: ${eurekaip-address}' apollo/{apollo-adminservice,apollo-configservice}/src/main/resources/bootstrap.yml
#更多方案,查看https://github.com/ctripcorp/apollo/wiki/部署&开发遇到的常见问题

进入apollo容器命令 apollo console_docker_02

 

 

进入apollo容器命令 apollo console_sql_03

 

 

源码构建

#依赖maven3和jdk8环境,请先安装好!
#注:Maven之阿里云镜像仓库配置maven/conf/settings.xml
    <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>*</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
#执行编译打包脚本
sh apollo/scripts/build.sh
#打包完成后执行
cp apollo/apollo-adminservice/target/apollo-adminservice-1.5.1-github.zip apollo-adminservice
cp apollo/apollo-configservice/target/apollo-configservice-1.5.1-github.zip apollo-configservice
cp apollo/apollo-portal/target/apollo-portal-1.5.1-github.zip apollo-portal
cp apollo/apollo-adminservice/src/main/docker/Dockerfile apollo-adminservice
cp apollo/apollo-configservice/src/main/docker/Dockerfile apollo-configservice
cp apollo/apollo-portal/src/main/docker/Dockerfile apollo-portal
#开始生成docker镜像
cat docker-compose.yml #新建此文件
version: "3"
services:
  apollo-configservice:
    container_name: apollo-configservice
    build: apollo-configservice/
    image: apollo_configservice
    ports:
      - "8080:8080"
    environment:
      DS_URL: "jdbc:mysql://本机IP:3307/ApolloConfigDB?characterEncoding=utf8"
      DS_USERNAME: "root"
      DS_PASSWORD: "Doordu"
      eurekaip-address: "本机IP"
    volumes:
      - /opt/logs/100003171:/opt/logs/100003171
    depends_on:
      - config-db 
    restart: always
  config-db:
    container_name: config-db
    image: mysql:5.7
    restart: always
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: Doordu
    ports:
      - "3307:3306"
    volumes:
      - /data/config-db:/var/lib/mysql
      - /usr/local/src/config-sql:/docker-entrypoint-initdb.d
  apollo-adminservice:
    container_name: apollo-adminservice
    image: apollo_adminservice
    build: apollo-adminservice/
    ports:
      - "8090:8090"
    environment:
      DS_URL: "jdbc:mysql://本机IP:3307/ApolloConfigDB?characterEncoding=utf8"
      DS_USERNAME: "root"
      DS_PASSWORD: "Doordu"
      eurekaip-address: "本机IP"
    volumes:
      - /opt/logs/100003172:/opt/logs/100003172
    depends_on:
      - apollo-configservice
    restart: always
  apollo-portal:
    container_name: apollo-portal
    build: apollo-portal/
    image: apollo-portal
    ports:
      - "8070:8070"
    environment:
      DS_URL: "jdbc:mysql://本机IP:3306/ApolloPortalDB?characterEncoding=utf8"
      DS_USERNAME: "root"
      DS_PASSWORD: "Doordu"
      DEV_META: "http://本机IP:8080"
    volumes:
      - /opt/logs/100003173:/opt/logs/100003173
    depends_on:
      - apollo-db
      - apollo-adminservice
    restart: always
  apollo-db:
    container_name: apollo-db
    image: mysql:5.7
    restart: always
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: Doordu
    ports:
      - "3306:3306"
    volumes:
      - /usr/local/src/portal-sql:/docker-entrypoint-initdb.d
      - /data/apollo-db:/var/lib/mysql

启动容器

docker-compose build && docker-compose up -d #启动编排文件里面的容器

进入apollo容器命令 apollo console_IP_04

 

 

docker-compose ps #查看容器启动情况

进入apollo容器命令 apollo console_sql_05

 

 

#日志文件路径
/opt/logs/
#由于configservice容器自带了eureka服务,把服务注册地址修改为物理机所映射的端口,也就是8080,执行
docker exec -it config-db mysql -u root -pDoordu -D ApolloConfigDB -e "update ServerConfig set Value = 'http://本机IP:8080/eureka/' where id = 1;"
#apollo界面
http://本机IP:8070
账:apollo 密:admin
#eureka界面
http://本机IP:8080
#针对不同环境修改权限,登录控制端数据库,经测试填入pro则屏蔽pro环境的配置,忽略掉官方备注!o(∩_∩)o

 

燃烧吧,骚年.