1.設置服務器之間的host,測試環境是在window10上搭建的,因此去修改C:\Windows\System32\drivers\etc文件,以下:git
2.建立項目:spring
3.編輯配置文件:服務器
application.yml:
#一組服務須要使用相同的服務名稱,才能被識別爲一組!
application:
name: eureka-server
application-euk1.yml: eureka: client: #集羣模式須要設置爲true register-with-eureka: true #集羣模式須要設置爲true fetch-registry: true #設置服務註冊中心的URL,用於client和server端交流 #注意事項: #eureka.client.serviceUrl.defaultZone配置項的地址,不能使用localhost,要使用service-center-1之類的域名,經過host映射到127.0.0.1; service-url: defaultZone: http://euk2.com:8702/eureka/ instance: #hostname爲必填 hostname: euk1.com server: port: 8701
application.euk2.yml: eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://euk1.com:8701/eureka/ instance: hostname: euk2.com server: port: 8702
4.設置Configuration,以不一樣的配置文件啓動兩個eureka實例:app
5.看一下啓動正常後的運行界面:(8702端口界面也是同樣的,就不貼了)測試
6.總結:在部署eureka單節點和高可用時候遇到的坑:fetch
a.第一次部署eureka的時候,只是在配置文件中配置了eureka的相關配置,沒有在啓動類上加註解 @EnableEurekaServer,因此訪問控制檯報錯404url
spa