在缺省情況下,啓動 Eureka Server,在瀏覽器中輸入http://EurekaIP:8761/後,就直接俄進入了spring cloud的服務治理頁面,
這麼做在生產環境是極不安全的,下面給Eureka Server加上安全的用戶認證。
1、在pom文件中加入安全認證依賴
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2、在application.properties設置用戶名和密碼
security.user.name=你的用戶名
security.user.password=你的密碼
3、在需要註冊到eureka註冊中心的spring cloud 微服務的application.properties中,
在下面的配置項目上加入用戶名和密碼,如下所示。
eureka.client.serviceUrl.defaultZone=http://${security.user.name}:${security.user.password}@註冊中心IP:${server.port}/eureka/