只是为了整理代码 (1) pom.xml
<?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>TDGiscloud</artifactId> <groupId>com.dzjy</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>tdcloud-server</artifactId> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>(2) 配置
server: port: 8761 # Redis数据库索引(默认为0) eureka: instance: hostname: eureka-server prefer-ip-address: true client: registerWithEureka: false fetchRegistry: false service-url: defaultZone: http://localhost:8761/eureka/ spring: application: name: tdcloudserver(3) Application
@EnableEurekaServer @SpringBootApplication public class TDGISEurakaServer { public static void main(String[] args) { SpringApplication.run(TDGISEurakaServer.class, args); } }(4) 高可用Eureka Server 集群 处理体量比较大的微服务集群 4.1 需要修改application.yml 配置,在配置中采用profile的格式
--- server: port: 8761 # Redis数据库索引(默认为0) eureka: instance: hostname:peer1 client: service-url: defaultZone: http://peer1:8761/eureka/ spring: profiles:peer1 ---- server: port: 8762 eureka: instance: hostname: peer2 client: service-url: defaultZone: http://peer2:8762/eureka/ spring: profiles:peer24.2 修改hosts 文件 添加 127.0.0.1 peer1 127.0.0.1 peer2 4.3 启动jar 配置 spring.profiles.active=peer1 spring.profiles.active=peer2