标签:配置 地址 default tap files local spl public frame
<dependencies> <!--开始Eureka的服务中心--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> </dependencies>
server: port: 1010 #端口 eureka: instance: hostname: localhost #主机 client: #客户端配置 registerWithEureka: false #EurekaServer自己不要注册到EurekaServer自己 ,只有EurekaClient才注册 fetchRegistry: false #EurekaServer不要拉取服务的通信地址列表 ,只有EurekaClient才拉取地址列表 serviceUrl: #注册中心的注册地址 defaultZone: http://localhost:1010/eureka/ #http://${eureka.instance.hostname}:${server.port}/eureka/
通过active分别启动不过有些不支持多个开启需要放开
如果需要模拟上个配置者需要在hosts文件中添加127.0.0.1:peer1等
如果开启会报错是没有问题的,因为他会30s发送一次连接,三次没有连接成功可能会报错,但是一开始会报错是正常的
eureka: client: serviceUrl: defaultZone: http://peer1:1011/eureka/,http://peer2:1012/eureka/,http://peer3:1013/eureka/ spring: profiles: active: peer3 #需要启用的配置 --- spring: profiles: peer1 #配置名称 application: name: eureka-service #服务名称 eureka: instance: hostname: peer1 #主机名称 prefer-ip-address: true instance-id: eureka-service server: port: 1011 --- spring: profiles: peer2 #配置名称 application: name: eureka-service #服务名称 eureka: instance: hostname: peer2 #主机名称 prefer-ip-address: true instance-id: eureka-service:1012 server: port: 1012 --- spring: profiles: peer3 #配置名称 application: name: eureka-service #服务名称 eureka: instance: hostname: peer3 #主机名称 prefer-ip-address: true instance-id: eureka-service:1013 server: port: 1013
/** * 注册中心启动类 * @EnableEurekaServer : 开启EurekaServer服务端 */ @SpringBootApplication @EnableEurekaServer public class EurekaServerApplication1010 { public static void main( String[] args ) { SpringApplication.run(EurekaServerApplication1010.class); } }
一样的分为三部
导包
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
写入yml
eureka: client: serviceUrl: #注册到EurekaServer defaultZone: http://peer1:1011/eureka/,http://peer2:1012/eureka/,http://peer3:1013/eureka/ instance: prefer-ip-address: true #是否开启ip注册 instance-id: user-server:1020 #ip名称 spring: application: name: user-server #服务名称 server: port: 1020
写入配置类
/** * 用户的启动类 * @EnableEurekaClient: 标记该应用是 Eureka客户端 */ @SpringBootApplication @EnableEurekaClient public class UserServerApplication1020 { public static void main( String[] args ) { SpringApplication.run(UserServerApplication1020.class); } }
标签:配置 地址 default tap files local spl public frame
原文地址:https://www.cnblogs.com/xiaoruirui/p/13617108.html