Apollo sub-environment deployment

The following figure is an overview of the Apollo architecture modules:

Insert picture description here

The above figure briefly describes the overall design of Apollo, we can see from the bottom up:

  • Config Service provides functions such as configuration reading and pushing, and the service object is the Apollo client
  • Admin Service provides functions such as configuration modification and publishing, and the service object is Apollo Portal (management interface)
  • Config Service and Admin Service are both multi-instance, stateless deployment, so you need to register yourself in Eureka and keep your heartbeat
  • On top of Eureka, we have built a layer of Meta Server to encapsulate Eureka's service discovery interface
  • Client accesses Meta Server through the domain name to obtain the Config Service service list (IP+Port), and then directly accesses the service through IP+Port. At the same time, load balance and error retry will be performed on the Client side.
  • Portal accesses Meta Server through the domain name to obtain the Admin Service service list (IP+Port), and then directly accesses the service through IP+Port. At the same time, load balance and error retry will be performed on the Portal side.

deploy

Environment description:
centos7.9
openjdk version "1.8.0_262"
mysql5.7

dev: 192.168.146.141
pro: 192.168.146.139

1. Create a database (dev/pro)

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

mkdir /etc/docker/
cat >/etc/docker/daemon.json <<EOF
{
  "graph": "/data/docker", 
  "storage-driver": "overlay2",
  "insecure-registries": ["registry.access.redhat.com","quay.io"],
  "registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"],
  "bip": "172.0.137.1/24",
  "exec-opts": ["native.cgroupdriver=systemd"],
  "live-restore": true
}
EOF

mkdir -p /data/docker
systemctl start docker
systemctl status docker
systemctl enable docker
docker --version

docker run -itd --name mysql --restart=always -e MYSQL_ROOT_PASSWORD=123456  -p 3306:3306 -v /data/mysql/data:/var/lib/mysql mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

# docker exec -it mysql /bin/bash
# mysql -u root -p123456
mysql> grant all on *.* to 'apollo'@'%' identified by '123456';
mysql> flush privileges;
mysql> exit;
# exit

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 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 separately for database, table creation and sample data. We only need to import the database. The address of the SQL file is as follows:

  • https://github.com/ctripcorp/apollo/tree/master/scripts/sql

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 3 sets of ApolloConfigDB. Here I have deployed a MySQL instance in dev and pro respectively.

Import sql file

dev

mysql -h 192.168.146.141 -uapollo -p123456 < apolloconfigdb.sql

pro

mysql -h 192.168.146.139 -uapollo -p123456 < apolloconfigdb.sql
mysql -h 192.168.146.139 -uapollo -p123456 < apolloportaldb.sql
Note: After importing the data here, you need to modify the data in ServerConfig
Insert picture description here
Obtain the installation package

There are 3 installation packages required:

  • apollo-configservice
  • apollo-adminservice
  • apollo-portal
  • https://github.com/ctripcorp/apollo/releases
[[email protected] src]# ls
apollo-adminservice-1.8.0-github.zip  apolloconfigdb.sql  apollo-configservice-1.8.0-github.zip

Deploy Apollo Config Server (dev/pro)
[[email protected] /usr/local/src]# mkdir /usr/local/apollo-configservice
[[email protected] /usr/local/src]# unzip apollo-configservice-1.8.0-github.zip -d /usr/local/apollo-configservice
[[email protected] /usr/local/src]# mkdir /usr/local/apollo-adminservice
[[email protected] /usr/local/src]# unzip apollo-adminservice-1.8.0-github.zip -d /usr/local/apollo-adminservice/

Configure the database connection information of apollo-configservice:

[[email protected] /usr/local/src]# cd /usr/local/apollo-configservice/
[[email protected] /usr/local/apollo-configservice]# vim config/application-github.properties 
# DataSource
spring.datasource.url = jdbc:mysql://dev:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false
spring.datasource.username = apollo
spring.datasource.password = 123456

Configure database connection information for apollo-adminservice:

[[email protected] /usr/local/apollo-configservice]# cd ../apollo-adminservice/
[[email protected] /usr/local/apollo-adminservice]# vim config/application-github.properties 
# DataSource
spring.datasource.url = jdbc:mysql://dev:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false
spring.datasource.username = apollo
spring.datasource.password = 123456
pro配置的时候注意修改dev为pro

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 them in the scripts/startup.sh script in the installation directory:

If you need to modify the JVM parameters, you can modify the JAVA_OPTS part of scripts/startup.sh.
To adjust the log output path of the service, you can modify the LOG_DIR in scripts/startup.sh and apollo-configservice.conf.
To adjust the listening port of the service, you can Modify 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 meta server information used in apollo-portal and apollo-client.

Start apollo-configservice:

[[email protected] /usr/local/apollo-configservice]# scripts/startup.sh 
netstat -lntp |grep 8080

Start apollo-adminservice:

[[email protected] /usr/local/apollo-adminservice]# scripts/startup.sh 
netstat -lntp |grep 8090
Deploy Apollo Portal Server (pro)
[[email protected] /usr/local/src]# mkdir /usr/local/apollo-portal
[[email protected] /usr/local/src]# unzip apollo-portal-1.8.0-github.zip -d /usr/local/apollo-portal/

Configure the database connection information for apollo-portal:

[[email protected] /usr/local/src]# cd /usr/local/apollo-portal/
[[email protected] /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 = apollo
spring.datasource.password = 123456

Then 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:

[[email protected] /usr/local/apollo-portal]# vim config/apollo-env.properties
dev.meta=http://dev:8080
pro.meta=http://prod:8080

Start apollo-portal:

[[email protected] /usr/local/apollo-portal]# scripts/startup.sh 
netstat -lntp |grep 8070

After the startup is successful, visit the 8070 port of pro through the browser:

Insert picture description here


apollo/admin

Click to create a project

Insert picture description here


Insert picture description here


Note: the appid must be unique, otherwise the environment will not be displayed

Insert picture description here


Click Add configuration

Insert picture description here


Insert picture description here


Insert picture description here


and then click Publish

Then it is to use the client to connect to the configuration center, which is not finished. . .
https://github.com/multilinguals/apollo-php-client