Eureka服务的简单搭建
2017-12-02 本文已影响0人
MC丶LEE
1.为什么使用Eureka集群?
还是借用这一张图来说明吧:
image在这个图中,展示的是eureka集群的工作流程,而之所以进行eureka集群的搭建,在于在我们平时的生产环境中,很难保证单节点的eureka服务能提供百分百不间断的服务,如果eureka无响应了,整个项目应用都会出现问题,因此要保证eureka随时都能提供服务的情况下,最好的方式就是采用eureka的集群模式,也就是搭建eureka的高可用,在eureka的集群模式下,多个eureka server之间可以同步注册服务,因此,在一个eureka宕掉的情况下,仍然可以提供服务注册和服务发现的能力,从而达到注册中心的高可用。
2.Eureka需要的Jar包
<dependencies>
<!--eureka服务端的包-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--eureka服务端认证需要的包-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<!--springboot的父类-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<!--springcloud的包-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
3.Eureka的配置
##Eureka服务端安全管理
security:
basic:
enabled: true
user:
name: user
password: password
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
##健康检查
healthcheck:
enable: true
##单一Eureka服务不进行注册配置
registerWithEureka: false
fetchRegistry: false
##进行注册的路径因为进行了安全管理所以需要账号密码认证
serviceUrl:
defaultZone: http://user:password@localhost:8761/eureka/
3.Eureka的启动类
//只需在springboot启动类加@EnableEurekaServer
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}