In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to deploy eureka clusters in Docker. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
Environmental preparation 1.docker environment
Installation under centos7: https://www.jianshu.com/p/ec02810d6a2b
Docker common command: https://www.jianshu.com/p/af7977b1075c
If you haven't used docker, you'd better familiarize yourself with docker first. The relevant explanation of docker has been omitted in the following content.
2.springcloud-eureka project
Blog address: https://my.oschina.net/devilsblog/blog/3114468
Code Cloud address: https://gitee.com/devilscode/cloud-practice/tree/eureka-test/
If you want to do it, you can follow the post. If you don't want to do it, you can directly down the code.
3.docker-compose environment
Execute the command: yum install docker-compose-y
The above environment is the minimum content to configure an eureka cluster in docker, and it is best to prepare in advance.
2. Local operation
Idea runs ServerApplication.main (). Open a browser and enter http://localhost:9000 to see the following figure.
Compile to jar and run
Execute mvn install under the root directory of the project, and you can see eureka-server-1.0-SNAPSHOT.jar under target
Jump to the directory under target and enter java-jar eureka-server-1.0-SNAPSHOT.jar > tmp.log
If you open the refresh browser window, you can still see the interface.
There is a hole here, that is, do not use the jar command that comes with Idea, it will report an error and there is no master list.
3. Docker single node trial run step1: upload files
Step2: create Dockerfile# docker image for eureka-server# version 1.0.The author Calvin# represents the underlying environment FROM java:8# represents the mapping folder VOLUME / tmp# copies files to the port EXPOSE 900 mapped by the mirror ADD eureka-server-1.0-SNAPSHOT.jar eureka-server.jar#, the RUN bash-c 'touch eureka-server.jar'# startup command ENTRYPOINT ["java", "- Djava.security.egd=file:/dev/./urandom" "- jar", "/ eureka-server.jar"] step3: compiles docker images
Compile
$docker build-t eureka-server.
-t indicates the specified image name
Don't ignore the last English dot.
The directory to be executed must have Dockerfile
The first execution may require downloading the base image of java8, which takes a long time
View the result
$docker images
Step4: starts the verification result of the image
Start the mirror docker run-d-p 9000Rang9000-- name eureka-server eureka-server
Page view
4. Run multiple nodes in Docker
Source code modification
Copy the application.yml file into two copies, the contents of which are as follows:
# slave1server: port: 9000eureka: instance: hostname: eureka-server1 client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://eureka-server2:9000/eureka#-# slave2server: port: 8080eureka : instance: hostname: eureka-server1 client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://eureka-server1:9000/eureka
Add docker-compose configuration
Version: '2'services: eureka-server1: image: eureka-server container_name: eureka-server1 hostname: eureka-server1 networks:-eureka-net ports:-9000 environment:-spring.profiles.active=slave1 eureka-server2: image: eureka-server container_name: eureka-server2 hostname: eureka-server2 networks:-eureka-net ports:-9001 environment:-spring. Profiles.active=slave2networks: eureka-net: driver: bridge
Recompile the docker image
# disable the original service docker stop eureka-server# to delete the service history to avoid repeating the service name during subsequent startup, docker rm eureka-server# deleting the original image docker rmi eureka# and regenerating the image. A mirror is still generated here, which is consistent with the previous step docker build-t eureka-server.
Start multiple services
# directory is Dockerfile and docker-compose.yml folder docker-compose up-d
Verification result
# View service docker ps | grep eureka-server # View log and wait for docker logs eureka-server1-f # to view port netstat-nltp
As you can already see in the figure, eureka-server has registered two
Five and three groups of tests
This part is outside the subject, and onlookers can withdraw.
Re-register a local registry into the cluster, and you can see the registered eureka-server from the remote cluster.
Result
Register the common-service service with the local registry, then register the feign-service with port 9001 of the remote center, and then call the processing
Remote 9000 port
Remote 9001 port
Call common-service with feign-service
Phenomenon
Conclusion
If you register a cluster, the registrations between the clusters should be notified to each other, and unilateral registration will cause services to be out of sync.
Even if there is an intermediate registry that can see the three services, the corresponding service will not be found because some of the instance information is not synchronized.
Three services can be seen on remote port 9000 and only two services on remote 9001
An exception occurred when feign-service called common-service
Re-register common-service to the remote, call once after the registration is successful, and then deactivate all registries
Results:
Conclusion:
Feign-service has pulled the registered service instance information to the local cache. Even if the registry hangs, it will not affect the service invocation for a short time (the specific time node should be before the registry restarts successfully).
VI. Summary
Practice docker to start micro-services, common operation exercises for enterprises
Deployment of registry clusters in docker and batch deployment of other services is manual for the time being, follow-up study K8s
Explore the three problems of eureka cluster, which can be regarded as trying the characteristic scenario of eureka and strengthening the memory.
After reading the above, do you have any further understanding of how to deploy eureka clusters in Docker? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.