7、Hyperf 3 微服务系列 - Consul 服务注册与发现 - Rocky Linux 9.1 安装 Consul
hi,我是温新,一名 PHPer
Hyperf 3 微服务代码已上传至 Github:https://github.com/ziruchu/hyperf3-microservice-code
学习目标:了解 consul 并把它跑起来
什么是 Consul
Consul 是微服务架构中,解决服务发现、配置中心的分布式中间件。
安装 Consul
系统:Rocky Linux 9.1
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo dnf -y install consul
查看版本
consul -v
Consul v1.15.1
Revision 7c04b6a0
Build Date 2023-03-07T20:35:33Z
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)
启动 Consul
创建数据存储目录
mkdir -p /usr/local/software/consul/data
启动服务
consul agent -client=0.0.0.0 -data-dir=/usr/local/software/consul/data/ -ui -dev
访问服务
http://192.168.31.90:8500
Consul 相关命令
启动参数说明
-dev
:表示开发环境模式运行;
-server
:以服务端身份启动(注册中心);
-client
:指定客户端访问的 ip,0.0.0.0 表示不限制客户端 IP;
-ui
:开启 web 界面访问;
-bootstrap-expect=3
:表示 server 集群最低节点数为 3,低于该值工作不正常;
-data-dir
:表示指定数据的存储目录(该目录必须先创建);
-node
:表示节点在 web ui 中显示的名称。
查看集群节点
consul members
重新加载配置文件
consul reload
优雅的关闭节点
consul leave
查询所有注册服务
consul catalog services
本篇文章学习了 Consul 的安装及相关的参数和命令。
我是温新,本篇文章结束。
请登录后再评论