备注:源代码已经全部上传到github,有错误地方请指正,谢谢!地址:https://github.com/hcmony/springcloud
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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.hcmony</groupId>
<artifactId>springcloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>eureka</artifactId>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2,配置文件
server.port=8888
spring.application.name=eureka-server
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone= http://${eureka.instance.hostname}:${server.port}/eureka/
eureka.instance.preferIpAddress=true
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
#1、在生产上可以开自注册,部署两个server
#2、在本机器上测试的时候,可以把比值调低,比如0.49
#3、或者简单粗暴把自我保护模式关闭
eureka.server.enable-self-preservation=false
#暴露actuator的所有端点
management.endpoints.web.exposure.include=*
#health endpoint是否必须显示全部细节。默认情况下, /actuator/health 是公开的,并且不显示细节
management.endpoint.health.show-details=always
3,java代码
package com.hcmony;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}