Goal: Containerized deployment of Spring Cloud basic service components based on Docker
Environment: CentOS 7.2 operating system
Basic service: Eureka service registration center + Config service configuration center
Others: Zuul service gateway+Zipkin service tracking center+RabbitMQ message queue service+ElasticSearch storage service+Kibana display service
Steps: Microservice jar package construction -> Docker environment preparation -> Docker Compose orchestration file writing -> orderly start the application
1. Microservice jar package construction
Build executable jar packages for Eureka service registration center, Config service configuration center, Zipkin service tracking center, Zuul service gateway, and Service test service.
Except for the registry and configuration center services, other microservices read configuration files from the Gitlab configuration center.
2. Docker environment preparation
(1) docker installation
yum install -y docker
systemctl start docker
docker versionView version:
(2) Mirror accelerator configuration
Reference: http://guide.daocloud.io/dcs/docker-9153151.html
Direct import error resolution:
Modify /etc/docker/daemon.json to remove commas
重启docker:systemctl restart docker
(3) docker-compose installation
yum install -y python-pip
pip install docker-compose
docker-compose versionView version:
(4) Image construction
Java-based Dockerfile writing: take eureka-server as an example
Remarks: When building an image, only the basic services of eureka-server and config-server are set to execute the jar package when the container is started, and other services are started with the command command in the compose arrangement file as required.
3. Docker Compose orchestration file writing
(1) Support components
There are three supporting components required for the construction of a microservice center:
rabbitmq - provides message queue functionality
elasticsearch - Provides service tracking link data storage function
kibana - Provides service tracking link data display function: docking with elasticsearch
Compared with the process of installing components and configuring virtual machines, it is more reasonable to directly add supporting components to the orchestration queue of containerized deployment
docker-compose.yml :
Support components need to be activated first
(2) Service Registration Center
The registry is the basic service and needs to be started first
The external access address is: http://host address:8761/
(3) Service Configuration Center
The configuration center is the basic service, which needs to be started first, and the configuration center has a large number of visits. Enable two configuration services to achieve high availability.
The configuration file address set in the configuration center is the Gitlab server address.
(4) Service Tracking Center
The service tracking center is a post-start service, which depends on the basic service and needs to read the configuration file from the configuration center to start.
External access address: http://host IP:9411/
(5) Service Gateway
The service gateway is a post-start service, which depends on the basic service and the test service, and needs to find the test service address.
(6) Test microservices
The test microservice is a post-start service that provides access address mapping services.
Because docker-compose can only realize the order of container startup, it cannot guarantee the order of services inside the container. Therefore, use the sleep command to delay the startup of the gateway, trace, and test three services.
Directory Structure:
4. Start apps sequentially
Start command: docker-compose up -d
Sequence: rabbitmq+elasticsearch+kibana+registration center+configuration center->tracking center+gateway+test service
View container information after startup: docker-compose ps
Verify that the services are running normally: visit http://host IP:5000/testapi/user/hello multiple times
(1) Registration Center
(2) Tracking Center
(3)rabbitmq
(4)elasticsearch
(5) kibana