①建module
cloud-eureka-server7001
cloud-eureka-server7002
②改pom
<!--eureka-server-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!--boot web actuator-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
③写yaml
cloud-eureka-server7001
server:
port: 7001
eureka:
instance:
hostname: eureka7001.com #eureka服务端的实例名称(需要进行主机映射配置 eureka7001.com)
client:
#false表示不向注册中心注册自己。
register-with-eureka: false
#false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
fetch-registry: false
service-url:
#集群版
defaultZone: http://eureka7002.com:7002/eureka/
cloud-eureka-server7002
server:
port: 7002
eureka:
instance:
hostname: eureka7002.com #eureka服务端的实例名称(需要进行主机映射配置 eureka7002.com)
client:
#false表示不向注册中心注册自己。
register-with-eureka: false
#false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
fetch-registry: false
service-url:
#集群版
defaultZone: http://eureka7001.com:7001/eureka/
④主启动
cloud-eureka-server7001
@EnableEurekaServer
@SpringBootApplication
public class EurekaMain7001 {
public static void main(String[] args) {
SpringApplication.run(EurekaMain7001.class,args);
}
}
cloud-eureka-server7002
@EnableEurekaServer
@SpringBootApplication
public class EurekaMain7002 {
public static void main(String[] args) {
SpringApplication.run(EurekaMain7002.class, args);
}
}
⑤测试
http://localhost:7001/
http://localhost:7002/