Eureka服务端的安装
Eureka的两个组件
Eureka server: 提供服务注册服务
微服务节点通过配置启动后,会在 eurka server中进行注册 =》eureka server中的服务注册表会存储所有可用服务节点的信息,并可以在界面中看到。
Eureka Client :通过注册中心进行访问
一个java客户端,有一个内置的,使用轮询负载算法的负载均衡器,启动后会向Eureka server发送心跳(30秒一次),如果Eureka server在多个心跳周期中没有接收到节点的心跳。会把之节点从服务注册表中移除。
1.创建model
参考这个链接中的model,都有一样,直接复制过来。
http://hechunbo.com/index.php/archives/366.html
2.更改pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.hcb</groupId>
<artifactId>hcb_common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 用于图形监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 一般通用配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
3.配置文件
新建application.yml文件 ,注意defaultZone 不能少。
server:
port: 7001
eureka:
instance:
hostname: localhost
client:
#false 不向注册中心注册自己
register-with-eureka: false
#false表示自己就是注册中心,不需要检索服务
fetch-registry: false
#提供查询服务和注册服务的地址
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
4.新建启动类
com.hcb.springcloud.EurekaServer
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {
public static void main(String[] args) {
SpringApplication.run(EurekaServer.class,args);
}
}
5.启动运行
还不快抢沙发