大家好,又见面了,我是你们的朋友全栈君。
上一篇讲了下如何搭建Eureka服务注册中心,那个是单机版的,本篇介绍下集群版搭建。
参考cloud-eureka-server7001新建模块cloud-eureka-server7002。
路径:C:\Windows\System32\drivers\etc\hosts,在最后面追加以下内容:
# spring cloud
127.0.0.1 eureka7001.com
127.0.0.1 eureka7002.comserver:
port: 7001
eureka:
instance:
hostname: eureka7001.com #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己。
fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
service-url:
defaultZone: http://eureka7002.com:7002/eureka/server:
port: 7002
eureka:
instance:
hostname: eureka7002.com #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己。
fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
service-url:
defaultZone: http://eureka7001.com:7001/eureka/server:
port: 8001
spring:
application:
name: cloud-payment-service
datasource:
type: com.alibaba.druid.pool.DruidDataSource # 当前数据源操作类型
driver-class-name: org.gjt.mm.mysql.Driver # mysql驱动包
url: jdbc:mysql://localhost:3306/db_payment?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: root123
druid:
test-while-idle: true
validation-query: SELECT 1
mybatis:
mapperLocations: classpath:mapper/*.xml
type-aliases-package: com.sgtech.springcloud.entity # 所有Entity别名类所在包
eureka:
client:
#表示是否将自己注册进EurekaServer默认为true。
register-with-eureka: true
#是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
fetchRegistry: true
service-url:
#单机版
# defaultZone: http://localhost:7001/eureka
# 集群版
defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
instance:
instance-id: payment8001参考模块:cloud-payment8001新建cloud-payment8002。
server:
port: 8002
spring:
application:
name: cloud-payment-service
datasource:
type: com.alibaba.druid.pool.DruidDataSource # 当前数据源操作类型
driver-class-name: org.gjt.mm.mysql.Driver # mysql驱动包
url: jdbc:mysql://localhost:3306/db_payment?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: root123
druid:
test-while-idle: true
validation-query: SELECT 1
mybatis:
mapperLocations: classpath:mapper/*.xml
type-aliases-package: com.sgtech.springcloud.entity # 所有Entity别名类所在包
eureka:
client:
#表示是否将自己注册进EurekaServer默认为true。
register-with-eureka: true
#是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
fetchRegistry: true
service-url:
#单机版
# defaultZone: http://localhost:7001/eureka
# 集群版
defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eurekahttp://eureka7001.com:7001/,http://eureka7002.com:7002/会发现多了一个注册中心副本和2个实例
http://localhost:8001/payment/get/22,http://localhost:8002/payment/get/22
https://gitee.com/indexman/cloudstudy
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/132985.html原文链接:https://javaforall.cn