eureka服务端和客户端的简单搭建
本篇博客简单记录一下,eureka 服务端和 客户端的简单搭建。
目标:
1、完成单机 eureka server 和 eureka client 的搭建。
2、完成eureka server 的添加安全认证,即不能别人知道我们的eureka server地址就可以注册上去。
3、测试环境下,关闭eureka的自我保护
一、eureka server 端的搭建
1、引入依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
注意:
1、由于服务端需要保护,因此还引入了security依赖。
2、编写配置文件
spring:
application:
name: eureka-server
server:
port: 8761
tomcat:
uri-encoding: utf-8
eureka:
client:
register-with-eureka: false # 由于eureka即可以作为服务端也可以作为客户端,此处是作为服务器段,因此这个参数需要设置成false: 即不作为一个客户端注册到服务注册中心
fetch-registry: false # true:表示作为一个客户端中eureka server 服务端获取服务注册信息,此处作为一个服务端因此需要设置成 false
service-url:
defaultZone : http://${security.user.name}:${security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/
instance:
hostname: localhost
server:
# 此处表示关闭 eureka 的自我保护
enable-self-preservation: false
# 清理无效节点的时间间隔,默认是60s,此处修改成10s
eviction-interval-timer-in-ms: 10000
security:
basic:
enabled: true # 开启basic认证
user:
name: root # 用户名
password: admin # 密码
注意:
1、默认情况下eureka即可以做为服务端,也可以做为客户端,此处作为服务端,因此需要将 register-with-eureka的值改成false,即不注册到eureka server上。
2、fetch-registry: 服务端这个值 需要改成 false, 即不去检索服务。
3、security 开头的配置是因为引入了spring security保护server端,因此 需要注意 service-url 中的 defaultZone 的值的写法 : http://用户名:密码@主机:端口/eureka/
4、enable-self-preservation的值设置成 false 表示 关闭eureka的自我保护。
客户端需要修改下方2个参数的值,正式环境不建议修改。
# 客户端与服务器断心跳的时间间隔,默认为 30秒
lease-renewal-interval-in-seconds: 3
# 租约到期时间,此值不可过小,开发环境小点没有事,默认为 90秒
lease-expiration-duration-in-seconds: 9
3、编写启动类
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
注意:
1、 eureka server 的服务端上需要加上 @EnableEurekaServer 注解,表示作为服务端启动。
二、eureka client 端的搭建
1、引入依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
2、编写配置文件
server:
port: 8762
eureka:
client:
service-url:
defaultZone : http://${security.user.name}:${security.user.password}@localhost:8761/eureka/ #连接到服务注册中心的地址,如果服务注册中心开启了权限需要设置 http://username:password@ip:port/eureka/格式
instance:
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${server.port}
# 客户端与服务器断心跳的时间间隔,默认为 30秒
lease-renewal-interval-in-seconds: 3
# 租约到期时间,此值不可过小,开发环境小点没有事,默认为 90秒
lease-expiration-duration-in-seconds: 9
security:
user:
name: root
password: admin
spring:
application:
name: eureka-client
info:
app:
name: "eureka-client"
description: "eureka-client程序"
version: "0.0.1"
注意:
1、注意一下注册到 eureka server 上 url 的编写格式。
2、spring.application.name 表示注册到eureka服务上的名字,建议小写。
3、编写启动类
@SpringBootApplication
@EnableDiscoveryClient
public class EurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication.class, args);
}
}
注意:
1、eureka client需要加上 @EnableDiscoveryClient 注解,表示这个一个客户端。
三、运行界面
1、浏览器上输入 : http://localhost:8761 回车后,填写用户名(root)/密码(admin) 登录即可看到这个页面
四、完整代码地址:
https://gitee.com/huan1993/spring-cloud-parent.git 里面 eureka-server和eureka-client即为本篇博客的代码。
eureka服务端和客户端的简单搭建的更多相关文章
- SpringCloud02 Eureka知识点、Eureka服务端和客户端的创建、Eureka服务端集群、Eureka客户端向集群的Eureka服务端注册
1 Eureka知识点 按照功能划分: Eureka由Eureka服务端和Eureka客户端组成 按照角色划分: Eureka由Eureka Server.Service Provider.Servi ...
- thrift服务端到客户端开发简单示例
(1)首先我们在服务器端写个helloworld.thrift文件,如下所示: service HelloWorld{ string ping(1: string name), string getp ...
- oauth2.0服务端与客户端搭建
oauth2.0服务端与客户端搭建 - 推酷 今天搭建了oauth2.0服务端与客户端.把搭建的过程记录一下.具体实现的功能是:client.ruanwenwu.cn的用户能够通过 server.ru ...
- C# 编写WCF简单的服务端与客户端
http://www.wxzzz.com/1860.html Windows Communication Foundation(WCF)是由微软开发的一系列支持数据通信的应用程序框架,可以翻译为Win ...
- 三、eureka服务端获取服务列表
所有文章 https://www.cnblogs.com/lay2017/p/11908715.html 正文 eureka服务端维护了一个服务信息的列表,服务端节点之间相互复制服务信息.而作为eur ...
- Spring Eureka的使用入门--服务端与客户端
接上篇: Eureka作为注册中心,连接服务端与客户端: 服务端: 依赖包: apply plugin: 'org.springframework.boot' apply plugin: 'io.sp ...
- spring cloud eureka 服务端开启密码认证后,客户端无法接入问题
Eureka服务端开启密码的认证比较简单 在pom文件中加入: <dependency> <groupId>org.springframework.boot</group ...
- SVN服务端和客户端的安装与搭建
版权声明:本文为博主原创文章,转载请注明原文出处. https://blog.csdn.net/zzfenglin/article/details/50931462 SVN简介 SVN全名Subver ...
- Unity使用C#实现简单Scoket连接及服务端与客户端通讯
简介: 网络编程是个很有意思的事情,偶然翻出来很久之前刚开始看Socket的时候写的一个实例,贴出来吧 Unity中实现简单的Socket连接,c#中提供了丰富的API,直接上代码. 服务端代码: [ ...
随机推荐
- openswan专栏序言
openswan专栏序言 "一杯茶,一包烟,一个bug解一天!!!". 2020年春季,正值新冠病毒在全球肆虐之际,美国的疫情已经相当的严峻,每天仍以3万速度狂奔.而国内的疫情 ...
- go build 与go install
相同点都能生成可执行文件 不同点go build 不能生成包文件, go install 可以生成包文件go build 生成可执行文件在当前目录下, go install 生成可执行文件在bin目录 ...
- vue-cli3 创建多页面应用项目
1.创建vue项目 cmd命令执行 vue create ruc-continuing 创建vue项目,项目名称:ruc-continuing 选择一个 preset(预置项),或自定义: 选择自 ...
- UVA 11853 Paintball(几何数学+DFS)
https://vjudge.net/problem/UVA-11853 根据题意描述,相当于在一个正方形中有若干个圆形障碍物,问是否能从左边界走到右边界.判断是否有解需要一点创造性的思维:不妨把正方 ...
- 为什么不推荐Python初学者直接看项目源码
无论是有没有其他语言的经验,入门Python都很简单.Python拥有简单直观的语法,方便的语法糖,以及丰富的第三方库.只要一个基础的Python教程,大家基本上都能无障碍的入门.在入门之后,很多人对 ...
- phpmyadmin 设置密码
例如 xampp 安装路径为 /opt/lampp/, copy 一份默认的配置 cp /opt/lampp/phpmyadmin/libraries/config.default.php /opt/ ...
- jmeter长时间压测
如何进行24h小时的压测? 长时间压测注意事项 生成报告文件过大 https://www.cnblogs.com/SunshineKimi/p/12298668.html
- 第一次接触linux系统的你,必须要知道的概念
linux系统一切皆为文件 linux系统一个多用户系统 没有消息就是好消息 linux系统目录结构 Linux文件系统采用带链接的树形目录结构,即只有一个根目录(通常用"/"表示 ...
- css Table 表格宽度失效解决方案
使用div包裹内容进行支撑 <table cellspacing="0"> <caption>89 HOLLAND ROAD SINGAPORE 27575 ...
- P3507-[POI2010]GRA-The Minima Game【dp,博弈论】
正题 题目链接:https://www.luogu.com.cn/problem/P3507 题目大意 \(n\)个数,没人轮流取若干个并获得取走的数中最小数的权值,两人的目标都是自己的权值\(-\) ...