Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy distributed configuration Center Apollo with one click by docker compose

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Docker compose how to deploy distributed configuration center Apollo with one click, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

Brief introduction

When talking about distribution, we must think of distributed configuration center, distributed log, distributed link tracing and so on.

In distributed deployment, businesses often have a lot of configurations, such as: applications need to read some configuration information when they start and run, and configuration basically accompanies the whole life cycle of the application, such as database connection parameters, startup parameters, etc., all need to be maintained and configured, but it is impossible to log on to configure one by one server.

Today I'm going to share with you about the distributed configuration Center Apollo:

Apollo (Apollo) is a distributed configuration center developed by Ctrip Framework Department, which can centrally manage the configuration of applications in different environments and clusters. After configuration modification, it can be pushed to the application in real time, and has standardized permissions, process governance and other features, so it is suitable for micro-service configuration management scenarios.

Set up

There are two ways to build official documents, one is to download the source code to build, the other is to use Docker or K8S to build, today we use Docker to build, after all, Docker is more friendly for developers.

If there is an existing Mysql service, it is recommended that the existing Mysql service or cloud service RDS be used as the database. After all, the data is priceless.

Version: "3" services: apollo-configservice: # Config Service provides configured read, push and other functions The service object is Apollo client image: apolloconfig/apollo-configservice:1.8.1 restart: always # container_name: apollo-configservice volumes: -. / logs/apollo-configservice:/opt/logs ports:-"8080 EUREKA_INSTANCE_IP_ADDRESS=xxx.xxx.xxx.xxx 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, release 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 SERVER_PORT=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: # Administrative 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!

From the above docker-compose.yaml, we can see that there are three services, namely:

Config Service provides configured read, push and other functions, and the service object is the Apollo client

Admin Service provides functions such as configuration modification and release, and the service object is Apollo Portal (management interface).

Portal (Management Interface)

If you want to know how they work, it is recommended to check the official documentation.

The log is 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 the 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 lower-case-table-names=1 environment 3306"

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

Initialize the database

Initialize apolloconfigdb.sql and apolloportaldb.sql

After the database is initialized, remember to modify the eureka.service.url of the serverconfig table in the apolloconfigdb library, otherwise apollo-adminservice cannot register with eureka

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

Docker-compose up-d # starts three services in the file and runs in the background

Check the startup status

Docker-compose ps

Access the http://10.0.0.53:8070/ # Apollo management side

Default user name: apollo

Default password: admin

Create a test project

test

Create a .NetCore project to add Apollo.net client

Add Apollo

Configure Apollo

Configure as above

Add test content

Get Apollo from the code

Initiator request / weatherforecast/apollotest

Found that the configuration set in apollo was not obtained.

Check that the value of the Apollo configuration has not been released

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

Find that the data is already new. Let's modify Apollo's Value again.

Refresh

As a result, this Apollo has been built and can be used normally.

Code

The code in the example is in the

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

Welcome, Start.

Note that if the program cannot pull the configuration after startup, you can open the Apollo log. You can see the detailed configuration in the console and put it on the first line of the Program.cs Main function!

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

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report