Consul是什么
Consul是一种网络工具,可提供功能齐全的服务网格和服务发现。在本地尝试领事。这句话引用与官网
部署安装
我这边使用的是linux7.6的环境
下载源代码
wget https://releases.hashicorp.com/consul/1.9.0/consul_1.9.0_linux_amd64.zip没有使用镜像的情况下,下载比较慢.下载完成之后解压
unzip consul_1.9.0_linux_amd64.zip,解压完成之后移动到/usr/local/bin下面
unzip consul_1.9.0_linux_amd64.zip
mv consul /usr/local/bin
#检查是否有效
consul version
# 查看相关指令
consul
# 开发环境启动 这里切记 如果是私有服务器一定要用私有ip否则 外网无法访问
consul agent -dev -ui -client=ip
- 启动成功访问地址
http://ip:8500看到下面的页面即为启动成功
错误记录
- 启动报错
2020-12-11T17:21:46.622+0800 [ERROR] agent: Error starting agent: error="2 errors occurred:
* listen udp 114.55.164.189:8600: bind: cannot assign requested address
* listen tcp 114.55.164.189:8600: bind: cannot assign requested address
这里是因为指定的ip是外网ip,启动失败
使用外网ip启动成功但是外网拒绝访问 ,百度有的启动命令是这种
consul agent -dev -ui -node=consul-dev-client=114.55.164.189可以正常启动并且不报错,但是浏览器访问http://ip:8500拒绝访问按照争取的步骤启动还是无法访问
- 检查服务器的安全组配置,是否开发8500端口
- 如果有其他堡垒机胡或者宝塔工具等,也需要单独开发端口
- 直接关闭防火墙
systemctl stop firewalld
3. 服务注册成功显示错误
Get "http://PC-20190718WRMV:8006/actuator/health": dial tcp: lookup PC-20190718WRMV on 100.100.2.138:53: no such host
- 检查心跳协议是否关闭
spring.cloud.consul.discovery.heartbeat.enable=true - 启动服务的机器的
ip映射 将PC-20190718WRMV映射为127.0.0.1 window系统在C:\Windows\System32\drivers\etc在hosts中添加127.0.0.1 PC-20190718WRMV后面这个对应你电脑服务启动的名称
成功的页面