Eureka Server单机版搭建

单机环境搭建 
1、创建xc-govern-center工程: 包结构:com.xuecheng.govern.center
2、添加依赖
在父工程添加:(有了则不用重复添加)

在Eureka Server工程添加:
<dependency>     <groupId>org.springframework.cloud</groupId>     <artifactId>spring‐cloud‐dependencies</artifactId>     <version>Dalston.SR5</version>     <type>pom</type>     <scope>import</scope> </dependency>  

3、启动类

4、@EnableEurekaServer 需要在启动类上用@EnableEurekaServer标识此服务为Eureka服务  
5、从其它服务拷贝application.yml和logback-spring.xml。 application.yml的配置内容如下:

registerWithEureka:被其它服务调用时需向Eureka注册
fetchRegistry:需要从Eureka中查找要调用的目标服务时需要设置为true
<dependencies>    
<!‐‐ 导入Eureka服务的依赖 ‐‐>     <dependency>         <groupId>org.springframework.cloud</groupId>         <artifactId>spring‐cloud‐starter‐eureka‐server</artifactId>     </dependency> </dependencies>  
@EnableEurekaServer//标识这是一个Eureka服务 @SpringBootApplication public class GovernCenterApplication {     public static void main(String[] args) {         SpringApplication.run(GovernCenterApplication.class, args);     } }  
server:   port: 50101 #服务端口   spring:   application:     name: xc‐govern‐center #指定服务名   eureka:   client:     registerWithEureka: false #服务注册,是否将自己注册到Eureka服务中     fetchRegistry: false #服务发现,是否从Eureka中获取注册信息     serviceUrl: #Eureka客户端与Eureka服务端的交互地址,高可用状态配置对方的地址,单机状态配置自己(如果 不配置则默认本机8761端口)       defaultZone: http://localhost:50101/eureka/   server:     enable‐self‐preservation: false #是否开启自我保护模式     eviction‐interval‐timer‐in‐ms: 60000 #服务注册表清理间隔(单位毫秒,默认是60*1000)  
serviceUrl.defaultZone 配置上报Eureka服务地址
  当前服务是Eureka:高可用状态配置对方的地址,单机状态配置自己

当前服务非Eureka:将Eureka服务地址全部配置,中间以逗号分隔 enable-self-preservation:自保护设置,下边有介绍。
eviction-interval-timer-in-ms:清理失效结点的间隔,在这个时间段内如果没有收到该结点的上报则将结点从服务 列表中剔除。
  5、启动Eureka Server
启动Eureka Server,浏览50101端口。

说明:

Eureka Server有一种自多保护模式,当微服务不再向Eureka Server上报状态,Eureka Server会从服务列表将此 服务删除,如果出现网络异常情况(微服务正常),此时Eureka server进入自保护模式,不再将微服务从服务列 表删除。
在开发阶段建议关闭自保护模式。




猜你喜欢

转载自blog.51cto.com/14500648/2430157