一、引入依赖
1、Eureka 6001
- 依赖导入
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>microservice-cloud-01</artifactId>
<groupId>com.haoxiansheng.springcloud</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>microservice-cloud-05-eureka-6001</artifactId>
<dependencies>
<!-- 导入Eureka-server 服务端依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
</project>
- 配置文件 application.yml
server:
port: 6001 # 服务端口
eureka:
instance:
hostname: eureka6001.com # eureka服务端的实例名
client:
registerWithEureka: false # 服务注册,false表示不将自已注册到Eureka服务中
fetchRegisrty: false # 服务发现,false表示自己不从Eureka服务中获取注册信息
serviceUrl: # Eureka客户端与Eureka服务端的交互地址,集群版配置对方的地址,单机版配置自
#己(如果不配置则默认本机8761端口)
#defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
defaultZone: http://127.0.0.1:6002/eureka/
server:
enable-self-preservation: false # 禁用自我保护机制
- 开启
package com.haoxiansheng.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer //标识一个Eureka Server服务注册中心
@SpringBootApplication
public class EurekaServer_6001 {
public static void main(String[] args) {
SpringApplication.run(EurekaServer_6001.class, args);
}
}
2、 Eureka 6002
- 依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>microservice-cloud-01</artifactId>
<groupId>com.haoxiansheng.springcloud</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>microservice-cloud-05-eureka-6002</artifactId>
<dependencies>
<!-- netflix-eureka-server 服务端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
</project>
- 配置文件 application.yml
server:
port: 6002 # 服务端口
eureka:
instance:
hostname: eureka6002.com # eureka服务端的实例名
client:
registerWithEureka: false # 服务注册,false表示不将自已注册到Eureka服务中
fetchRegisrty: false # 服务发现,false表示自己不从Eureka服务中获取注册信息
serviceUrl: # Eureka客户端与Eureka服务端的交互地址,集群版配置对方的地址,单机版配置自
#己(如果不配置则默认本机8761端口)
#defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
defaultZone: http://127.0.0.1:6001/eureka/
server:
enable-self-preservation: false # 禁用自我保护机制
- 启动
package com.haoxiansheng.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class EurekaServer_6002 {
public static void main(String[] args) {
SpringApplication.run(EurekaServer_6002.class, args);
}
}