您好,登錄后才能下訂單哦!
公眾號: java樂園
1、 Eureka作為spring cloud的服務發現與注冊中心,在整個的微服務體系中,處于核心位置。單機模式下的eureka服務,顯然不能滿足高可用的實際生產環境,這就要求配置一個能夠應對各種突發情況,具有較強容災能力的eureka服務。Eureka通過“伙伴機制”實現高可用。每一臺Eureka都需要在配置中指定另外兩個Eureka的地址伙伴,Eureka啟動時會向自己的伙伴節點獲取當前已經存在的注冊表,這樣在向Eureka集群中新加機器時就不需要擔心注冊表的不完整。
2、 新建三個maven項目,分別為sc-eureka-cluster-server-node1,sc-eureka-cluster-server-node2,sc-eureka-cluster-server-node3。項目結構如下:
備注:pom.xml和EurekaServerApplication.java的內容給單機模式是一模一樣的,請參考上篇文章。
3、 主要看下bootstap.yml或者application.yml文件的改動
sc-eureka-cluster-server-node1
spring:
application:
name: sc-eureka-cluster-server-node1
server:
port: 5001
eureka:
instance:
hostname: sc-eureka-cluster-server-node1
lease-renewal-interval-in-seconds: 30
lease-expiration-duration-in-seconds: 30
prefer-ip-address: true
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://sc-eureka-cluster-server-node2:5002/eureka/,http://sc-eureka-cluster-server-node3:5003/eureka/
sc-eureka-cluster-server-node2
spring:
application:
name: sc-eureka-cluster-server-node2
server:
port: 5002
eureka:
instance:
hostname: sc-eureka-cluster-server-node2
lease-renewal-interval-in-seconds: 30
lease-expiration-duration-in-seconds: 30
prefer-ip-address: true
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://sc-eureka-cluster-server-node1:5001/eureka/,http://sc-eureka-cluster-server-node3:5003/eureka/
sc-eureka-cluster-server-node3
spring:
application:
name: sc-eureka-cluster-server-node3
server:
port: 5003
eureka:
instance:
hostname: sc-eureka-cluster-server-node3
lease-renewal-interval-in-seconds: 30
lease-expiration-duration-in-seconds: 30
prefer-ip-address: true
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://sc-eureka-cluster-server-node1:5001/eureka/,http://sc-eureka-cluster-server-node2:5001/eureka/
4、 配置host文件C:\Windows\System32\drivers\etc\hosts
127.0.0.1 sc-eureka-cluster-server-node1
127.0.0.1 sc-eureka-cluster-server-node2
127.0.0.1 sc-eureka-cluster-server-node3
5、 分別啟動EurekaServerApplication.java
sc-eureka-cluster-server-node1的日志:
sc-eureka-cluster-server-node2的日志:
sc-eureka-cluster-server-node3的日志
如果出現上面圈住的日志說明啟動成功
6、 在瀏覽器分別訪問
http://sc-eureka-cluster-server-node1:5001/
http://sc-eureka-cluster-server-node2:5002/
http://sc-eureka-cluster-server-node3:5002/
下面列出幾個重要的配置項類:
org.springframework.boot.autoconfigure.web.ServerProperties
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean
com.netflix.eureka.EurekaServerConfig
com.netflix.eureka.DefaultEurekaServerConfig
org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean
com.netflix.discovery.EurekaClientConfig
com.netflix.discovery.DefaultEurekaClientConfig
org.springframework.cloud.netflix.eureka.EurekaClientConfigBean
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。