1, foreword
I'm not going to talk about apollo in detail, on the official website. https://github.com/ctripcorp/... What I have said is very clear. I will not make an axe in this class. Little friends who do not know can go to the official website to learn about it.
This article is just a record of the way I deployed Apollo using docker and its clusters, to share it with you and to make a record of myself.
Note: I started with direct deployment. The creation and initialization of the database are done by myself according to the official website.
2. Source Code Compiling
2.1 Network Strategy
The network strategy can be described directly by the official website. Specifically, we edit apollo-configservice/src/main/resources/application.yml and apollo-adminservice/src/main/resources/application.yml respectively, and then add in the network cards that need to be ignored.
For apollo-configservice, the following example omits docker0 and veth. * when registering with Eureka.
spring: application: name: apollo-configservice profiles: active: ${apollo_profile} cloud: inetutils: ignoredInterfaces: - docker0 - veth.*
Note that you should be careful when modifying application.yml. Never correct other information, such as spring.application.name, etc.
2.2 Dynamic Specified Registration Network
To build a cluster with docker, adminservice and configservice need to register their addresses with the registry. If the registered IP is not specified, the network inside the docker is registered, which causes the network to be impassable.
Add the following code in apollo-configservice/src/main/resources/bootstrap.yml and apollo-adminservice/src/main/resources/bootstrap.yml.
eureka: instance: ip-address: ${eureka.instance.ip-address}
This place takes values from environment variables and configures them outside the container, which brings greater flexibility to deployment.
Upon completion of the modification of the source code, you can directly build the package and get the zip package corresponding to the three services.
If you are too lazy to modify, you can also directly from the https://github.com/yuelicn/ap... Pull down my modified source code and pack it directly.
3. dockerfile writing
Apollo's Dockerfile is very simple and can be used directly from the official source. Below is an adminservice example.
# Dockerfile for apollo-adminservice # Build with: # docker build -t apollo-adminservice . # Run with: # docker run -p 8090:8090 -d --name apollo-adminservice apollo-adminservice FROM java:8-jre MAINTAINER Louis ENV VERSION 1.5.0 RUN apt-get install unzip ADD apollo-adminservice-${VERSION}-github.zip /apollo-adminservice/apollo-adminservice-${VERSION}-github.zip RUN unzip /apollo-adminservice/apollo-adminservice-${VERSION}-github.zip -d /apollo-adminservice \ && rm -rf /apollo-adminservice/apollo-adminservice-${VERSION}-github.zip \ && sed -i '$d' /apollo-adminservice/scripts/startup.sh \ && echo "tail -f /dev/null" >> /apollo-adminservice/scripts/startup.sh EXPOSE 8090 CMD ["/apollo-adminservice/scripts/startup.sh"]
Notice that,
1: version needs to be modified according to its packaged version
2: Modify your path when ADD zip package
The dockerfile files for the three services are basically the same, so I won't go into that much. Need small partners directly from https://github.com/yuelicn/do... clone is OK.
4 docker-compose
4.1 apollo-configservice-compose.yml
version: "3" services: apollo-configservice: container_name: apollo-configservice build: apollo-configservice/ image: apollo-configservice ports: - 8080:8080 volumes: - "/docker/apollo/logs/100003171:/opt/logs/100003171" environment: - spring_datasource_url=jdbc:mysql://127.0.0.1:8306/ApolloConfigDB_TEST?characterEncoding=utf8 - spring_datasource_username=root - spring_datasource_password=mysql2019* - eureka.instance.ip-address=172.11.11.11 restart: always
Matters needing attention,
1: build: specify the location of your Dockerfile file
2: The configuration information of your database specified in the environment variable
3: eureka.instance.ip-address specifies the address to be registered with eureka, which is best used in your physical machine's intranet address.
Special note: It's better to change the eureka.service.url value in ServerConfig in Apollo ConfigDB database to specific IP before starting.
Start up:
docker-compose -f apollo-configservice-compose.yml up --build -d
3.2 apollo-adminservice-compose.yml
The content of apollo-adminservice-compose.yml is basically the same as that of apollo-configservice-compose.yml, which I will not explain one by one.
3.3 apollo-portal-compose.yml
version: "3" services: apollo-portal: container_name: apollo-portal build: apollo-portal/ image: apollo-portal ports: - 8070:8070 volumes: - "/docker/apollo/logs/100003173:/opt/logs/100003173" - "/apollo-portal/config/apollo-env.properties:/apollo-portal/config/apollo-env.properties" environment: - spring_datasource_url=jdbc:mysql://127.0.0.1:8306/ApolloPortalDB?characterEncoding=utf8 - spring_datasource_username=root - spring_datasource_password=mysql2019* restart: always
Matters needing attention:
1: Note that the above configservice is basically the same
2: The matters needing special attention are important! Important! Important! Important! Important! Volume: I will
The apollo-env.properties file is mapped to the outside of the container. After configuring its own apollo-env.properties file, it fills in its own mount address. The address before the colon "/ apollo-portal/config/apollo-env.properties" is changed to its own. This configuration file must be specified before startup.
start-up
docker-compose -f apollo-configservice-compose.yml up --build -d
3.3.1 apollo-env.properties
local.meta=http://localhost:8080 dev.meta=${dev_meta} fat.meta=${fat_meta} uat.meta=${uat_meta} lpt.meta=${lpt_meta} pro.meta=${pro_meta}
If you configure your meta address, you can delete it directly. If you don't understand it, you can go to the official website to learn about it. After the environment is configured, you can modify the corresponding database Apollo PortalDB. Server Config.
In the apollo.portal.envs value, fill in your configuration environment. Otherwise, we can only see the default dev environment on the portal management page.
4 Complete docker-compose.yml
If you dislike the start-up troubles one by one, use a complete compose to start.
version: "3" services: apollo-configservice: container_name: apollo-configservice build: apollo-configservice/ image: apollo-configservice ports: - 8080:8080 volumes: - "/docker/apollo/logs/100003171:/opt/logs/100003171" environment: - spring_datasource_url=jdbc:mysql://47.xx.xx.209:8306/ApolloConfigDB?characterEncoding=utf8 - spring_datasource_username=root - spring_datasource_password=Tusdao@xx* - eureka.instance.ip-address=172.11.11.11 restart: always apollo-adminservice: container_name: apollo-adminservice build: apollo-adminservice/ image: apollo-adminservice ports: - 8090:8090 volumes: - "/docker/apollo/logs/100003172:/opt/logs/100003172" environment: - spring_datasource_url=jdbc:mysql://47.xx.xx.209:8306/ApolloConfigDB?characterEncoding=utf8 - spring_datasource_username=root - spring_datasource_password=Tusdao@xx* - eureka.instance.ip-address=172.11.11.11 depends_on: - apollo-configservice restart: always apollo-portal: container_name: apollo-portal build: apollo-portal/ image: apollo-portal ports: - 8070:8070 volumes: - "/docker/apollo/logs/100003173:/opt/logs/100003173" - "/Apollo/docker-image/apollo-portal/config/apollo-env.properties:/apollo-portal/config/apollo-env.properties" environment: - spring_datasource_url=jdbc:mysql://47.xx.xx.209:8306/ApolloPortalDB?characterEncoding=utf8 - spring_datasource_username=root - spring_datasource_password=Tusdao@xx* depends_on: - apollo-adminservice restart: always
Note: The places that need to be modified are basically the same as individual ones. I won't nag about that.
To deploy Apoll docker basically completed, if a small partner needs a complete docker deployment file, please move https://github.com/yuelicn/do...
5 Cluster Construction
The construction of Apollo Cluster is very simple. It only needs two modifications. We will use the formal environment (pro) to illustrate.
In the pro environment, we built two sets of adminservice and configservice. The database is the same Apollo ConfigDB.
1: Write the eureka.service.url value Eureka connection information in ServerConfig separated by commas: http://IP-1:port/eureka,http://IP-2:port/eureka
2: Modify the connection information of the corresponding environment in apollo-env.properties, such as pro.meta= http://IP-1:port,http://IP-2 port addresses are separated by commas.
After that, the service was restarted.
Finally, it is emphasized that adminservice and configservice need to be deployed independently for each environment, including databases. portal only needs to deploy one set.
OK! Complete, the above refers to personal record building, hope to help you, if the wrong place is welcome to correct.
Modified source address: https://github.com/yuelicn/ap...
Docker-Apollo: https://github.com/yuelicn/do...