1.集群原理
互相注册,相互守望
2.实现
(1)新建eureka-server1001工程
(2)导入jar包
<properties> <java.version>1.8</java.version> <spring-cloud.version>Hoxton.SR4</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
(3)在启动类上加入@EnableEurekaServer注解
(4)新建application.yml
spring: application: name: eureka-server1001 #工程名 server: port: 1001 #端口号 eureka: instance: namespace: 127.0.0.1 #实例地址 client: register-with-eureka: false #是否注册自己 fetch-registry: false #是否检索服务 service-url: defaultZone: http://${eureka.instance.namespace}:1002/eureka/ #注册中心地址
(5)新建eureka-server1002工程
(6)导入jar包
(7)在启动类上加入@EnableEurekaServer注解
(8)新建application.yml
spring: application: name: eureka-server1002 #工程名 server: port: 1002 #端口号 eureka: instance: namespace: 127.0.0.1 #实例地址 client: register-with-eureka: false #是否注册自己 fetch-registry: false #是否检索服务 service-url: defaultZone: http://${eureka.instance.namespace}:1001/eureka/ #注册中心地址