为什么
使用这个三个版本,是有讲究的;spring boot 2.2.2
,spring cloud Hoxton.SR1
,spring cloud alibaba 2.1.0.RELEASE
开始引入注册中心,概念待补充… 计划Eureka集群2个节点,一个cloud-eureka-server7001,另一个cloud-eureka-server7002
把 hostname:
eureka7001.com
改为: hostname:localhost
hostname: eureka7001.com
把 defaultZone: http://{eureka.instance.hostname}: {server.port}/eureka/ 改为:defaultZone: http://eureka7002.com:7002/eureka/ 你没看错,是eureka7002.com:7002,要互相注册,相互守护
完整配置文件
server:
port: 7001
eureka:
instance:
#eureka服务端的实例名称
#hostname: localhost
hostname: eureka7001.com
client:
#false表示不向注册中心注册自己。
register-with-eureka: false
#false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
fetch-registry: false
service-url:
#设置与Eureka Server交互的地址查询服务和注册服务都要依赖这个地址
#defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
#单机就是7001自己
#defaultZone: http://eureka7001.com:7001/eureka/
#集群指向其它eureka
defaultZone: http://eureka7002.com:7002/eureka/
windows的hosts在xxx mac下 直接 终端
sudo vim /etc/hosts
###################SpringCloud2020##############
127.0.0.1 eureka7001.com
127.0.0.1 eureka7002.com
artifactId和name记得改为7002
<artifactId>cloud-eureka-server7002</artifactId>
<name>cloud-eureka-server7002</name>
完成pom
<?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>cloud2020</artifactId>
<groupId>cn.cookily.springcloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-eureka-server7002</artifactId>
<name>cloud-eureka-server7002</name>
<dependencies>
<!--eureka-server 2.x版本 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!-- 引入自己定义的api通用包,可以使用Payment支付Entity -->
<dependency>
<groupId>cn.cookily.springcloud</groupId>
<artifactId>cloud-api-commons</artifactId>
<version>${project.version}</version>
</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>
<!--一般通用配置-->
<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>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
代码如下
@SpringBootApplication
@EnableEurekaServer
public class EurekaMain7002 {
public static void main(String[] args) {
SpringApplication.run(EurekaMain7002.class, args);
}
}
端口
hostname
defaultZone
,别看花了
server:
port: 7002
eureka:
instance:
#eureka服务端的实例名称
#hostname: localhost
hostname: eureka7002.com
client:
#false表示不向注册中心注册自己。
register-with-eureka: false
#false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
fetch-registry: false
service-url:
#设置与Eureka Server交互的地址查询服务和注册服务都要依赖这个地址
#defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
#单机就是7002自己
#defaultZone: http://eureka7002.com:7002/eureka/
#集群指向其它eureka
defaultZone: http://eureka7001.com:7001/eureka/
7002模块不在Dashboard里的话,刷新一下maven