Spring cloud server 单机集群配置

Spring cloud server 单机集群配置

以下按部署两套server为例进行配置;
首先要在本机上修改/etc/hosts文件,添加两个hostname配置;

10.3.3.132 server1
10.3.3.132 server2

下面会用到这两个配置

server1的application.properties配置

请注意以下两处的配置:
这里配置是的另一个server实例的地址

eureka.client.serviceUrl.defaultZone=http://dmcpxy:dmcpxy@server2:18761/eureka/

这里配置的是当前实例使用的hostname,当在单机上部署服务注册中心集群时,这里不能使用${spring.cloud.client.ipAddress},否则会有冲突。而是要指定具体的一个不能重复的名字,如:

eureka.instance.hostname=server1

#for spring cloud server
spring.application.name=dmcpxy-cloud-server
server.port=18761
server.address=0.0.0.0
eureka.client.serviceUrl.defaultZone=http://test:test@server2:18762/eureka/

eureka.instance.prefer-ip-address=true

eureka.server.enable-self-preservation=true
eureka.server.eviction-interval-timer-in-ms=30000

eureka.instance.lease-expiration-duration-in-seconds=30


eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port}
eureka.instance.hostname=server1


security.basic.enabled=true
security.user.name=test
security.user.password=test

eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
########################################################
endpoints.shutdown.enabled=true
endpoints.shutdown.sensitive=false
endpoints.shutdown.path=/admin/shutdown
management.security.enabled=false
management.port=15151
management.address=127.0.0.1
########################################################

server2的application.properties配置

#for spring cloud server
spring.application.name=dmcpxy-cloud-server
server.port=18762
server.address=0.0.0.0
eureka.client.serviceUrl.defaultZone=http://test:test@server1:18761/eureka/

eureka.instance.prefer-ip-address=true

eureka.server.enable-self-preservation=true
eureka.server.eviction-interval-timer-in-ms=30000

eureka.instance.lease-expiration-duration-in-seconds=30


eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port}
eureka.instance.hostname=server2


security.basic.enabled=true
security.user.name=test
security.user.password=test

eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
########################################################
endpoints.shutdown.enabled=true
endpoints.shutdown.sensitive=false
endpoints.shutdown.path=/admin/shutdown
management.security.enabled=false
management.port=15151
management.address=127.0.0.1
########################################################

你可能感兴趣的:(互联网,大数据,Java,应用服务器)