As we all know, Apollo is Ctrip's open source configuration center, so the Chinese documents are relatively complete, so I won't go into details here. The main purpose of this article is to record how to deploy Apollo Configuration Center in a distributed manner under CentOS8. Apollo's feature highlights:
The official distributed deployment document:
If you just want to quickly build an Apollo environment during local development, refer to the official Quick Start:
The following figure is an overview of the Apollo architecture modules:
The above figure briefly describes the overall design of Apollo, we can see from the bottom up:
Therefore, we usually deploy two nodes responsible for different roles: ConfigServer (including config service, admin service, meta server) node and PortalServer node. First use virtualization software to create two CentOS8 virtual machines, I use VMware here:
Because Apollo is written based on the Spring Boot framework of Java, and relies on MySQL for data storage. So on these two virtual machines, I have installed MySQL and JDK in advance.
The official requirements for the runtime environment are:
And my runtime environment here is:
as follows:
[ root@config-server ~]# java -version
java version "11.0.5"2019-10-15 LTS
Java(TM) SE Runtime Environment 18.9(build 11.0.5+10-LTS)
Java HotSpot(TM)64-Bit Server VM 18.9(build 11.0.5+10-LTS, mixed mode)[root@config-server ~]# mysql --version
mysql Ver 8.0.18for Linux on x86_64(Source distribution)[root@config-server ~]# cat /etc/redhat-release
CentOS Linux release 8.0.1905(Core)[root@config-server ~]#
After completing the preparations, the first step is to create the corresponding database. Because Apollo relies on the MySQL database, you need to create and complete the initialization of the database tables in advance. Distributed deployment of Apollo services requires the creation of the two databases ApolloPortalDB
and ApolloConfigDB
on different MySQL instances.
Of course, if you don't need to manage it separately, you can also create it in a MySQL instance. Officially, SQL files are prepared for database, table creation, and sample data. We only need to import the database. The address of the SQL file is as follows:
It should be noted that ApolloPortalDB
only needs to be deployed in the production environment, and ApolloConfigDB
needs to be deployed in each environment, such as fat, uat and pro environments to deploy three sets of ApolloConfigDB
. I have deployed a MySQL instance in Config-Server and Portal-Server respectively.
After successfully importing the two SQL files into the two databases, the created databases and tables are as follows:
There are 3 installation packages required:
You can download the official installation package directly, or you can build it from the source code. Since there is no need to modify the source code, I download the installation package directly here. See Github Releases for the download address.
Copy the download link and use the wget
command to download on the server or upload it to the server after downloading locally. The installation package of config-server is as follows:
[ root@config-server ~]# cd /usr/local/src
[ root@config-server /usr/local/src]# ls
apollo-adminservice-1.7.1-github.zip apollo-configservice-1.7.1-github.zip
[ root@config-server /usr/local/src]#
The installation package of portal-server is as follows:
[ root@portal-server ~]# cd /usr/local/src
[ root@portal-server /usr/local/src]# ls
apollo-portal-1.7.1-github.zip
[ root@portal-server /usr/local/src]#
Unzip the compressed package to a suitable directory:
[ root@config-server /usr/local/src]# mkdir /usr/local/apollo-configservice
[ root@config-server /usr/local/src]# unzip apollo-configservice-1.7.1-github.zip -d /usr/local/apollo-configservice
[ root@config-server /usr/local/src]# mkdir /usr/local/apollo-adminservice
[ root@config-server /usr/local/src]# unzip apollo-adminservice-1.7.1-github.zip -d /usr/local/apollo-adminservice/[root@config-server /usr/local/src]# ls /usr/local/apollo-configservice
apollo-configservice-1.7.1.jar apollo-configservice-1.7.1-sources.jar apollo-configservice.conf config scripts
[ root@config-server /usr/local/src]# ls /usr/local/apollo-adminservice/
apollo-adminservice-1.7.1.jar apollo-adminservice-1.7.1-sources.jar apollo-adminservice.conf config scripts
[ root@config-server /usr/local/src]#
Configure the database connection information of apollo-configservice:
[ root@config-server /usr/local/src]# cd /usr/local/apollo-configservice/[root@config-server /usr/local/apollo-configservice]# vim config/application-github.properties
# DataSource
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false
spring.datasource.username = root
spring.datasource.password = 123456a.
ApolloConfigDB
database connection string information, pay attention to the user name and password without spaces!Configure the database connection information of apollo-adminservice:
[ root@config-server /usr/local/apollo-configservice]# cd ../apollo-adminservice/[root@config-server /usr/local/apollo-adminservice]# vim config/application-github.properties
# DataSource
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false
spring.datasource.username = root
spring.datasource.password = 123456a.
ApolloConfigDB
database connection string information, pay attention to the user name and password without spaces!If you need to adjust the configuration of apollo-configservice and apollo-adminservice's JVM startup parameters, service monitoring port, and log file storage directory, you can modify it in the scripts/startup.sh under the installation directory:
JAVA_OPTS
part of scripts/startup.sh
LOG_DIR
in scripts/startup.sh
and apollo-configservice.conf
SERVER_PORT
in scripts/startup.sh
. In addition, since apollo-configservice also assumes the responsibility of the meta server, if you want to modify the port, you must also modify the eureka.service.url
configuration item in the ApolloConfigDB.ServerConfig
table and the ones used in apollo-portal and apollo-client meta server informationStart apollo-configservice:
[ root@config-server /usr/local/apollo-configservice]# scripts/startup.sh
2020 Tuesday, November 10,:34:22 CST ==== Starting ====
Started [20958]
Waiting for server startup...Tuesday, November 10, 2020 16:34:38 CST Server started in15 seconds![root@config-server /usr/local/apollo-configservice]#
Check whether the startup is successful:
[ root@config-server /usr/local/apollo-configservice]# jps
1655 apollo-configservice.jar
1807 Jps
[ root@config-server /usr/local/apollo-configservice]# netstat -lntp |grep 8080
tcp6 00:::8080:::* LISTEN 1655/java
[ root@config-server /usr/local/apollo-configservice]#
Start apollo-adminservice:
[ root@config-server /usr/local/apollo-adminservice]# scripts/startup.sh
2020 Tuesday, November 10,:39:46 CST ==== Starting ====
Started [1886]
Waiting for server startup...Tuesday, November 10, 2020 16:40:01 CST Server started in15 seconds![root@config-server /usr/local/apollo-adminservice]#
Check whether the startup is successful:
[ root@config-server /usr/local/apollo-adminservice]# jps
1655 apollo-configservice.jar
2012 Jps
1886 apollo-adminservice.jar
[ root@config-server /usr/local/apollo-adminservice]# netstat -lntp |grep 8090
tcp6 00:::8090:::* LISTEN 1886/java
[ root@config-server /usr/local/apollo-adminservice]#
If you want to stop the service, just execute the scripts/shutdown.sh in the corresponding service directory.
Similar to the previous section, unzip the compressed package to a suitable directory:
[ root@portal-server /usr/local/src]# mkdir /usr/local/apollo-portal
[ root@portal-server /usr/local/src]# unzip apollo-portal-1.7.1-github.zip -d /usr/local/apollo-portal/[root@portal-server /usr/local/src]# ls /usr/local/apollo-portal/
apollo-portal-1.7.1.jar apollo-portal-1.7.1-sources.jar apollo-portal.conf config scripts
[ root@portal-server /usr/local/src]#
Configure the database connection information for apollo-portal:
[ root@portal-server /usr/local/src]# cd /usr/local/apollo-portal/[root@portal-server /usr/local/apollo-portal]# vim config/application-github.properties
# DataSource
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false
spring.datasource.username = root
spring.datasource.password = 123456a.
Then it is to configure the meta service information of apollo-portal. Apollo Portal needs to access different meta service (apollo-configservice) addresses in different environments, so we need to provide this information in the configuration.
By default, meta service and config service are deployed in the same JVM process, so the address of meta service is the address of config service. The format of the configuration item is env.meta=http://{config-service-url:port}, as shown below:
[ root@portal-server /usr/local/apollo-portal]# vim config/apollo-env.properties
dev.meta=http://192.168.243.159:8080
dev.meta
In addition to configuring meta service through apollo-env.properties
, apollo also supports specifying meta service at runtime (priority is higher than apollo-env.properties
):
${env}_meta
${env}_meta
java -Ddev_meta=http://config-service-url -jar xxx.jar
System.setProperty("dev_meta", "http://config-service-url");
${ENV}_META
DEV_META=http://config-service-url
Start apollo-portal:
[ root@portal-server /usr/local/apollo-portal]# scripts/startup.sh
2020 Tuesday, November 10,:56:36 CST ==== Starting ====
Started [21010]
Waiting for server startup........Tuesday, November 10, 2020 16:57:17 CST Server started in40 seconds![root@portal-server /usr/local/apollo-portal]#
Check whether the startup is successful:
[ root@portal-server /usr/local/apollo-portal]# jps
21010 apollo-portal.jar
21162 Jps
[ root@portal-server /usr/local/apollo-portal]# netstat -lntp |grep 8070
tcp6 00:::8070:::* LISTEN 21010/java
[ root@portal-server /usr/local/apollo-portal]#
After the startup is successful, access port 8070 of portal-server through a browser:
After successful login, enter the home page:
Then you can enter the sample project to do some tests to see if it works normally:
At this point we have completed the distributed deployment of Apollo. Here is just one set of environments. If there are multiple sets of environments, you only need to repeat the steps in the Apollo Config Server section to deploy multiple Config Server nodes. Then configure the access addresses of these Config Server nodes in the apollo-env.properties
configuration file of Portal Server.
Recommended Posts