首先是版本是
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring.cloud.version>Dalston.SR4</spring.cloud.version>
<spring-boot-admin.version>1.5.4</spring-boot-admin.version>
</properties>
首先是单节点的
spring:
profiles:
active: aliyun
---
spring:
profiles: aliyun
server:
port: 8765
eureka:
instance:
hostname: registry1
client:
registerWithEureka: false
fetchRegistry: false
service-url:
defaultZone: http://${security.user.name}:${security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/
security:
user:
name: user
password: ${REGISTRY_SERVER_PASSWORD:password}
可以看出来运行是可以了但是因为是单节点就没有分片这些显示了。其中在配置文件中的registerWithEureka和fetchRegistry是为了让eureka互相注册作为一个集群,如果都是false那么当前的服务器是唯一的服务器
接下来是集群
首先我尝试了用ip地址直接配置
spring:
profiles:
active: aliyun1
---
spring:
profiles: aliyun
server:
port: 8761
eureka:
instance:
ip-address: 127.0.0.1
client:
registerWithEureka: true
fetchRegistry: false
service-url:
defaultZone: http://${security.user.name}:${security.user.password}@127.0.0.1:${server.port}/eureka/
security:
user:
name: user
password: ${REGISTRY_SERVER_PASSWORD:password}
test:
hostname: registry2
port: 8762
---
spring:
profiles: aliyun1
server:
port: 8762
eureka:
instance:
ip-address: 127.0.0.1
client:
registerWithEureka: true
fetchRegistry: true
service-url:
defaultZone: http://${security.user.name}:${security.user.password}@127.0.0.1:${server.port}/eureka/
security:
user:
name: user
password: ${REGISTRY_SERVER_PASSWORD:password}
test:
hostname: registry1
port: 8761
结果界面显示
结果这两个分区都是挂掉的。。。。无效
查了一下原因
https://www.cnblogs.com/xuechen/p/9085162.html
https://blog.youkuaiyun.com/qq_36345181/article/details/81349211
然后修改了配置
spring:
profiles:
active: aliyun
---
spring:
profiles: aliyun
server:
port: 8761
eureka:
instance:
hostname: registry1
client:
registerWithEureka: true
fetchRegistry: true
service-url:
defaultZone: http://${security.user.name}:${security.user.password}@${test.hostname}:${test.port}/eureka/
security:
user:
name: user
password: ${REGISTRY_SERVER_PASSWORD:password}
test:
hostname: registry2
port: 8762
---
spring:
profiles: aliyun1
server:
port: 8762
eureka:
instance:
hostname: registry2
client:
registerWithEureka: true
fetchRegistry: true
service-url:
defaultZone: http://${security.user.name}:${security.user.password}@${test.hostname}:${test.port}/eureka/
security:
user:
name: user
password: ${REGISTRY_SERVER_PASSWORD:password}
test:
hostname: registry1
port: 8761
效果,分区已经可以正常使用了