docker Deployment apollo Detailed Tutorial

  • 2021-06-28 14:37:36
  • OfStack

1. Preface

I won't say more about apollo here. What https://github.com/ctripcorp/apollo has said on the official website is very clear. I won't be fooling around in this class. My unknown buddies can go to the official website to learn about it.

This article is just a record of how I deployed Apollo using docker and its clusters, sharing it with you and making a record of myself.

Note: I started with direct deployment, and the creation and initialization of the database were done by myself on the official website.

2. Source Code Compilation

2.1 Network Policy

Network policies can be described directly by the official website by editing apollo-configservice/src/main/resources/application.yml and apollo-adminservice/src/main/resources/application.yml respectively, and then adding in the network cards that need to be ignored.

For apollo-configservice, the following example omits the network cards of docker0 and veth. * when registering with Eureka.


spring:
   application:
     name: apollo-configservice
   profiles:
    active: ${apollo_profile}
   cloud:
    inetutils:
     ignoredInterfaces:
      - docker0
      - veth.*

Note that care should be taken when modifying application.yml. Never mistake other information, such as spring.application.name.

2.2 Dynamically specify the registration network

To set up a cluster using docker, both adminservice and configservice need to register addresses with the registry. If IP is not specified for registration, the network inside docker is registered, causing the network to become unreachable.

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 is where values are taken from environment variables, and configuring outside containers allows for greater flexibility in deployment.

Upon completion of the modification of the source code, build can be packaged directly and zip packages corresponding to three services can be obtained.

If you are too lazy to make changes, you can also package your modified source directly from https://github.com/yuelicn/apollo.

3. Writing by dockerfile

Dockerfile of Apollo is very simple, just use the official offer.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.The desired partner is available directly from https://github.com/yuelicn/docker-apollo.

Writing of 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: The location of your Dockerfile file is specified in build:
2: Configuration information for your database specified in the environment environment variable
3: eureka.instance.ip-address specifies to register to the eureka address, which is best used for the internal network address of your physical machine.

Special Note: It is better to modify the eureka.service.url value in ServerConfig in ApolloConfigDB database to specific IP before starting up.
Start:


docker-compose -f apollo-configservice-compose.yml up --build -d

4.2 apollo-adminservice-compose.yml

The content of apollo-adminservice-compose.yml is basically the same as apollo-configservice-compose.yml, which I will not explain in 11.

4.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: Notice that configservice is essentially the same
2: Particular considerations are important!Important!Important!Important!Important!volumes: I will
The apollo-env.properties file is mapped outside the container, its apollo-env.properties file is configured, its mount address is filled in, and the address before the colon'/apollo-portal/config/apollo-env.properties'is modified to its own.This profile must be specified before starting.
start-up


docker-compose -f apollo-configservice-compose.yml up --build -d

4.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 own meta address, you can delete any that you do not have.If you don't understand it, go to the official website to find out. Modify the value of apollo.portal.envs in ApolloPortalDB.ServerConfig to fill in the environment you configured.Otherwise, we can only see the default dev environment on the portal administration page.

5 Complete docker-compose.yml

If you suspect a boot hassle, start with a full compose.


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, so I won't nag about it.

Essentially complete Apoll deployment to this docker. If your partner needs a complete docker deployment file, go to https://github.com/yuelicn/docker-apollo

6 Cluster Building

The Apollo cluster is very simple to set up. It only needs to be modified in two places. We will describe it in the formal environment (pro).
In the pro environment, we have built two sets of adminservice, configservice, the same ApolloConfigDB database.

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 for the corresponding environment in apollo-env.properties, e.g. pro.meta=http://IP-1:port, http://IP-2:port addresses separated by commas.

Then restart the service.

Finally, it is emphasized that adminservice and configservice require each environment to be deployed separately, including databases.portal only needs to deploy one set.

OK!Complete. This refers to a person who has set up records and wants to help you. If you are not in the right place, you are welcome to make corrections.

Modified source address: https://github.com/yuelicn/apollo

Sorted Docker-Apollo:https://github.com/yuelicn/docker-apollo


Related articles: