Spring Cloud Eureka 集群搭建部署

Spring Cloud Eureka 集群搭建部署

Maven依赖如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?xml version="1.0"?>
<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springblade</groupId>
<artifactId>spring-cloud-blade</artifactId>
<version>1.0</version>
</parent>

<artifactId>spring-blade-eureka</artifactId>
<name>spring-blade-eureka</name>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
</project>

Application类内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
package org.springblade.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class Application {

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

application.xml 配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
spring:
application:
name: EUREKA-HA
---
server:
port: 8001 # 指定该Eureka实例的端口
spring:
profiles: eurekap1
eureka:
instance:
hostname: eurekap1
client:
serviceUrl:
defaultZone: http://user:password123@eurekap2:8002/eureka,http://user:password123@eurekap3:8003/eureka
#server:
#enable-self-preservation: false # 设为false,关闭自我保护
#eviction-interval-timer-in-ms: 4000 # 清理间隔(单位毫秒,默认是60*1000)
security:
basic:
enabled: true # 开启基于HTTP basic的认证
user:
name: user # 配置登录的账号是user
password: password123 # 配置登录的密码是password123

---
server:
port: 8002 # 指定该Eureka实例的端口
spring:
profiles: eurekap2
eureka:
instance:
hostname: eurekap2
client:
serviceUrl:
defaultZone: http://user:password123@eurekap1:8001/eureka,http://user:password123@eurekap3:8003/eureka
#server:
#enable-self-preservation: false # 设为false,关闭自我保护
#eviction-interval-timer-in-ms: 4000 # 清理间隔(单位毫秒,默认是60*1000)
security:
basic:
enabled: true # 开启基于HTTP basic的认证
user:
name: user # 配置登录的账号是user
password: password123 # 配置登录的密码是password123

---
server:
port: 8003 # 指定该Eureka实例的端口
spring:
profiles: eurekap3
eureka:
instance:
hostname: eurekap3
client:
serviceUrl:
defaultZone: http://user:password123@eurekap1:8001/eureka,http://user:password123@eurekap2:8002/eureka
#server:
#enable-self-preservation: false # 设为false,关闭自我保护
#eviction-interval-timer-in-ms: 4000 # 清理间隔(单位毫秒,默认是60*1000)
security:
basic:
enabled: true # 开启基于HTTP basic的认证
user:
name: user # 配置登录的账号是user
password: password123 # 配置登录的密码是password123

编写start.bat 进行一键启动

1
2
3
java -jar -Dspring.profiles.active=eurekap1 spring-blade-eureka-1.0.jar
java -jar -Dspring.profiles.active=eurekap2 spring-blade-eureka-1.0.jar
java -jar -Dspring.profiles.active=eurekap3 spring-blade-eureka-1.0.jar