步骤一:创建debugggcloud_eureka_7002,debugggcloud_eureka_7003工程
步骤二:把debugggcloud_eureka_7001里面的eureka-server的pom坐标复制到7002和7003工程里面去
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
步骤三:修改debugggcloud_eureka_7001里面的yml文件的eureka.client.service-url.defaultZone修改为
eureka:
instance:
hostname: localhost #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己。
fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
service-url:
#单机 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址(单机)。
defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
步骤四:找到C:\Windows\System32\drivers\etc路径下的hosts文件,修改映射配置添加进hosts文件
127.0.0.1 eureka7001.com
127.0.0.1 eureka7002.com
127.0.0.1 eureka7003.com
步骤五复制上面步骤三的application.yml文件到7002工程,7003工程,其中注意eureka.client.service-url.defaultZone的内容,
7001工程的内容为:
eureka:
instance:
hostname: eureka7001.com #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己。
fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
service-url:
#单机 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址(单机)。
defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
7002工程的内容为:
eureka:
instance:
hostname: eureka7002.com #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己。
fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
service-url:
#单机 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址(单机)。
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7003.com:7003/eureka/
7003工程的内容为:
eureka:
instance:
hostname: eureka7003.com #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己。
fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
service-url:
#单机 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址(单机)。
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/
步骤六7001工程里面的启动类的名称复制到7002工程,7003工程里面去,并按照端口名修改下类名:
7002工程
package com.debuggg.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class Eureka7002_App {
public static void main(String[] args) {
SpringApplication.run(Eureka7002_App.class,args);
}
}
7003工程
package com.debuggg.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class Eureka7003_App {
public static void main(String[] args) {
SpringApplication.run(Eureka7003_App.class,args);
}
}
步骤七将eureka的客户端的eureka.client.service-url.defaultZone修改为:
eureka:
client:
service-url:
# defaultZone: http://eureka7001.com:7001/eureka/ #客户端入驻(注册到eureka服务端)的地址
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
instance:
instance-id: debugggcloud-dept8001 #用于显示在eureka服务端页面的服务名称,最开始叫 localhost:debugggcloud-dept:8001
prefer-ip-address: true
完成以上步骤之后,启动三个eureka服务端,再启动eureka客户端,访问:localhost:7001即可看到eureka集群启动成功