eureka注册中心

Eureka 服务端需要引入spring-cloud-starter-netflix-eureka-server
需要注册进eureka的所有服务(客户端)需要引入spring-cloud-starter-netflix-eureka-client

单机版

Eureka server服务端配置

Application.yml

server:
  port: 7001

eureka: #官方文档拷贝来的
  instance:
    hostname: localhost
  client:
    registerWithEureka: false #不向注册中心注册自己
    fetchRegistry: false 
    serviceUrl:
      defaultZone: http://localhost:7002/eureka/

Main方法1)

@SpringBootApplication

@EnableEurekaServer
//要加上这个

public class Application {

 

   
public static void main(String[]
args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
   
} 
}

 

 

Eureka client客户端配置

Application.yml

eureka:
  instance:
    hostname: localhost

  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
     


 

Main方法

@SpringBootApplication

@EnableEurekaClient//需要这个注解

 public class Main80 {

    public static void main(String[] args) {

        SpringApplication.run(Main80.class, args);

    }

}

 

 

集群版eueka配置

server:
  port: 7001

eureka: #官方文档拷贝来的
  instance:
    hostname: localhost
  client:
    registerWithEureka: false  
    fetchRegistry: false  
    serviceUrl:
      defaultZone: http://localhost:7002/eureka/
 server:
  port: 7002

eureka: #官方文档拷贝来的
  instance:
    hostname: localhost
  client:
    registerWithEureka: false #不向注册中心注册自己
    fetchRegistry: false #false表示自己端就是注册中心 职责就是维护实例 不需要去检索服务
    serviceUrl:
      defaultZone: http://localhost:7001/eureka/



然后服务往进来注册的时候俩都要注册

 

 

```bash
server:  port: 80  
eureka:  
 client:  
   serviceUrl: 
        defaultZone: http://localhost:8001,http://localhost:8002
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章