搭建eureka集群
搭建三个eureka服务,修改全局配置文件
-
eureka01配置全局文件
spring: application: name: eureka01 server: port: 7001 #eureka的基本信息 eureka: instance: hostname: eureka7001.com client: service-url: defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/ #本身就是注册中心,不需要注册 register-with-eureka: false #本身就是注册中心,不需要获取注册信息 fetch-registry: false
-
eureka02配置全局文件
spring: application: name: eureka02 server: port: 7002 #eureka的基本信息 eureka: instance: hostname: eureka7002.com client: service-url: defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7003.com:7003/eureka/ #本身就是注册中心,不需要注册 register-with-eureka: false #本身就是注册中心,不需要获取注册信息 fetch-registry: false
-
eureka03配置全局文件
spring: application: name: eureka03 server: port: 7003 #eureka的基本信息 eureka: instance: hostname: eureka7003.com client: service-url: defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/ #本身就是注册中心,不需要注册 register-with-eureka: false #本身就是注册中心,不需要获取注册信息 fetch-registry: false
-
注意要配置windows的hosts文件(C:WindowsSystem32driversetchosts)
127.0.0.1 eureka7001.com 127.0.0.1 eureka7002.com 127.0.0.1 eureka7003.com
-
提供方的配置文件
spring: application: name: server01 server: port: 8082 #eureka的基本信息 eureka: instance: hostname: 127.0.0.1 client: service-url: defaultZone: http://127.0.0.1:7001/eureka/,http://127.0.0.1:7002/eureka/,http://127.0.0.1:7003/eureka/ #它本身是一个普通的服务,需要在eureka-server注册 register-with-eureka: true #需要获取注册信息 fetch-registry: true
-
消费方的配置文件
spring: application: name: client_01 server: port: 8080 #eureka的基本信息 eureka: instance: hostname: 127.0.0.1 client: service-url: defaultZone: http://127.0.0.1:7001/eureka/,http://127.0.0.1:7002/eureka/,http://127.0.0.1:7003/eureka/ #它本身是一个普通的服务,需要在eureka-server注册 register-with-eureka: true #需要获取注册信息 fetch-registry: true