Docker compose one click deployment of distributed configuration center Apollo

Posted by michibk on Thu, 23 Sep 2021 07:34:26 +0200

brief introduction

When talking about distributed, we must think of distributed configuration center, distributed log, distributed link tracking, etc

In distributed deployment, businesses often have many configurations. For example, applications need to read some configuration information during startup and operation. Configuration basically accompanies the whole life cycle of applications, such as database connection parameters and startup parameters, which need to be maintained and configured, but it is impossible to log in to configure one server at a time
Today, I want to share with you the distributed configuration center Apollo:

Apollo (Apollo) is a distributed configuration center developed by Ctrip framework department. It can centrally manage the configuration of different application environments and clusters. After the configuration is modified, it can be pushed to the application end in real time. It also has standardized permissions, process governance and other characteristics. It is suitable for micro service configuration management scenarios.

build

There are two building methods in the official documents. One is to download the source code and the other is to use Docker or K8S. Today we use Docker to build. After all, Docker is more friendly to developers.

If Mysql service is available, it is recommended to use Mysql service or cloud service RDS as the database. After all, the data is priceless.

version: "3"
services:
  apollo-configservice: #Config Service provides functions such as reading and pushing configuration, and the service object is the Apollo client
    image: apolloconfig/apollo-configservice:1.8.1
    restart: always
    #container_name: apollo-configservice
    volumes:
          - ./logs/apollo-configservice:/opt/logs
    ports:
      - "8080:8080"
    environment:
      - TZ='Asia/Shanghai'    
      - SERVER_PORT=8080
      - EUREKA_INSTANCE_IP_ADDRESS=xxx.xxx.xxx.xxx
      - EUREKA_INSTANCE_HOME_PAGE_URL=http://xxx.xxx.xxx.xxx:8080
      - SPRING_DATASOURCE_URL=jdbc:mysql://xxx.xxx.xxx.xxx:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai
      - SPRING_DATASOURCE_USERNAME=root
      - SPRING_DATASOURCE_PASSWORD=MysqkPassWord!
      
      
  apollo-adminservice: #Admin Service provides configuration modification, publishing and other functions. The service object is Apollo Portal (Management Interface)
    image: apolloconfig/apollo-adminservice:1.8.1
    restart: always
    #container_name: apollo-adminservice
    volumes:
      - ./logs/apollo-adminservice:/opt/logs
    ports:
      - "8090:8090"
    depends_on:
      - apollo-configservice
    environment:
      - TZ='Asia/Shanghai'    
      - SERVER_PORT=8090
      - EUREKA_INSTANCE_IP_ADDRESS=xxx.xxx.xxx.xxx
      - SPRING_DATASOURCE_URL=jdbc:mysql://xxx.xxx.xxx.xxx:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai
      - SPRING_DATASOURCE_USERNAME=root
      - SPRING_DATASOURCE_PASSWORD=MysqkPassWord!
      
      
  apollo-portal: #Management interface
    image: apolloconfig/apollo-portal:1.8.1
    restart: always
    container_name: apollo-portal
    volumes:
      - ./logs/apollo-portal:/opt/logs
    ports:
      - "8070:8070"
    depends_on:
      - apollo-adminservice
    environment:
      - TZ='Asia/Shanghai'    
      - SERVER_PORT=8070
      - EUREKA_INSTANCE_IP_ADDRESS=xxx.xxx.xxx.xxx
      - APOLLO_PORTAL_ENVS=dev
      - DEV_META=http://xxx.xxx.xxx.xxx:8080
      - SPRING_DATASOURCE_URL=jdbc:mysql://xxx.xxx.xxx.xxx:3306/ApolloPortalDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai
      - SPRING_DATASOURCE_USERNAME=root
      - SPRING_DATASOURCE_PASSWORD=MysqkPassWord!

As can be seen from the above docker-compose.yaml, there are three services, namely:

  1. Config Service provides functions such as reading and pushing configuration, and the service object is the Apollo client

  2. Admin Service provides configuration modification, publishing and other functions. The service object is Apollo Portal (Management Interface)

  3. Portal (administration interface)
    If you want to know how they work, it is recommended to check the official documents

The logs are mounted to the external. / logs directory

You can see that the deployment of Mysql is not given above. If you need to deploy Mysql using a container, please refer to docker-compose.yaml below

version: '3'

services: 

  mysql: # myslq database
    image: 'mysql/mysql-server'
    container_name: 'mysql'
    restart: always
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --lower-case-table-names=1
    environment: #environment variable
      MYSQL_ROOT_HOST: "%" 
      MYSQL_ROOT_PASSWORD: password
      MYSQL_USER: brook
      MYSQL_PASSWORD: password
    ports:
      - "3306:3306"

The above mysql docker-compose.yaml is only for testing

Initialize database
initialization

[apolloconfigdb.sql]( https://github.com/apolloconfig/apollo/blob/master/scripts/docker-quick-start/sql/apolloconfigdb.sql )And [Apollo PORTALDB. SQL]( https://github.com/apolloconfig/apollo/blob/master/scripts/docker-quick-start/sql/apolloportaldb.sql )


After the database is initialized, remember to modify eureka.service.url of the serverconfig table in the Apollo config DB library, otherwise the Apollo admin service cannot be registered with Eureka
 

After modification, switch to the Apollo docker-compose.yaml directory and use

docker-compose up -d #Start the three services in the file and run in the background


View startup

docker-compose ps


visit http://10.0.0.53:8070/ #Apollo management end


Default user name: apollo
Default password: admin


Create a test project
 

test

Create a. NetCore project and add Apollo.net client

Add Apollo


Configure Apollo

Configuration above

Add test content
Get Apollo in code

Initiator request / weatherforecast / Apollo test


It was found that the configuration set in apollo was not obtained

Check Apollo and find that the configured value is not published


So if you configure or modify Apollo, you must remember to publish it. After publishing, we refresh the browser again


It is found that the data is new. Let's modify the Value of Apollo again


Refresh


To this end, Apollo has been built and can be used normally

code

The code in the example is

https://github.com/yuefengkai/Brook.Apollo

Welcome to Start

Note: if the configuration cannot be pulled after the program is started, you can open the Apollo log, see the detailed configuration in the console, and put it in the first line of the Program.cs Main function!

LogManager.UseConsoleLogging(Com.Ctrip.Framework.Apollo.Logging.LogLevel.Trace);

reference resources

1.https://github.com/apolloconfig/apollo.net
2.https://github.com/apolloconfig/apollo
3.https://github.com/apolloconfig/apollo/tree/master/scripts/docker-quick-start

Topics: ASP.NET Docker docker compose apollo