還是三板斧:先改配置文件,支持集群,然后出包,上傳到linux環境(3個節點),最后啟動jar包跑起來。
1、在原eureka服務端代碼(參見Greenwich.SR2版本的Spring Cloud Eureka實例)基礎上修改配置文件即可,這次我們廢棄原來的application.properties文件,新增3個yml(用properties也可以,自己選用):
application-es1.yml(給192.1.6.19節點用,它需要指定另外兩個節點作為注冊中心,其他兩個同理):
eureka: client: fetch-registry: true register-with-eureka: true service-url: defaultZone: http://192.1.6.20:8761/eureka,http://192.1.6.22:8761/eureka instance: prefer-ip-address: true instance-id: ${spring.cloud.client.ip-address}:${server.port} hostname: ${spring.cloud.client.ip-address} ip-address: 192.1.6.19 spring: profiles: active: es1 application: name: eureka-server server: port: 8761
application-es2.yml:
eureka: client: fetch-registry: true register-with-eureka: true service-url: defaultZone: http://192.1.6.19:8761/eureka,http://192.1.6.22:8761/eureka instance: prefer-ip-address: true instance-id: ${spring.cloud.client.ip-address}:${server.port} hostname: ${spring.cloud.client.ip-address} ip-address: 192.1.6.20 spring: profiles: active: es2 application: name: eureka-server server: port: 8761
application-es3.yml:
eureka: client: fetch-registry: true register-with-eureka: true service-url: defaultZone: http://192.1.6.19:8761/eureka,http://192.1.6.20:8761/eureka instance: prefer-ip-address: true instance-id: ${spring.cloud.client.ip-address}:${server.port} hostname: ${spring.cloud.client.ip-address} ip-address: 192.1.6.22 spring: profiles: active: es3 application: name: eureka-server server: port: 8761
2、maven出包后直接到linux對應的三個節點上rz -y上傳生成的jar包
3、在三個節點上啟動eureka-server,分別根據環境指定參數es1、es2、es3,比如我在192.1.1.0上啟動,那么我需要指定環境為es1,其他兩個同理:
java -jar eureka-0.0.1-SNAPSHOT.jar --spring.profiles.active=es1
最后看下eureka界面http://192.1.1.2:8761/,可以看到已經支持集群,另外兩個鏈接界面就不貼了:
如果要重啟實例,需要先把原有進程找出來,比如我要重啟es3環境的eureka:
$ netstat -nlp | grep 8761 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp6 0 0 :::8761 :::* LISTEN 14998/java $ kill 14998 $ java -jar eureka-0.0.1-SNAPSHOT.jar --spring.profiles.active=es3