1.使用IDEA,Spring Initializr创建
2.填写项目资料
3.选择spring boot版本,插件选择Cloud Discovery→Eureka Server
4.选择保存地址
5.pom文件
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.test
eureka-server
0.0.1-SNAPSHOT
jar
eureka-server
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.3.RELEASE
UTF-8
UTF-8
1.8
Finchley.RELEASE
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
6.修改application.yml
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
spring:
application:
name: eurka-server
备注:在默认情况下erureka server也是一个eureka client
通过eureka.client.registerWithEureka:false和fetchRegistry:false来表明自己是一个eureka server
7.启动文件添加@EnableEurekaServer注解
package com.test.eurekaserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
8.去掉勾选
9.启动项目
备注:如果出现方法或类找不到,请clean
10.eurka-server是必须为了避免麻烦我们后台启动eurka-server
1.install 打成jar包
2.打开终端进入target文件夹
3.启动 java -jar eureka-server-0.0.1-SNAPSHOT.jar
结束运行:Ctrl+C
备注:如果端口被占用
1.ps -e | grep eureka
2.kill -9 1410(进程ID)
4.后台启动:nohup java -jar eureka-server-0.0.1-SNAPSHOT.jar /dev/null 2>&1 &
结束运行:ps -e | grep eureka kill -9 (进程ID)