Apollo-docker
One click package / deployment scheme of Ctrip Apollo.
Almost no need to modify any Apollo source code or configuration to build a rapid development / test environment.
Project address: https://gitee.com/ellipse/apollo-docker
1. Download source code
Apollo
git clone https://gitee.com/nobodyiam/apollo.git
Compile script
git clone https://gitee.com/ellipse/apollo-docker.git
Project directory structure:
apollo-docker/ -- apollo/ <--Precompiled version -- admin/ -- config/ -- portal/ -- apollo.env -- docker-compose.yml -- build/ <--Compile script -- gulpfile.js -- ...
2. Environmental preparation
Maven
Apollo project builds with Maven
Node.js
The script is written in Gulp and requires Node.js
Docker
The test server needs to install Docker and Docker compose
3. Compatibility check
Before using script packaging, check the compatibility of maven version. Run the built-in compilation script of the project, and pass if no error is reported.
// Run under project root cd scripts build.bat
My maven version is 3.6.3, and errors will be reported during compilation:
[INFO] Apollo ConfigService ............................... FAILURE [ 5.037 s] [INFO] Apollo AdminService ................................ SKIPPED [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 49.311 s [INFO] Finished at: 2020-05-23T11:08:01+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single (default) on project apollo-configservice: Execution default of goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-assembly-plugin:2.6:single: java.lang.ExceptionInInitializerError: null ..... ..... [ERROR] Number of foreign imports: 1 [ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]] [ERROR] [ERROR] ----------------------------------------------------- [ERROR] : Index 1 out of bounds for length 1
The exception information is not intuitive. After some exploration, it is caused by the incompatibility between maven assembly plugin and maven version.
Modify the pom.xml File, change the Maven assembly plugin version to 3.3.0.
<!-- v1.6.1 494-498 That's ok --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.3.0</version> </plugin>
Run again after modification build.bat Script, compiled.
4. Compile
Copy the build folder of this project to the root directory of apollo. The directory structure is:
/ -- apollo-portal/ -- build/ -- gulpfile.js
Open the console in the build directory and do the following
# ~/apollo/build/ # Installation required Node.js npm i gulp
Wait for the compilation to complete.
/ -- build/ -- apollo/ -- admin/ -- config/ -- portal/ -- apollo.env <- General environment variables -- docker-compose.yml <- Run script -- gulpfile.js
Modify as needed apollo.env And docker-compose.yml .
# apollo.env DS_IP=192.168.0.109 # IP address of the host where the database is located DS_PORT=3306 # Database port HOST_IP=192.168.0.103 # Docker host IP, only referenced in environment variable DS_URL=jdbc:mysql://${DS_IP}:${DS_PORT}/${DB_NAME}?characterEncoding=utf8 DS_USERNAME=root # Database user name DS_PASSWORD=123456 # Database password eureka.instance.ip-address=${HOST_IP} # The IP specified when registering with Eureka. The host IP is used here
# docker-compose.yml version: '3' services: apollo-config-01: container_name: apollo-configservice-01 build: ./config ports: - 8080:8080 volumes: - /data/apollo/config01:/opt/logs/100003171 env_file: - apollo.env environment: - DB_NAME=ApolloConfigDB_Docker # Database name ... ... apollo-portal-01: container_name: apollo-portalservice-01 build: ./portal ports: - 8070:8070 volumes: - /data/apollo/portal01:/opt/logs/100003173 env_file: - apollo.env environment: - DB_NAME=ApolloPortalDB_Docker - LOCAL_META=http://192.168.0.103:8080 ා address of Eureka - DEV_META=http://192.168.0.103:8080 # - FAT_META=http://192.168.0.103:8080 # - UAT_META=http://192.168.0.103:8080 # - LPT_META=http://192.168.0.103:8080 # - PRO_META=http://192.168.0.103:8080 #
In addition, other Spring configurations can be added to the environment to override Apollo's default parameters, such as
environment: - server.port=18080
5. Stand alone deployment
Test environment: CentOS8 (Vmware) and install Docker and Docker compose
Upload the newly generated apollo folder to the server
/ -- build/ --Apollo / < upload this folder -- gulpfile.js
Command line into the apollo folder, run
docker-compose up -d
Check whether the startup is successful
docker-compose ps
Name Command State Ports ----------------------------------------------------------------------------------------- apollo-adminservice-01 /apollo-adminservice/scrip ... Up 0.0.0.0:8090->8090/tcp apollo-configservice-01 /apollo-configservice/scri ... Up 0.0.0.0:8080->8080/tcp apollo-portalservice-01 /apollo-portal/scripts/sta ... Up 0.0.0.0:8070->8070/tcp
Note: docker compose must include docker in- compose.yml The file can only be executed in the directory.
If the startup fails, check the log in the server / data/apollo /. The log location in docker has been redirected to the host in the previous configuration.
If the network fails to start, refer to this article: https://my.oschina.net/u/580483/blog/4264763
Due to the slow process of service registration and discovery, you need to wait about 30 seconds after startup (human flesh timing)
Visit Eureka management page in browser http://192.168.0.103:8080 /, you can see that apollo-adminsert and APOLLO-CONFIGSERVICE have been successfully registered, and the ip address is correct.
Visit the Apollo portal administration page http://192.168.0.103:8070 /, administrator Tools > system information, you can see that apollo-adminsert and APOLLO-CONFIGSERVICE have been successfully obtained in the environment information.
Note: if the server has a firewall, you need to open the corresponding port and restart the firewall
firewall-cmd --zone=public --add-port=8080/tcp --permanen
6. Distributed deployment
6.1 test environment
Tester 1: CentOS 8 (Vmware) 192.168.0.103 ---- ConfigService ---- AdminService ---- Portal Tester 2: CentOS 8 (Vmware) 192.168.0.104 ---- ConfigService ---- AdminService
6.2 modify configuration
Select the precompiled version for deployment.
data base
UPDATE serverconfig SET `Value` = "http://192.168.0.103:8080/eureka/,http://192.168.0.104:8080/eureka/" WHERE `Key` = "eureka.service.url"
Tester 1
Copy the Apollo folder under the root directory of this project, and name it apollo_103. modify apollo.env `, others are modified according to the actual environment.
HOST_IP=192.168.0.103
Modify docker-compose.yml , others are modified according to the actual environment.
apollo-portal-01: ... environment: - DB_NAME=ApolloPortalDB_Docker - LOCAL_META=http://192.168.0.103:8080,http://192.168.0.104:8080 - DEV_META=http://192.168.0.103:8080,http://192.168.0.104:8080
Tester 2
Copy apollo_103 and renamed apollo_104. modify apollo.env , others are modified according to the actual environment.
HOST_IP=192.168.0.104
Modify docker-compose.yml , comment out (or delete) the apollo-portal-01 section. Others shall be modified according to the actual environment.
# apollo-portal-01: # container_name: apollo-portalservice-01 # build: ./portal # ports: # - 8070:8070 # volumes: # - /data/apollo/portal01:/opt/logs/100003173 # env_file: # - apollo.env # environment: # - DB_NAME=ApolloPortalDB_Docker # - LOCAL_META=http://192.168.0.103:8080,http://192.168.0.104:8080 # - DEV_META=http://192.168.0.103:8080,http://192.168.0.104:8080 # - FAT_META=http://192.168.0.103:8080,http://192.168.0.104:8080 # - UAT_META=http://192.168.0.103:8080,http://192.168.0.104:8080 # - LPT_META=http://192.168.0.103:8080,http://192.168.0.104:8080 # - PRO_META=http://192.168.0.103:8080,http://192.168.0.104:8080
6.3 start Apollo
Log in to two servers respectively, and log in to Apollo_ Execute in 10x Directory:
docker-compose up -d