使用3个Eureka服务搭建集群

Eureka1:端口为7001;

Eureka2:端口为7002;

Eureka3:端口为7003;

它们之间是两两互相注册的关系

一、Eureka的集群搭建

1、再次创建2个Eureka工程

工程名:microservicecloud-eureka-7002

工程名:microservicecloud-eureka-7003

2、pom.xml文件

<dependencies>
<!--eureka-server服务端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>

3、域名映射

找到 "C:\Windows\System32\drivers\etc\hosts" 文件,并在hosts文件中增加如下内容:

127.0.0.1 eureka7001.com
127.0.0.1 eureka7002.com
127.0.0.1 eureka7003.com

4、配置文件的修改

(1)工程 microservicecloud-eureka-7001 的 application.yml文件做如下修改:

server:
port: 7001
eureka:
instance:
hostname: eureka7001.com #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己。Eureka不响自己注册
fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
service-url:
defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/

(2)工程 microservicecloud-eureka-7002 的 application.yml文件做如下修改:

server:
port: 7002
eureka:
instance:
hostname: eureka7002.com #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己。Eureka不响自己注册
fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
service-url:
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7003.com:7003/eureka/

(3)工程 microservicecloud-eureka-7003 的 application.yml文件做如下修改:

server:
port: 7003
eureka:
instance:
hostname: eureka7003.com #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己。Eureka不响自己注册
fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
service-url:
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/

二、微服务注册到Eureka集群中

(1)创建一个微服务

微服务的启动类上增加 @EnableEurekaClient 注解;

@SpringBootApplication
@EnableEurekaClient //本服务启动后自动注册到eureka中
@EnableDiscoveryClient //服务的发现, 暴露出来
public class DeptProvider8001_App
{
public static void main(String[] args)
{
SpringApplication.run(DeptProvider8001_App.class, args);
}
}

(2)微服务注册到Eureka集群的所有节点上

微服务yaml文件如下所示:

server:
port: 8001 mybatis:
config-location: classpath:mybatis/mybatis.cfg.xml # mybatis配置文件所在路径
type-aliases-package: com.yufeng.springcloud.entities # 所有Entity别名类所在包
mapper-locations:
- classpath:mybatis/mapper/**/*.xml # mapper映射文件 spring:
application:
name: microservicecloud-dept
datasource:
type: com.alibaba.druid.pool.DruidDataSource # 当前数据源操作类型
driver-class-name: org.gjt.mm.mysql.Driver # mysql驱动包
url: jdbc:mysql://192.168.172.20:3306/cloudDB01 # 数据库名称
username: root
password: root
dbcp2:
min-idle: 5 # 数据库连接池的最小维持连接数
initial-size: 5 # 初始化连接数
max-total: 5 # 最大连接数
max-wait-millis: 200 # 等待连接获取的最大超时时间 eureka:
client: # 客户端注册进eureka内
service-url:
defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
instance:
instance-id: microservicecloud-provider-dept-8001
prefer-ip-address: true # 访问路径可以显示IP info:
app.name: yufeng-microservicecloud
company.name: www.yufeng.com
build.artifactId: $project.artifactId$
build.version: $project.version$

  

Spring Cloud Eureka的集群配置(六)的更多相关文章

  1. Spring Cloud Eureka Server集群Demo级搭建

    将上篇随笔Spring Cloud Eureka服务Demo级搭建进行改造,改造成一个在本机的伪集群 1.修改hosts文件(windows10 hosts文件位置:C:\Windows\System ...

  2. Spring Cloud Config实现集群配置中心

    Spring Cloud Config为分布式系统提供了配置服务器和配置客户端,可以管理集群中的配置文件.使用Git.SVN等版本管理系统存放配置文件,配置服务器会到版本管理系统获取配置,集群中的配置 ...

  3. Spring Cloud Alibaba | Nacos集群部署

    目录 Spring Cloud Alibaba | Nacos集群部署 1. Nacos支持三种部署模式 2. 集群模式下部署Nacos 2.1 架构图 2.2 下载源码或者安装包 2.3 配置集群配 ...

  4. Eureka单机&集群配置

    目录 Eureka是什么 自我保护机制 版本选择 服务搭建 创建项目 导入GAV坐标 application启动类添加注解 配置yml 启动项目 集群配置 修改上面的yml 打jar包到另外一台电脑O ...

  5. Spring Cloud :断路器集群监控(Turbine)

    一. 简介      上一篇文章我们已经实现了对单个服务实例的监控,当然在实际应用中,单个实例的监控数据没有多大的价值,我们更需要的是一个集群系统的监控信息,这时我们就需要引入Turbine.Turb ...

  6. Spring Cloud之Swagger集群搭建

    在微服务中,Swagger是每个服务 比如会员服务,订单服务,支付服务 进行继承. 如何将整个微服务中的Swagger进行合成,同一台服务器上. 使用Zuul+Swagger实现管理整个微服务API文 ...

  7. Redis客户端之Spring整合Jedis,ShardedJedisPool集群配置

    Jedis设计 Jedis作为推荐的java语言redis客户端,其抽象封装为三部分: 对象池设计:Pool,JedisPool,GenericObjectPool,BasePoolableObjec ...

  8. (4) Spring中定时任务Quartz集群配置学习

    原 来配置的Quartz是通过spring配置文件生效的,发现在非集群式的服务器上运行良好,但是将工程部署到水平集群服务器上去后改定时功能不能正常运 行,没有任何错误日志,于是从jar包.JDK版本. ...

  9. Spring Cloud Eureka整合使用和配置

    遵循SpringBoot三板斧 服务端 第一步加依赖 <dependency> <groupId>org.springframework.cloud</groupId&g ...

随机推荐

  1. java使用jxl,poi解析excel文件

    public interface JavaExcel { /** * 使用jxl写excel文件 */ public void writeJxlExcel(); /** * 使用jxl读excel文件 ...

  2. Intellij IDEA快捷键大全汇总(2019更新)

    Intellij IDEA快捷键大全汇总(2019) Ctrl+Shift + Enter,语句完成“!”,否定完成,输入表达式时按 “!”键 Alt+回车 导入包,自动修正 Ctrl+N   查找类 ...

  3. IIS日志分析工具-Log Parser

    下载地址:https://www.microsoft.com/en-us/download/details.aspx?id=24659 参考链接: https://www.cnblogs.com/fu ...

  4. RF:win10跑用例过程中有中文日志会显示非中文

    问题:RobotFramework在win10跑用例过程中有中文日志会显示非中文,如截图: 解决:  C:\Python27\Lib\site-packages\robot\utils\unic.py ...

  5. Linux查看和修改时间、日期

    1.查看时间.日期 # date Fri Jan 11 14:04:10 CST 2019 2.修改时间 语法:date -s "时:分:秒" # date -s "17 ...

  6. thinkphp5.1 判断是不是post提交

    if(Request::isPost()){ }else{ } 这样就对了

  7. mysql 定时计划任务 wish 按照id分组定时循环启动

    SELECT count(*) FROM wish_sellers_in;UPDATE  wish_sellers_in  SET act_status =0 WHERE  id >=1 AND ...

  8. 吴裕雄 python 机器学习——线性回归模型

    import numpy as np from sklearn import datasets,linear_model from sklearn.model_selection import tra ...

  9. rest_framework_extensions实现缓存

    1.安装包 pip install drf-extensions pip install django-redis pip install django-redis-cache 2.配置redis # ...

  10. tensorflow,model,object_detection,训练loss先下降后递增,到几百万,解决tensorflow,model,object,detection,loss,incease

    现象:训练loss一开始下降一部分,跌代到若干次(具体多少和你的learning rate大小有关,大就迭代小就发生,小就需要多几次迭代) 日志如下(下面的日志来源于网络,我自己的日志已经clear掉 ...