Eureka笔记:
1、导入依赖
这个已过时
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactid>spring-cloud-starter-eureka-server</artifactid>
<version>1.4.7.RELEASE</version>
</dependency>
建议使用:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactid>spring-cloud-starter-netflix-eureka-server</artifactid>
<version>1.4.7.RELEASE</version>
</dependency>
2、编辑配置文件
eureka:
instance:
hostname: eureka-server-9003 #服务端实例名称
client:
register-with-eureka: false #表示是否向eureka注册中心注册自己
fetch-registry: false #为false代表自己为注册中心
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka #为替换源码中的地址
3、开启这个功能: @EnableEurekaServer @EnableXXX
4、配置类
5、访问后台控制页面 localhost:port 即可
6、配置provider项目 注册到注册中心:
- 添加依赖
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
7、配置监控信息
*导入依赖包
<!--配置监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
application.yml:
info:
app.name: yog测试eureka注册中心
company.name: yog
build.artifactId: $project.artifactId$
build.version: $project.version$
8、配置Eureka集群:
- 新建Module
- 添加pom依赖
- 修改eureka注册中心的配置
修改eureka注册中心配置:(非当前项目的 ip:port)
经过测试 需要修改hosts文件才能注册DS
service-url:
defaultZone: http://eureka9004.com:9004/eureka/,http://eureka9005.com:9005/eureka/ #为替换源码中的地址
修改provider项目的配置:(所有eureka注册中心的 ip:port)
service-url:
defaultZone: http://localhost:9003/eureka/,http://localhost:9004/eureka/,http://localhost:9005/eureka/ #为替换源码中的地址