网站开发如何避开法律,广告公司网站官网,水资源论证网站建设,51空间【Consul】Linux安装Consul保姆级教程 大家好 我是寸铁#x1f44a; 总结了一篇【Consul】Linux安装Consul保姆级教程✨ 喜欢的小伙伴可以点点关注 #x1f49d; 前言
今天要把编写的go程序放到linux上进行测试Consul服务注册与发现#xff0c;那怎么样才能实现这一过程 总结了一篇【Consul】Linux安装Consul保姆级教程✨ 喜欢的小伙伴可以点点关注 前言
今天要把编写的go程序放到linux上进行测试Consul服务注册与发现那怎么样才能实现这一过程 安装
Step1
sudo yum install -y yum-utils这个命令安装了 yum-utils 软件包它提供了一些实用的yum工具比如 yum-config-manager用于管理 yum 配置。 运行结果如下 Step2
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo这个命令通过yum-config-manager工具向yum添加了一个新的仓库即 HashiCorp 的软件包仓库。该仓库位于 https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo并包含了Consul和其他 HashiCorp 工具的软件包。 运行结果如下 Step3
sudo yum -y install consul这个命令使用 yum 包管理器从 HashiCorp 仓库安装了 Consul。-y 标志表示在安装过程中不需要用户确认直接默认回答 yes。 运行结果如下 验证安装成功
consul version启动客户端
做完三步启动一下Consul的客户端命令如下
consul agent -dev启动成功后会弹出如下信息 代表启动Consul客户端成功 停止服务
在节点运行终端中执行ctrl c表示退出节点运行。 报错排查
出现如下信息报错不要慌寸铁带你解决 Starting Consul agent...Version: 1.18.1Build Date: 2024-03-26 21:59:08 0000 UTCNode ID: 7d32991a-f1f0-ba7f-8f21-3bfe0ddf3295Node name: localhost.localdomainDatacenter: dc1 (Segment: all)Server: true (Bootstrap: false)Client Addr: [127.0.0.1] (HTTP: 8500, HTTPS: -1, gRPC: 8502, gRPC-TLS: 8503, DNS: 8600)Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)Gossip Encryption: falseAuto-Encrypt-TLS: falseACL Enabled: falseReporting Enabled: falseACL Default Policy: allowHTTPS TLS: Verify Incoming: false, Verify Outgoing: false, Min Version: TLSv1_2gRPC TLS: Verify Incoming: false, Min Version: TLSv1_2Internal RPC TLS: Verify Incoming: false, Verify Outgoing: false (Verify Hostname: false), Min Version: TLSv1_2 Log data will now stream in as it occurs:2024-03-30T23:31:57.1670800 [WARN] agent: Node name localhost.localdomain will not be discoverable via DNS due to invalid characters. Valid characters include all alpha-numerics and dashes.
2024-03-30T23:31:57.1680800 [DEBUG] agent.hcp: initialized HCP metrics sink
2024-03-30T23:31:57.1690800 [DEBUG] agent.grpc.balancer: switching server: targetconsul://dc1.7d32991a-f1f0-ba7f-8f21-3bfe0ddf3295/server.dc1 fromnone tonone
2024-03-30T23:31:57.1800800 [WARN] agent.auto_config: Node name localhost.localdomain will not be discoverable via DNS due to invalid characters. Valid characters include all alpha-numerics and dashes.
2024-03-30T23:31:57.1830800 [INFO] agent.server: shutting down server
2024-03-30T23:31:57.1840800 [ERROR] agent: Error starting agent: errorFailed to start Consul server: Failed to start RPC layer: listen tcp 127.0.0.1:8300: bind: address already in use
2024-03-30T23:31:57.1840800 [INFO] agent: Exit code: code1
具体如下
2024-03-30T23:31:57.1840800 [ERROR] agent: Error starting agent: errorFailed to start Consul server: Failed to start RPC layer: listen tcp 127.0.0.1:8300: bind: address already in use
2024-03-30T23:31:57.1840800 [INFO] agent: Exit code: code1这个地址127.0.0.1:8300已经在使用了说明你已经启动了。 使用如下命令ps -ef | grep consul查看使用情况
$ ps -ef | grep consul
root 16888 1 0 Jan20 ? 09:22:26 consul agent -dev
root 22218 19751 0 16:45 pts/0 00:00:00 grep --colorauto consul如果想要关闭执行命令kill -9 强制杀死进程第一个元素上面的16888就是进程id 再重新启动如下
consul agent -dev显示结果如下 说明启动成功了 查看Consul信息
查看服务目录
consul catalog services如下信息
[rootlocalhost ~]# consul catalog services
consulconsul是Consul官方默认存在的一个服务 查看注册服务的信息
向Consul监控的8500端口发送请求查看注册Consul服务的信息。
curl http://localhost:8500/v1/agent/services查看笔者注册的Consul信息结果如下:
[rootlocalhost resourceScheMana]# curl http://localhost:8500/v1/agent/services
{C_72_B_1: {ID: AAAA,Service: ADD,Tags: [sadijsajmijdsa5256451],Meta: {},Port: 1151,Address: 124.30.52.xx,TaggedAddresses: {lan_ipv4: {Address: 124.30.52.xx,Port: 1611},wan_ipv4: {Address: 124.30.52.xx,Port: 1611}},Weights: {Passing: 1,Warning: 1},EnableTagOverride: false,Datacenter: dc1}至此Linux安装和使用Consul的基本操作完成 看到这里的小伙伴恭喜你又掌握了一个技能 希望大家能取得胜利坚持就是胜利 我是寸铁我们下期再见 往期好文
保姆级教程
【保姆级教程】Windows11下go-zero的etcd安装与初步使用
【保姆级教程】Windows11安装go-zero代码生成工具goctl、protoc、go-zero
【Go-Zero】手把手带你在goland中创建api文件并设置高亮 报错解决
【Go-Zero】Error: user.api 27:9 syntax error: expected ‘:‘ | ‘IDENT‘ | ‘INT‘, got ‘(‘ 报错解决方案及api路由注意事项
【Go-Zero】Error: only one service expected goctl一键转换生成rpc服务错误解决方案
【Go-Zero】【error】 failed to initialize database, got error Error 1045 (28000):报错解决方案
【Go-Zero】Error 1045 (28000): Access denied for user ‘root‘‘localhost‘ (using password: YES)报错解决方案
【Go-Zero】type mismatch for field “Auth.AccessSecret“, expect “string“, actual “number“报错解决方案
【Go-Zero】Error: user.api 30:2 syntax error: expected ‘)‘ | ‘KEY‘, got ‘IDENT‘报错解决方案
【Go-Zero】Windows启动rpc服务报错panic:context deadline exceeded解决方案 Go面试向
【Go面试向】defer与time.sleep初探
【Go面试向】defer与return的执行顺序初探
【Go面试向】Go程序的执行顺序
【Go面试向】rune和byte类型的认识与使用
【Go面试向】实现map稳定的有序遍历的方式