1024programmer Asp.Net Deployment and usage experience of Apollo Configuration Center

Deployment and usage experience of Apollo Configuration Center

Deployment and usage experience of Apollo Configuration Center

Deployment and usage experience of Apollo Configuration Center
Apollo features: Mature and stable. Supports management of configurations in multiple environments/multi-clusters/multi-namespaces. Real-time (1s) notification of configuration modifications to applications. Supports permission control, configuration inheritance, version management, grayscale release, usage monitoring, etc.

Foreword

Apollo is Ctrip’s open source distributed configuration management center.

This article mainly introduces its deployment and installation based on Docker-Compose and some usage experience

Features

  • Mature and stable
  • Supports management of configurations of multiple environments/multi-clusters/multi-namespaces
  • Configuration modifications publish real-time (1s) notifications to applications
  • Supports permission control, configuration inheritance, version management, grayscale publishing, usage monitoring, etc.
  • Officially provided. NET/Java/Go SDK and Http interface
  • Made in Chinese, friendly documentation, endorsed by major manufacturers, mature usage solutions
  • Easy to use, supports Docker, K8S, and the official also provides a variety of high-availability solution references

usage

  • Currently used as a configuration center in microservice projects, with stable performance and good experience
  • Memory situation: When the new installation is started, it is about 100M. When working on 20 projects and 80 clients, the three services occupy about 1.5G
  • The test environment and the production environment are separated to ensure safety and avoid incorrect operations
  • Why choose Apollo: stable & simple. Although it is not as good as Nacos in performance and does not have service discovery function, it is stable! ! !
  • Before I deployed it myself, I would have thought this thing was so difficult, heavy, and troublesome. There are only two words for my feelings when writing this article: awesome*

Practice

Preparation

  • Current version: v2.1

  • apollo-db: mysql 5.6.6+ database

    • Default port: 3306
    • Depends on two databases: ApolloPortalDB, ApolloConfigDB
    • Default account/password: apollo/admin
  • apollo-configservice: Config Service provides functions such as reading and pushing configurations.

    • Default port: 8080
    • The application connects to this service using
  • apollo-adminservice: Admin Service provides configuration modification, publishing and other functions

    • Default port: 8090
    • The management interface uses this service
  • apollo-portal: Portal provides a web interface to manage configuration

    • Default port: 8070
    • Web management interface
    • Default account/password: apollo/admin
  • Deureka: Provides service registration and discovery

    • Config Service and Admin Service will register services with Eureka and maintain heartbeats
    • Need to specify eureka.service.url
    • in Admin Service

  • The priorities of service configuration methods from high to low are: system parameters>environment variables>external configuration files

Install using Docker Compose

This article is based on Docker V24 and Docker Compose V2. For installation, please refer to previous articles

Configuration instructions

  • The log file is mounted. /logs directory
  • Fixed the image version mysql v5.7, apollo v2.1.0
  • Specify MySql account password: root devops666, modified port mapping 13306:3306
  • Mount MySql data and initialize the script folder. /initsql (v2.1 script)
  • Use the service name apollo-db in the Apollo service to connect to MySql: SPRING_DATASOURCE_URL:'...apollo-db:3306/...'
  • Set to start the database first: depends_on:apollo-db
  • The apollo-configservice service specifies the address registered with Deureka (Apollo service discovery component): http://192.168.123.214:8080
  • Specify the service address registered with Deureka in the apollo-adminservice service: http://192.168.123.214:809
  • The apollo-adminservice service needs to specify the Deureka service address: -Deureka.service.url=``http://192.168.123.214:8080/eureka/
  • Specify the network: devopsnetwork (docker network create devopsnetwork)
  • The default account password of the web management terminal is: apollo admin, change it after logging in! ! !

Configuration file compose.yml

  • Prepare compose.yml and . /initsql/Initialization script, modify the IP in it

  • Copy to server

  • Then run docker compose up -d

     version: '3.1'
      services:
        #Apollo database
        apollo-db:
          image: mysql:5.7
          container_name: apollo_db_5_7
          restart: always
          environment:
            TZ: Asia/Shanghai
            MYSQL_ROOT_PASSWORD: 'devops666'
          ports:
            - "13306:3306"
          volumes:
            - ./initsql:/docker-entrypoint-initdb.d- ./data:/var/lib/mysql
          networks:
            -devopsnetwork
    
        #Apollo Service Discovery Registration Center
        apollo-configservice:
          container_name: apollo_configservice_2_1
          image: apolloconfig/apollo-configservice:2.1.0
          restart: always
          depends_on:
            -apollo-db
          environment:
            SPRING_DATASOURCE_URL: 'jdbc:mysql://apollo-db:3306/ApolloConfigDB?characterEncoding=utf8'
            SPRING_DATASOURCE_USERNAME: 'root'
            SPRING_DATASOURCE_PASSWORD: 'devops666'
            JAVA_OPTS: "-Deureka.instance.homePageUrl=http://192.168.123.214:8080"
            # EUREKA_INSTANCE_HOME_PAGE_URL: http://192.168.123.214:8080
            # EUREKA_INSTANCE_PREFER_IP_ADDRESS: false
          volumes:
            - ./logs:/opt/logs
          ports:
            - "8080:8080"
          networks:
            -devopsnetwork
    
        #Core interface service
        apollo-adminservice:
          container_name: apollo_adminservice_2_1
          image: apolloconfig/apollo-adminservice:2.1.0
          restart: always
          environment:
            SPRING_DATASOURCE_URL: 'jdbc:mysql://apollo-db:3306/ApolloConfigDB?characterEncoding=utf8'
            SPRING_DATASOURCE_USERNAME: 'root'
            SPRING_DATASOURCE_PASSWORD: 'devops666'
            JAVA_OPTS: "-Deureka.instance.homePageUrl=http://192.168.123.214:8090 -Deureka.service.url=http://192.168.123.214:8080/eureka/ "
          depends_on:
            -apollo-db
          ports:
            - "8090:8090"
          volumes:
            - ./logs/:/opt/logs
          networks:
            -devopsnetwork
           
      
        apollo-portal:
          image: apolloconfig/apollo-portal:2.1.0
          container_name: apollo_portal_2_1
          restart: always
          environment:
            SPRING_DATASOURCE_URL: 'jdbc:mysql://apollo-db:3306/ApolloPortalDB?characterEncoding=utf8'
            SPRING_DATASOURCE_USERNAME: 'root'
            SPRING_DATASOURCE_PASSWORD: 'devops666'
            APOLLO_PORTAL_ENVS: 'dev'
            DEV_META: 'http://192.168.123.214:8080'
            #Default account apollo admin
          depends_on:
            -apollo-db
          ports:
            - "8070:8070"
          volumes:
            - ./logs/:/opt/logs
          networks:
            -devopsnetwork
    
      networks:
        devopsnetwork:
          external: true
      ```
    
     

Deployment successful

Deployment machine IP: 192.168.123.214

Use K8S installation

Just follow the official documentation step by step. The helm file can be obtained from apolloconfig/apollo-helm-chart. Here I only share the steps and some precautions

  1. Initialize the database

    1. You can use existing or deployed mysql services and create a special account and password for apollo
    2. Execute the v2.1 default initialization script of the corresponding version of Apollo to create ApolloConfigDB and ApolloPortalDB
    3. In the production environment, remember to modify the environment and organization of the ServerConfig table apollo.portal.envs:pro organizations:[{"orgId":"xxx","orgName":"xxx company" }]
  2. Use helm to add apollo repo

  3. Install apollo-service

  4. Install apollo-portal

  5. k8s use

    • Apollo related configurations can be stored in the ConfigMap of k8s for easy use in k8s services

use

.NET SDK

Official: Com.Ctrip.Framework.Apollo.Configuration

  1. Add package: Com.Ctrip.Framework.Apollo.Configuration

  2. Add apollo configuration in appsetting.json

    1. MetaServer: Apollo service address, which can also be viewed in the system information
    2. AppId: Application Id
    3. Namespaces: The default namespace is application
  3. Get parameter registration: it can be configuration or environment variables

    builder.Configuration.AddApollo(builder.Configuration.GetSection("apollo"));

  4. Inject IConfiguration and use it

Connection configuration

 "apollo": {
     "MetaServer": "http://192.168.123.214:8080",
     "AppId": "devops.test",
     "Namespaces": [ "application" ]
   }
 

Demo example

dotnet v7.0

var builder = WebApplication.CreateBuilder(args);
 builder.Configuration.AddApollo(builder.Configuration.GetSection("apollo"));
 app.MapGet("/config", context =>
 {
     context.Response.Headers["Content-Type"] = "text/html; charset=utf-8";
     //Configure service
     var configService = context.RequestServices.GetRequiredService();
     string? key = context.Request.Query["key"];
     if (string.IsNullOrWhiteSpace(key))
     {
         return context.Response.WriteAsync("Get configuration:/config?key=test");
     }
     var value = configService[key];
     return context.Response.WriteAsync(value ?? "undefined");
 });
 

Complete Demo example: Github address

The pit that has been stepped on

  • Database configuration connection, use service name instead of container name
  • I didn’t understand what the -Deureka.instance.homePageUrl and -Deureka.service.url parameters did at first. I only knew that the configuration health check failed. After reading the documentation, I realized that Deureka.instance.homePageUrl was registered. Service address, -Deureka.service.url is the interface address of the registration center
  • Github address
  • Official Documents
  • Module Introduction
  • Deploying Quick Start with Docker
  • Distributed deployment
  • Deployment architecture
  • Performance Test
  • .NET SDK: apollo.net
  • Default initialization script
  • Skip service discovery
  • Configuration instructions

后语

If you have enough time, it is best to go through the document and understand how it is designed. If you encounter problems, you will be really confused.

Improve a little every day, even just a little!

Author: Yi Mo

Github:yimogit

Pure static tool site: metools

Note: Welcome to make bricks, please point out any shortcomings;

Confusion is probably because you think too much and do too little.

application.CreateBuilder(args);
builder.Configuration.AddApollo(builder.Configuration.GetSection(“apollo”));
app.MapGet(“/config”, context =>
{
context.Response.Headers[“Content-Type”] = “text/html; charset=utf-8”;
//Configure service
var configService = context.RequestServices.GetRequiredService();
string? key = context.Request.Query[“key”];
if (string.IsNullOrWhiteSpace(key))
{
return context.Response.WriteAsync(“Get configuration:/config?key=test”);
}
var value = configService[key];
return context.Response.WriteAsync(value ?? “undefined”);
});

Complete Demo example: Github address

The pit that has been stepped on

  • Database configuration connection, use service name instead of container name
  • I didn’t understand what the -Deureka.instance.homePageUrl and -Deureka.service.url parameters did at first. I only knew that the configuration health check failed. After reading the documentation, I realized that Deureka.instance.homePageUrl was registered. Service address, -Deureka.service.url is the interface address of the registration center
  • Github address
  • Official Documents
  • Module Introduction
  • Deploying Quick Start with Docker
  • Distributed deployment
  • Deployment architecture
  • Performance Test
  • .NET SDK: apollo.net
  • Default initialization script
  • Skip service discovery
  • Configuration instructions

后语

If you have enough time, it is best to go through the document and understand how it is designed. If you encounter problems, you will be really confused.

Improve a little every day, even just a little!

Author: Yi Mo

Github:yimogit

Pure static tool site: metools

Note: Welcome to make bricks, please point out any shortcomings;

Confusion is probably because you think too much and do too little.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/deployment-and-usage-experience-of-apollo-configuration-center/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索