spring cloud eureka註冊中心環境搭建

  1. 引入maven依賴,該依賴包含spring boot starter依賴,所以不需要再引入其他依賴
		<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
  1. 添加eureka註冊中心啓動類
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class, args);
    }

}

3.配置application.yml

server:
  port: 8001
spring:
	security:
	  basic:
	    enabled: true
      user:
        name: root
        password: zxy2019
  application:
    name: eureka-server
eureka:
  instance:
    namespace: eureka-server
    instace-id: ${spring.cloud.client.ipAddress}:${spring.application.name}
    hostname: localhost
    prefer-ip-address: false
  client:
    registerWithEureka: false
    fetchRegistry: false
    healthcheck:
      enabled: true
    serviceUrl:
      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka
  server:
    wait-time-in-ms-when-sync-empty: 0
    enable-self-preservation: false
    eviction-interval-timer-in-ms: 5000
  1. 爲了安全起見,加入spring security starter依賴,以保證不被人隨便查看註冊中心控制檯和隨意註冊服務到註冊中心
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

上面defaultZone屬性已經配置過註冊中心註冊時需要攜帶用戶名密碼纔可以註冊,而且訪問eureka控制檯也需要這個用戶名密碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章