consul
2020年10月29日Consul是一种服务网格解决方案,提供具有服务发现,配置和分段功能的全功能控制平面。这些功能可以根据需要单独使用,也可以一起使用以构建完整的服务网格。Consul需要一个数据平面,并支持代理和本机集成模型。Consul附带了一个简单的内置代理,因此一切都可以直接使用,还支持Envoy等第三方代理集成。
官网:https://www.consul.io/
部署
环境:
centos7
二进制部署
1、下载安装包
wget https://releases.hashicorp.com/consul/1.4.2/consul_1.4.2_linux_amd64.zip
2、解压到 bin 目录(/usr/bin)
unzip consul_1.4.2_linux_amd64.zip -d /usr/bin
3、测试安装结果
consul version
[root@k8s-master ~]# consul version Consul v1.4.2 Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)
4、创建配置目录
mkdir -p /etc/consul.d/
5、启动测试 agent
consul agent -server -bootstrap-expect=1 -node=agent-one -bind=10.222.28.12 -data-dir=/tmp/consul -enable-script-checks=true -config-dir=/etc/consul.d -client 0.0.0.0 -ui
详解: agent : 运行 consul agent -server Switches agent to server mode agent 作为 server 模式启动 -bootstrap-expect=<value> Sets server to expect bootstrap mode. 设置集群 server 数量,必须是在 -server 情况下,在节点数量到达参数值时选举 leader -node=<value> Name of this node. Must be unique in the cluster. 节点名称,在集群中必须唯一 -bind=<value> Sets the bind address for cluster communication. 设置节点的地址 -data-dir=<value> Path to a data directory to store agent state. 数据存储目录 -enable-script-checks Enables health check scripts. 是否开启脚本检查,默认是 false -config-dir=<value> Path to a directory to read configuration files from. This will read every file ending in '.json' as configuration in this directory in alphabetical order. Can be specified multiple times. 配置文件路径,会读取该目录下以 .json 结尾的文件,按字母顺序加载,可以指定多个 -client=<value> Sets the address to bind for client access. This includes RPC, DNS,HTTP, HTTPS and gRPC (if configured). 设置 web ui 等的地址,包括 DNS,HTTP 等方式访问的地址,默认 127.0.0.1 -ui Enables the built-in static web UI server. 使用默认的 web UI
6、查看进程、监听信息
ps -ef | grep consul
[root@k8s-master ~]# ps -ef | grep consul root 1772 1 0 10月21 ? 00:02:51 consul agent -server -bootstrap-expect=1 -node=agent-one -bind=10.222.28.12 -data-dir=/tmp/consul -enable-script-checks=true -config-dir=/etc/consul.d -client 0.0.0.0 -ui
netstat -anlp | grep consul
[root@k8s-master ~]# netstat -anlp | grep consul tcp 0 0 10.222.28.12:8300 0.0.0.0:* LISTEN 1772/consul tcp 0 0 10.222.28.12:8301 0.0.0.0:* LISTEN 1772/consul tcp 0 0 10.222.28.12:8302 0.0.0.0:* LISTEN 1772/consul tcp 0 0 10.222.28.12:43465 10.222.28.12:8300 ESTABLISHED 1772/consul tcp 0 0 10.222.28.12:8300 10.222.28.12:43465 ESTABLISHED 1772/consul tcp6 0 0 :::8500 :::* LISTEN 1772/consul tcp6 0 0 :::8600 :::* LISTEN 1772/consul udp 0 0 10.222.28.12:8301 0.0.0.0:* 1772/consul udp 0 0 10.222.28.12:8302 0.0.0.0:* 1772/consul udp6 0 0 :::8600 :::* 1772/consul
部署需要注意的地方:
最好服务器的网卡地址就是自己 -bind 的地址,不然的话会存在报错,遇到在 阿里云 上部署,我想 -bind 到自己的公网地址,但是阿里云服务器的网卡没有我要 bind 的公网地址,就出现各种乱七八糟的问题。