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,直接上代码. 服务端代码: [ ...
随机推荐
- Solon 1.5.29 发布,轻量级 Java 基础开发框架
本次版本主要变化: 增加 captcha-solon-plugin 插件(提供滑块验证与选文字验证能力) 插件 sa-token-solon-plugin,升级 sa-token 为 1.26.0 插 ...
- React Native踩坑日记 —— tailwind-rn
项目背景 在项目的初始阶段,我们需要建立自己的design system,我们spike了一些方案,tailwind-rn就是其中一种,如果有用到或者即将用到tailwind-rn的,可以进来看一看, ...
- HDU2063 过山车(二分匹配)
过山车 HDU - 2063 RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做part ...
- ECSHOP产品内容页新增上传功能
第一步:在 admin\templates\goods_info.htm中 <span class="tab-back" id="article-tab" ...
- shell 基本语法介绍
一.介绍 shell 是属于弱类型语言,指的是在定义变量时不需要指定变量的类型,就如python也是弱类型语言.一般以: :.sh结尾的文件 :文件第一行固定为:#!/bin/bash,表示指定以sh ...
- sonar扫面代码总体流程
- Typescript, ES6
* typescript 中文文档 https://www.tslang.cn/docs/home.html * ECMAScript 6 入门 http://es6.ruanyifeng.com/# ...
- nginx负载轮询
下面是一个可以使用nginx负载轮询,如果有一台服务器连接不通,返404,500,502,503,504,会自动切换到下一台服务器 upstream www { server 111.111.111. ...
- win10蓝牙鼠标无法连接,需pin码
从控制面板进到"设备和打印机",点击"添加设备" 鼠标切换到匹配模式,就可以看到自己的鼠标了,点"下一步" 出现了一样的画面,是的,不用输P ...
- P2179-[NOI2012]骑行川藏【导数,二分】
正题 题目链接:https://www.luogu.com.cn/problem/P2179 题目大意 给出\(E\)和\(n\)个\(s_i,k_i,u_i\)求一个序列\(v_i\)满足 \[\s ...