Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to achieve eureka High availability through docker and docker-compose

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to achieve high availability of eureka through docker and docker-compose". The editor shows you the operation process through actual cases. The method of operation is simple and fast, and it is practical. I hope this article "how to achieve high availability of eureka through docker and docker-compose" can help you solve the problem.

1. Eureka server project directory structure:

2. Eureka profile configuration:

Server: port: 8900spring: application: name: eureka-server profiles: active: devmanagement: security: false health: rabbit: enabled: false---spring: profiles: deveureka: client: serviceurl: defaultzone: http://localhost:${server.port}/eureka/ register-with-eureka: false fetch-registry: false instance: hostname: localhost prefer-ip-address: true---spring: profiles: test_ha_1eureka: client: serviceurl: defaultzone: http://eurekaserver2 : ${server.port} / eureka/ instance: hostname: eurekaserver1# prefer-ip-address: true this configuration is true, which means that the ip registered to the eureka If this happens, the eureka server will not be able to discover the replicas through the server. # therefore, if you want to achieve high availability of eureka through docker, it is best to use the default value (false) # it is not impossible to configure true and achieve high availability here, that is, each eureka service needs to be mapped outside the docker environment and know ip. -spring: profiles: test_ha_2eureka: client: serviceurl: defaultzone: http://eurekaserver1:${server.port}/eureka/ instance: hostname: eurekaserver2# prefer-ip-address: true

3. Docker maven plug-in configuration:

Org.springframework.boot spring-boot-maven-plugin com.spotify docker-maven-plugin 0.4.13 ${docker.image.prefix} / ${project.artifactid}: ${project.version} src/main/docker true / ${project.build.directory}

4. Contents of docker file file:

From java:8add eureka-server-1.0.0.jar eurekaserver.jarentrypoint ["java", "- djava.security.egd=file:/dev/./urandom", "- jar", "/ eurekaserver.jar"]

5. Generate an eureka server image:

Generate an eurekaserver image by executing the mvn clean package docker:build command, as follows:

6. Choreographed through docker-compose:

Version: '2'services: eurekaserver1: image: raynspace/eureka-server:1.0.0 ports:-"7900image 8900" environment:-spring.profiles.active=test_ha_1 eurekaserver2: image: raynspace/eureka-server:1.0.0 # hostname: eurekaserver2 ports:-"7800image 8900" environment:-spring.profiles.active=test_ha_2

7. Jump to the project directory, execute the docker-compose up command, and automatically generate two eureka server containers:

8. Since the eureka port has been mapped, access the eureka locally through the port to check the status of the eureka service:

As you can see from the figure above, another eureka service can be seen in both registered-replicas and available-replicas, and the eureka cluster has been built.

This is the end of the content on "how to achieve high availability of eureka through docker and docker-compose". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report