一、注冊中心集群配置
A台服務器:
創建application-peer1.properties,作為eureka1服務中心的配置,並將serviceUrl指向eureka-02,eureka-03 通過逗號隔開:
spring.application.name=eureka-server-a server.port=8000 eureka.instance.hostname=eureka-01 eureka.client.serviceUrl.defaultZone=http://B服務器IP:8001/eureka/,http://C服務器IP:8002/eureka/
B台服務器:
創建application-peer2.properties,作為eureka2服務中心的配置,並將serviceUrl指向eureka-01,eureka-03:
spring.application.name=eureka-server-b server.port=8001 eureka.instance.hostname=eureka2 eureka.client.serviceUrl.defaultZone=http://A服務器iP:8000/eureka/,http://C服務器Ip:8002/eureka/
C台服務器:
創建application-peer3.properties,作為eureka3服務中心的配置,並將serviceUrl指向eureka-01,eureka-02:
spring.application.name=eureka-server-c server.port=8002 eureka.instance.hostname=eureka-03 eureka.client.serviceUrl.defaultZone=http://A服務器iP:8000/eureka/,http://B服務器Ip:8001/eureka/
二、各服務配置
1、以單個user項目為例:
spring.application.name=rsp-eureka-provider(服務名稱) eureka.instance.prefer-ip-address=true spring.cloud.client.ipAddress=10.55.5.34(本機地址) eureka.instance.hostname= ${spring.cloud.client.ipAddress} eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port} eureka.instance.status-page-url=http://${spring.cloud.client.ipAddress}:${server.port}/swagger-ui.html //serviceUrl指向所有集群的eureka服務器,eureka1、eureka2、eureka3。 //服務器地址之間 逗號隔開 eureka.client.serviceUrl.defaultZone=http://A服務器iP:8000/eureka/,http://B服務器Ip:8001/eureka/,http://C服務器Ip:8002/eureka/
三、需要配置本地host
在部署eureka的服務器上都要在 hosts的文件中添加本地host,3台集群機器都要添加:
>vim /etc/hosts #新增 172.10.201.173 eureka-01 172.10.201.174 eureka-02 172.10.201.175 eureka-03
保存並退出