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 > Servers >

Share

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

This article is about how to achieve high availability of eureka through docker and docker-compose. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

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.

Thank you for reading! This is the end of this article on "how to achieve high availability of eureka through docker and docker-compose". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

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

Servers

Wechat

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

12
Report