consul集群模式
- 模式一:单机client模式
除了consul服务集群,每个微服务机器上运行以client模式运行一个consule agent, 每个微服务都注册到本地的consul agent client上
- 模式二:client集群模式
除了consul服务集群,创建有限的几个consul client, 通过配置反向代理来将请求转发给consul client集群来获取可用服务
单机client模式配置dapr服务发现
安装consul
-
安装consul包
yum install -y yum-utils yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo yum -y install consul
-
检查consul是否安装成功
consul version
配置consul server集群
-
假设consul集群的节点为3,cluster ip为192.168.52.2,在node1上启动consul agent
nohup consul agent -server -bootstrap-expect 3 -data-dir /tmp/consul -ui -client 0.0.0.0 -bind 192.168.52.2 -join 192.168.52.2 > /var/log/consul.log 2>&1 &
-
在node2(192.168.52.3)上启动consul agent, cluster IP为192.168.52.2
nohup consul agent -server -data-dir /tmp/consul -ui -client 0.0.0.0 -bind 192.168.52.3 -join 192.168.52.2 > /var/log/consul.log 2>&1 &
-
在node3(192.168.52.4)上启动consul agent, cluster IP为192.168.52.2
nohup consul agent -server -data-dir /tmp/consul -ui -client 0.0.0.0 -bind 192.168.52.4 -join 192.168.52.2 > /var/log/consul.log 2>&1 &
-
确保node1,node2和node3开启了8300,8301,8302,8500和8600端口的访问权限,如果不确定可以尝试关闭防火墙
systemctl stop firewalld systemctl disable firewalld
dapr客户端配置
假设dapr客户端所在服务器的IP地址为: 192.168.52.5
-
修改客户端的dapr的config.yaml添加
nameResolution
部分apiVersion: dapr.io/v1alpha1 kind: Configuration metadata: name: appconfig spec: nameResolution: component: "consul" configuration: selfRegister: false
-
以client方式启动consul
nohup consul agent -data-dir /tmp/consul -ui -client 0.0.0.0 -bind 192.168.52.5 -join 192.168.52.2 > /var/log/consul.log 2>&1 &
dapr服务端配置
假设dapr客户端所在服务器的IP地址为: 192.168.52.6
-
修改服务端的dapr的config.yaml添加
nameResolution
部分apiVersion: dapr.io/v1alpha1 kind: Configuration metadata: name: appconfig spec: nameResolution: component: "consul" configuration: selfRegister: true
-
以client方式启动consul
nohup consul agent -data-dir /tmp/consul -ui -client 0.0.0.0 -bind 192.168.52.6 -join 192.168.52.2 > /var/log/consul.log 2>&1 &