Consul是一种开源的服务发现和配置管理工具,可以作为分布式系统的注册中心。它提供了一个中心化的服务注册和发现机制,使得服务之间的通信更加容易和可靠。Consul可以自动检测服务的状态和健康情况,并将其信息提供给其他服务使用。同时,它也提供了一些高级功能,例如分布式锁、数据中心间的服务发现和故障转移等。通过使用Consul注册中心,可以大大简化分布式系统的开发和管理工作。
官网地址: https://www.consul.io
# sudo mv ~/Downloads/consul /usr/local/bin/
# consul version
Consul v1.8.0
# sudo mkdir /etc/consul.d
# sudo touch /etc/consul.d/consul.hcl
# /etc/consul.d/consul.hcl
datacenter = "mydc"
data_dir = "/opt/consul"
ui = true
# sudo consul agent -config-dir=/etc/consul.d
consul version
# consul.hcl
datacenter = "mydc"
data_dir = "D:\\consul"
ui = true
consul agent -config-dir="D:\\consul.d"
通过以下地址可以访问Consul的首页:http://localhost:8500
<!--consul 客户端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
</dependency>
server:
port: 8081
spring:
datasource:
url: jdbc:mysql://localhost:3306/cloud_user?useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
application:
name: userservice
cloud:
consul:
host: localhost # consul 服务端的 ip
port: 8500 # consul 服务端的端口 默认8500
discovery:
service-name: ${spring.application.name} # 当前应用注册到consul的名称
prefer-ip-address: true # 注册ip
heartbeat:
enabled: true
mybatis:
type-aliases-package: cn.itcast.user.pojo
configuration:
map-underscore-to-camel-case: true
logging:
level:
cn.itcast: debug
pattern:
dateformat: MM-dd HH:mm:ss:SSS
<!--consul 客户端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
</dependency>
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/cloud_order?useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
application:
name: orderservice
cloud:
consul:
host: localhost # consul 服务端的 ip
port: 8500 # consul 服务端的端口 默认8500
discovery:
service-name: ${spring.application.name} # 当前应用注册到consul的名称
prefer-ip-address: true # 注册ip
heartbeat:
enabled: true
mybatis:
type-aliases-package: cn.itcast.user.pojo
configuration:
map-underscore-to-camel-case: true
logging:
level:
cn.itcast: debug
pattern:
dateformat: MM-dd HH:mm:ss:SSS
feign:
client:
config:
default: # default?????
loggerLevel: FULL # ?????BASIC????????????
httpclient:
enabled: true # ??feign?HttpClient???
max-connections: 200 # ??????
max-connections-per-route: 50 # ??????????
亲爱的读者,
我在这篇文章中投入了大量的心血和时间,希望为您提供有价值的内容。这篇文章包含了深入的研究和个人经验,我相信这些信息对您非常有帮助。
如果您觉得这篇文章对您有所帮助,我诚恳地请求您考虑赞赏1元钱的支持。这个金额不会对您的财务状况造成负担,但它会对我继续创作高质量的内容产生积极的影响。
我之所以写这篇文章,是因为我热爱分享有用的知识和见解。您的支持将帮助我继续这个使命,也鼓励我花更多的时间和精力创作更多有价值的内容。