本文共 2121 字,大约阅读时间需要 7 分钟。
1,pom依赖
org.springframework.cloud spring-cloud-starter-netflix-eureka-server 2,SpringBoot启动类package com.wwl.eureka_server;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@SpringBootApplication@EnableEurekaServerpublic class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); }}
3,yaml配置文件,application.yaml
spring: application: name: eureka-serverserver: port: 7901# eureka配置eureka: client: fetch-registry: false register-with-eureka: false service-url: defaultZone: http://eureka1:7901/eureka instance: hostname: eureka1
1,依赖
org.springframework.cloud spring-cloud-starter-netflix-eureka-server
2,启动类开启Eureka
package com.wwl.eureka_server;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@SpringBootApplication@EnableEurekaServer // 开启Eurekapublic class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); }}
3,Eureka注册中心配置(Eureka集群模式)
spring: application: name: eureka-server---spring: profiles: eureka1server: port: 7901eureka: client: service-url: defaultZone: http://eureka1:7901/eureka,http://eureka2:7902/eureka,http://eureka3:7903/eureka instance: hostname: eureka1---spring: profiles: eureka2server: port: 7902eureka: client: service-url: defaultZone: http://eureka2:7902/eureka,http://eureka1:7901/eureka,http://eureka3:7903/eureka instance: hostname: eureka2---spring: profiles: eureka3server: port: 7903eureka: client: service-url: defaultZone: http://eureka3:7903/eureka,http://eureka1:7901/eureka,http://eureka2:7902/eureka instance: hostname: eureka3
注意问题:
Eureka集群模式在本地玩的时候,每个节点要配置hostname,并配置本地host文件转载地址:http://vnnlf.baihongyu.com/