SpringCloud服务的注册发现--------consul实现服务与发现

1,consul也可以替代Eureka实现注册和发现的功能,即注册中心。

之前在linux环境通过consul + upsync + nginx 实现nginx 的动态负载均衡

https://www.cnblogs.com/pickKnow/p/11227804.html

2,consul 实现注册中心

1,服务器端搭建

Consul 整合SpringCloud 学习网站:https://springcloud.cc/spring-cloud-consul.html

Consul下载地址https://www.consul.io/downloads.html

官方下载地址下载window版,解压得到一个可执行文件。
      设置环境变量,让我们直接在cmd里可直接使用consul使命。在path后面添加consul所在目录例如D:\soft\consul_1.1.0_windows_amd64

启动consul命

consul agent -dev -ui -node=cy

-dev开发服务器模式启动,-node结点名为cy,-ui可以用界面访问,默认能访问。

测试访问地址:http://localhost:8500

SpringCloud服务的注册发现--------consul实现服务与发现

3,配置,只需配置要注册服务的配置文件:

member:

server:
port: 8000
spring:
application:
name: consul-memeber
####consul注册中心地址
cloud:
consul:
host: localhost
port: 8500
discovery:
hostname: 127.0.0.1

order:

server:
port: 800
spring:
application:
name: consul-order
####consul注册中心地址
cloud:
consul:
host: localhost
port: 8500
discovery:
hostname: 127.0.0.1
上一篇:spark MySQL jar 包


下一篇:SpringCloud服务的注册发现--------Eureka