Apollo multi environment distributed deployment
For Apollo distributed deployment, three servers are used this time. One portal service, one fat environment (adminservice and configservice), and one uat environment (adminservice and configservice). After the environment is built, integrate SpringBoot to realize multi environment switching.
1, Introduction to each module of Apollo (quoted from the official website of Apollo)
1.Config Service
- Provide configuration acquisition interface
- Provide configuration update push interface (based on Http long polling)
- The interface service object is Apollo client
2.Admin Service
- Provide configuration management interface
- Provide interfaces for configuration modification and publishing
- The interface service object is Portal
3.Meta Server
- Portal accesses the Meta Server through the domain name to obtain the list of Admin Service services (IP+Port)
- The Client accesses the Meta Server through the domain name to obtain the Config Service service list (IP+Port)
- Meta Server obtains the service information of Config Service and Admin Service from Eureka, which is equivalent to an Eureka Client
- Adding a Meta Server role is mainly to encapsulate the details of service discovery. For Portal and Client, they always obtain the service information of Admin Service and Config Service through an Http interface, without caring about the actual service registration and discovery components behind them
- Meta Server is only a logical role. It is in the same JVM process as Config Service during deployment, so the IP and port are consistent with Config Service
4.Eureka
- Netflix provides service registration and discovery based on Eureka and spring cloud
- Config Service and Admin Service will register services with Eureka and keep heartbeat
- For simplicity, Eureka and Config Service are currently in the same JVM process during deployment (through Spring Cloud Netflix)
5.Portal
- Provides a Web interface for users to manage configuration
- Obtain the Admin Service list (IP+Port) through the Meta Server, and access the service through IP+Port
- Perform load balance and error retry on the Portal side
6.Client
- The client program provided by Apollo provides configuration acquisition, real-time update and other functions for applications
- Get the Config Service service list (IP+Port) through the Meta Server, and access the service through IP+Port
- Perform load balance and error retry on the Client side
2, Description of this environmental construction
1. Server description
- Portal 192.168.16.129
- FAT environment 192.168.16.130
- UAT environment 192.168.16.131
2. Service deployment description
- Only one Portal service needs to be deployed (only one database is required), and one Portal can manage multiple environments.
- Each environment corresponds to a set of AdminService and ConfigService, and each environment needs to correspond to a database.
3. Deployment structure diagram
3, Environment construction
1. Service package download
- apollo-portal
- apollo-adminservice
- apollo-configservice
After decompression, the directory is as follows:
2. Configure Portal services
- Modify database address:
Modify Apollo portal / config / application GitHub Properties file
spring.datasource.url = jdbc:mysql://192.168.1.9:3306/apolloportaldb?characterEncoding=utf8&serverTimezone=Asia/Shanghai spring.datasource.username = root spring.datasource.password = 1234
- Modify the address of the meta managed by the portal
Modify Apollo portal / config / Apollo env Properties file
There are only fat and uat environments here, so you only need to configure the meta addresses corresponding to these two environments
fat.meta=http://192.168.16.130:8080 uat.meta=http://192.168.16.131:8080
3. Configure Admin service
- Modify the database address of fat environment:
Modify Apollo adminservice / config / application GitHub Properties file
The data address here is the database used by the configservice service in the fat environment
spring.datasource.url = jdbc:mysql://192.168.1.9:3306/apolloconfigdb-fat?characterEncoding=utf8&serverTimezone=Asia/Shanghai spring.datasource.username = root spring.datasource.password = 1234
- Modify the database address of uat environment:
Modify Apollo adminservice / config / application GitHub Properties file
The data address here is the database used by the configservice service in the uat environment
spring.datasource.url = jdbc:mysql://192.168.1.9:3306/apolloconfigdb-uat?characterEncoding=utf8&serverTimezone=Asia/Shanghai spring.datasource.username = root spring.datasource.password = 1234
4. Configure Config service
- Modify the database address of fat environment:
Modify Apollo configservice / config / application GitHub Properties file
The data address here is the database used by the configservice service in the fat environment
spring.datasource.url = jdbc:mysql://192.168.1.9:3306/apolloconfigdb-fat?characterEncoding=utf8&serverTimezone=Asia/Shanghai spring.datasource.username = root spring.datasource.password = 1234
- Modify the database address of uat environment:
Modify Apollo configservice / config / application GitHub Properties file
The data address here is the database used by the configservice service in the fat environment
spring.datasource.url = jdbc:mysql://192.168.1.9:3306/apolloconfigdb-uat?characterEncoding=utf8&serverTimezone=Asia/Shanghai spring.datasource.username = root spring.datasource.password = 1234
5. Service startup
Remember the port of the open server: the default port of portal is 8070; admin default port 8090; Config default port 8080
First, start the admin service and config service of the two environments
sh ./apollo-adminservice/scripts/startup.sh sh ./apollo-configservice/scripts/startup.sh
Restart the portal service
sh ./apollo-portal/scripts/startup.sh
Visit 192.168.16.129:8070 portal service
Default username and password apollo admin
4, Integrate SpringBoot
1. Required dependencies
<dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-client</artifactId> <version>1.9.0</version> </dependency>
2. Write the SpringBoot configuration file
Corresponding to fat and uat environment respectively
application.yml
app: id: demo #Specifies the unique identity of the Apollo application spring: profiles: active: uat #Specifies which environment profile to activate server: port: 9000
application-fat.yml
apollo: meta: http://192.168.16.130:8080 # specify the address and port where the config service is located in the fat environment bootstrap: namespaces: application,datasource #Specify which namespaces to load (the namespace needs to be consistent with the namespace of Apollo; by default, only application needs to be loaded, and the following two configuration items need to be enabled) enabled: true eagerLoad: enabled: true
application-uat.yml
apollo: meta: http://192.168.16.131:8080 bootstrap: namespaces: application,datasource enabled: true eagerLoad: enabled: true
3. Write test interface
The value inside the value annotation should be consistent with the key configured in the Apollo service
@RestController public class DemoController { @Value("${redis.url:127.0.0.1}") private String redisUrl; @Value("${datasource.url:127.0.0.1}") private String dataSource; @GetMapping("/apollo/demo") public String demo(){ return redisUrl; } @GetMapping("/apollo/test") public String test(){ return dataSource; } }