注册中心关键配置:
#Eureka配置信息
#Eureka服务端名称
eureka.instance.hostname=localhost
#表示是否向eureka服务中心注册自己 默认为true
eureka.client.register-with-eureka=false
#是否从Eureka Server上获取注册信息,默认为true
eureka.client.fetch-registry=false
#监控页面
#单机写法
#eureka.client.service-url.defultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
#集群写法
eureka.client.service-url.defultZone=http://localhost:7002/eureka/,http://localhost:7003/eureka/
@EnableEurekaServer 服务端启动类配置,接收别人的注册
@SpringBootApplication
//服务端启动类配置,接收别人的注册
@EnableEurekaServer
public class ApiTest1 {
public static void main(String[] args) {
SpringApplication.run(ApiTest1.class,args);
}
}
客服端关键配置:
server.port=7002
spring.application.name=ApiTestClient1
#单机
#eureka.client.service-url.defultZone=http://localhost:7001/eureka/
#集群
eureka.client.service-url.defultZone=http://localhost:7002/eureka/,http://localhost:7003/eureka/
@EnableEurekaClient 客服端启动类配置
@SpringBootApplication
@EnableEurekaClient
public class ApiTestClient1 {
public static void main(String[] args) {
SpringApplication.run(ApiTestClient1.class,args);
}
}
可以通过访问Eureka看到当前注册中心详情 url:http://localhost:7001
大概就是这个样子(内容可能有点不符合上述配置,可到GitHub查看https://github.com/paascloud/paascloud-master 注:转自passcloud)
当访问成功时并且在 Instances currently registered with Eureka 内容中有客户端的监测状况。