eureka做服务注册与发现
2018-02-24 19:20
337 查看
关于eureka的介绍什么的就不写了哈,网上有很多。。
pom文件:
依赖引入好了之后就开始application.properties配置了
配置好了之后,在主入口中
打上@EnableEurekaServer这一注解就可以了
然后访问localhost:8666
就会弹出身份验证
输入用户名密码登录上去就进入eureka页面了
然后配置
服务就成功注册上了
首先搭建eureka服务端
可以通过Spring Initializr创建pom文件:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> <relativePath/> </parent> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <!--引入spring security做登录验证--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
依赖引入好了之后就开始application.properties配置了
server.port=8666 spring.application.name=eureka-server #服务注册中心实例的主机名 eureka.instance.hostname=127.0.0.1 #留存的服务示例低于多少比例进入保护模式 eureka.server.renewal-percent-threshold=0.5 #是否开启保护模式 eureka.server.enable-self-preservation=true #是否向服务注册中心注册自己 eureka.client.register-with-eureka=false #是否启用获取服务注册信息,因为这是一个单点的Eureka Server,不需要同步其他的Eureka Server节点的数据,故而设为false eureka.client.fetch-registry=false #注册和查询都需要依赖该地址,多个以逗号分隔 #这里有登录验证,把用户名密码写在这地址上,不然client连接的时候会报com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server eureka.client.serviceUrl.defaultZone=http://admin:123456@127.0.0.1:8666/eureka/ #这里使用spring security对注册中心做一个用户名密码登录 #先做个基础的,后面再来完善安全性问题 security.basic.enabled=true security.user.name=admin security.user.password=123456
配置好了之后,在主入口中
@SpringBootApplication @EnableEurekaServer public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } }
打上@EnableEurekaServer这一注解就可以了
然后访问localhost:8666
就会弹出身份验证
输入用户名密码登录上去就进入eureka页面了
然后注册一个client
新建一个project,首先还是需要添加依赖包<!--如果要健康检查,就需要这个依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency>
然后配置
server.port=8081 spring.application.name=user-service eureka.client.service-url.defaultZone=http://admin:123456@127.0.0.1:8666/eureka/ eureka.instance.lease-renewal-interval-in-seconds=5 eureka.instance.lease-expiration-duration-in-seconds=10 eureka.client.healthcheck.enable=true
服务就成功注册上了
相关文章推荐
- Spring Cloud学习---服务注册与发现(Eureka)
- SpringCloud 学习 | 第一篇: 高可用的服务注册与发现(Eureka)
- SOA之路 -- 为什么Eureka比ZooKeeper更适合做服务发现与注册服务
- 第一篇: 服务的注册与发现(Eureka)
- SpringCloud 入门 | 服务的注册与发现之Eureka
- springcloud eureka服务注册与发现
- springcloud(1)_ 史上最简单的 SpringCloud 教程 | 第一篇: 服务的注册与发现(Eureka)
- SpringCloud——Eureka服务注册和发现
- Spring Cloud 入门教程 - Eureka服务注册与发现
- SpringCloud——服务注册与发现Eureka以及注册源码解析
- SpringCloud——Eureka服务注册和发现
- Spring Cloud之路:(二) 服务的注册与发现(Eureka)
- Spring Cloud学习系列第一章:Eureka之服务注册与发现
- 服务注册发现Eureka之三:Spring Cloud Ribbon实现客户端负载均衡(客户端负载均衡Ribbon之三:使用Ribbon实现客户端的均衡负载)
- Spring Cloud Eureka 实现服务注册与发现
- Spring Cloud 学习笔记-Eureka 服务注册与发现
- SpringCloud服务注册与发现(Eureka 注册中心)
- 服务注册发现eureka
- SOA之路 -- 为什么Eureka比ZooKeeper更适合做服务发现与注册服务
- springcloud(第三篇)springcloud eureka 服务注册与发现