SpringCloud之EurekaServer集群技术

注意:spingcloud的版本号与springboot的冲突问题我这里用的springcloud版本是:finchley.SR2,springboot版本是:2.0.7。

创建项目

SpringCloud之EurekaServer集群技术

在resources下面添加两个配置文件 

如图:

SpringCloud之EurekaServer集群技术

application-peer1.yml配置文件内容

server:
  port: 8750

spring:
  profiles: peer1

eureka:
  instance:
    hostname: peer1
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://peer2/eureka/

application-peer2.yml配置文件内容

server:
  port: 8760

spring:
  profiles: peer2

eureka:
  instance:
    hostname: peer2
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://peer1/eureka/

 启动类加注解

@EnableEurekaServer
@SpringBootApplication
public class EurekaschoolingApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaschoolingApplication.class, args);
    }
}

这里代码阶段已经完成

打包

项目打包方式自选

启动项目

采用如下命令

java -jar eurekaschooling-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer1 
java -jar eurekaschooling-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer2

 

在浏览其中分别打开如下网址,说明我们的集群搭建完毕

http://127.0.0.1:8750/

http://127.0.0.1:8750/

SpringCloud之EurekaServer集群技术