Eureka集群配置(简单的)

Eureka 集群配置

一.准备多个注册中心

这是之前搭建Eureka注册中心的博客.注册中心端口号为7001。https://www.cnblogs.com/xiaominaaaa/p/14065538.html
ps: 就是多个注册中心互相指向对方的地址

配置虚拟路径

  • 之前有试过所有的eureka.instance.hostname都设置为localhost和127.0.0.1(两者都测试过),集群配置中没有显示,但是配置了虚拟路径后,可以显示了
  • 在 C://Windows/System32/drivers/HOSTS 文件下
127.0.0.1 eureka1.com
127.0.0.1 eureka2.com
127.0.0.1 eureka3.com

第一个注册中心端口号 7001

  • java 代码
@SpringBootApplication
@EnableEurekaServer
public class EurakeServer_7001 {
    public static void main(String[] args) {
        SpringApplication.run(EurakeServer_7001.class,args);
    }
}
  • pom.xml
 <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>
  • application.yml
server:
  port: 7001

#Eurake 注册中心配置,基本上都这样配置
eureka:
  instance:
    hostname: eureka1.com # Eurake 服务端的实例名称
  client:
    register-with-eureka: false # 表示是否向Eureka 注册中心注册自己
    fetch-registry: false # fatch-registry 为 false表示 自己为注册中心
    service-url: # 监控页面
        #指向其他的两个配置中心 
      defaultZone: http://eureka2.com:7002/eureka/,http://eureka3.com:7003/eureka/

第二个注册中心端口号 7002

  • java 代码
@SpringBootApplication
@EnableEurekaServer
public class EurakeServer_7002 {
    public static void main(String[] args) {
        SpringApplication.run(EurakeServer_7002.class,args);
    }
}
  • pom.xml
 <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>
  • application.yml
server:
  port: 7002

#Eurake 注册中心配置,基本上都这样配置
eureka:
  instance:
    hostname: eureka2.com # Eurake 服务端的实例名称
  client:
    register-with-eureka: false # 表示是否向Eureka 注册中心注册自己
    fetch-registry: false # fatch-registry 为 false表示 自己为注册中心
    service-url: # 监控页面
        #指向其他两个注册中心
      defaultZone: http://eureka1.com:7001/eureka/,http://eureka3.com:7003/eureka/

第三个注册中心端口号 7003

  • java 代码
@SpringBootApplication
@EnableEurekaServer
public class EurakeServer_7003 {
    public static void main(String[] args) {
        SpringApplication.run(EurakeServer_7003.class,args);
    }
}
  • pom.xml
 <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>
  • application.yml
server:
  port: 7003

#Eurake 注册中心配置,基本上都这样配置
eureka:
  instance:
    hostname: eureka3.com # Eurake 服务端的实例名称
  client:
    register-with-eureka: false # 表示是否向Eureka 注册中心注册自己
    fetch-registry: false # fatch-registry 为 false表示 自己为注册中心
    service-url: # 监控页面
    #指向其他两个注册中心
      defaultZone: http://eureka2.com:7001/eureka/,http://eureka1.com:7002/eureka/

成功之后的截图

posted @ 2021-01-03 21:06  阿肆啊  阅读(159)  评论(0)    收藏  举报