下面出现登录问题,需要参照给Eureka Server加上安全验证这篇文章:Spring Cloud (18) | 给Eureka Server加上安全验证
application.yml:
#安全验证
security:
basic:
enabled: true
user:
name: jack.ma
password: 1qaz2wsx
spring:
application:
name: eureka-server-cluster
profiles:
active: server1
application-server1.yml:
server:
port: 8761
eureka:
instance:
hostname: server1
# prefer-ip-address: true
instance-id: ${spring.application.name}:${server.port}
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://server2:8200/eureka/,http://server3:8300/eureka/
application-server2.yml:
server:
port: 8200
#
#spring:
# profiles:
# active: server1
eureka:
instance:
hostname: server2
# prefer-ip-address: true
instance-id: ${spring.application.name}:${server.port}
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://server1:8761/eureka/,http://server3:8300/eureka/
application-server3.yml:
server:
port: 8300
#
#spring:
# profiles:
# active: server1
eureka:
instance:
hostname: server3
# prefer-ip-address: true
instance-id: ${spring.application.name}:${server.port}
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://server1:8761/eureka/,http://server2:8200/eureka/
windows电脑,在c:/windows/systems/drivers/etc/hosts 修改
加入:
127.0.0.1 server1
127.0.0.1 server2
127.0.0.1 server3
启动工程:
在elipse中启动eureka-server:
java -jar eureka-server-0.0.1-SNAPSHOT.jar - -spring.profiles.active=server1
java -jar eureka-server-0.0.1-SNAPSHOT.jar - -spring.profiles.active=server2
java -jar eureka-server-0.0.1-SNAPSHOT.jar - -spring.profiles.active=server3
在 Edit Configurations中新建3个Spring Boot服务,选择“+“ 新建 “Spring Boot”, 分别是:eurekaServer-1,eurekaServer-2,eurekaServer-3
如图:
server1:
server3参照上图。
然后分别启动server1, server2, server3
eureka:
client:
serviceUrl:
defaultZone: http://jack.ma:1qaz2wsx@server1:8761/eureka/,http://jack.ma:1qaz2wsx@server2:8200/eureka/,http://jack.ma:1qaz2wsx@server3:8300/eureka/
defaultZone中多个服务之间,用","连接
三个Eureka Server中,按照这个顺序来显示微服务,shutdown其中的任何一个Eureka Server, 会顺次转发到另外一个Eureka Server上
完整项目,“墙裂“推荐看:https://github.com/dangduang/Spring-Cloud-By-Dang/tree/master/spring-cloud-eureka-server
更多系列文章推荐: