下载二进制包
下载地址:https://developer.hashicorp.com/consul/install
https://releases.hashicorp.com/consul/1.18.1/consul_1.18.1_linux_amd64.zip
下载解压
wget https://releases.hashicorp.com/consul/1.18.1/consul_1.18.1_linux_amd64.zip [root@mcw12 mcw]# ls consul_1.18.1_linux_amd64.zip [root@mcw12 mcw]# unzip consul_1.18.1_linux_amd64.zip Archive: consul_1.18.1_linux_amd64.zip inflating: consul [root@mcw12 mcw]# ls consul consul_1.18.1_linux_amd64.zip [root@mcw12 mcw]#
复制到指定位置
[root@mcw12 mcw]# ls consul consul_1.18.1_linux_amd64.zip [root@mcw12 mcw]# [root@mcw12 mcw]# ls /usr/local/bin/ [root@mcw12 mcw]# cp consul /usr/local/bin/ [root@mcw12 mcw]# ls /usr/local/bin/ consul [root@mcw12 mcw]#
服务部署
下面三个机器都是consul节点
创建启动文件
[root@mcw12 mcw]# cat /etc/systemd/system/consul.service [Unit] Description=consul Wants=network.target After=network.target [Service] LimitCORE=infinity LimitNOFILE=65535 LimitNPROC=65535 Environment="GOMAXPROCS=2" "PATH=/usr/local/bin:/usr/bin:/bin" ExecStart=/usr/local/bin/consul agent -config-dir=/etc/consul.d ExecReload=/bin/kill -HUP $MAINPID KillSignal=TERM Restart=on-failure RestartSec=1s User=root Group=root [Install] WantedBy=multi-user.target [root@mcw12 mcw]#
创建配置文件并启动。下面的token随便写的
[root@mcw12 mcw]# mkdir /etc/consul.d [root@mcw12 mcw]# vim /etc/consul.d/config.json [root@mcw12 mcw]# cat /etc/consul.d/config.json { "acl": { "default_policy": "deny", "down_policy": "extend-cache", "enabled": true, "tokens": { "agent": "m1896af6-xiao3-3e89-6dcc-6eab0dd031c0mcw", "master": "m18pVDL3+4TxiaodNSqY4pqAx1G40WLVSDlfOQI4cKwmcw=" } }, "bind_addr": "10.0.0.22", "bootstrap_expect": 3, "client_addr": "10.0.0.22", "data_dir": "/var/consul", "datacenter": "mcwdatacenter", "enable_debug": false, "encrypt": "", "log_level": "info", "rejoin_after_leave": true, "retry_interval": "15s", "retry_join": [ "10.0.0.22", "10.0.0.23", "10.0.0.24" ], "server": true, "start_join": [ "10.0.0.22", "10.0.0.23", "10.0.0.24" ], "ui": true } [root@mcw12 mcw]# systemctl start consul [root@mcw12 mcw]# systemctl status consul ● consul.service - consul Loaded: loaded (/etc/systemd/system/consul.service; disabled; vendor preset: disabled) Active: active (running) since Sun 2024-05-12 10:52:24 CST; 4s ago Main PID: 2411 (consul) Tasks: 8 CGroup: /system.slice/consul.service └─2411 /usr/local/bin/consul agent -config-dir=/etc/consul.d May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.382+0800 [INFO] agent: Starting server: address=10.0.0.22:8500 network=tcp protocol=http May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.382+0800 [INFO] agent: Starting server: address=scada::core_api network=scada protocol=http May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.382+0800 [INFO] agent: Started gRPC listeners: port_name=grpc_tls address=10.0.0.22:8503 network=tcp May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.382+0800 [INFO] agent: Retry join is supported for the following discovery methods: cluster=LAN discovery_methods...ton vsphere" May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.382+0800 [INFO] agent: Joining cluster...: cluster=LAN May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.382+0800 [INFO] agent: (LAN) joining: lan_addresses=["10.0.0.22", "10.0.0.23", "10.0.0.24", "10.0.0.22", "10.0.0...."10.0.0.24"] May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.400+0800 [INFO] agent: started state syncer May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.400+0800 [INFO] agent: Consul agent running! May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.403+0800 [INFO] agent: (LAN) joined: number_of_nodes=2 May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.403+0800 [INFO] agent: Join cluster completed. Synced with initial agents: cluster=LAN num_agents=2 Hint: Some lines were ellipsized, use -l to show in full. [root@mcw12 mcw]# consul members Error retrieving members: Get "http://127.0.0.1:8500/v1/agent/members?segment=_all": dial tcp 127.0.0.1:8500: connect: connection refused [root@mcw12 mcw]#
访问网页
10.0.0.22:8500,目前另外两个节点还没启动,复制一下consul命令和配置到其它节点,修改配置为当前机器的ip,然后启动一下,agent token 和mastertoken,三个节点一样就可以
启动另外两个节点之前没有leader
[root@mcw12 mcw]# curl http://10.0.0.22:8500/v1/status/leader
""[root@mcw12 mcw]#
启动另外两个节点
[root@mcw13 ~]# cat /etc/consul.d/config.json { "acl": { "default_policy": "deny", "down_policy": "extend-cache", "enabled": true, "tokens": { "agent": "m1896af6-xiao3-3e89-6dcc-6eab0dd031c0mcw", "master": "m18pVDL3+4TxiaodNSqY4pqAx1G40WLVSDlfOQI4cKwmcw=" } }, "bind_addr": "10.0.0.23", "bootstrap_expect": 3, "client_addr": "10.0.0.23", "data_dir": "/var/consul", "datacenter": "mcwdatacenter", "enable_debug": false, "encrypt": "", "log_level": "info", "rejoin_after_leave": true, "retry_interval": "15s", "retry_join": [ "10.0.0.22", "10.0.0.23", "10.0.0.24" ], "server": true, "start_join": [ "10.0.0.22", "10.0.0.23", "10.0.0.24" ], "ui": true } [root@mcw13 ~]# systemctl restart consul
[root@mcw14 ~]# cat /etc/consul.d/config.json { "acl": { "default_policy": "deny", "down_policy": "extend-cache", "enabled": true, "tokens": { "agent": "m1896af6-xiao3-3e89-6dcc-6eab0dd031c0mcw", "master": "m18pVDL3+4TxiaodNSqY4pqAx1G40WLVSDlfOQI4cKwmcw=" } }, "bind_addr": "10.0.0.24", "bootstrap_expect": 3, "client_addr": "10.0.0.24", "data_dir": "/var/consul", "datacenter": "mcwdatacenter", "enable_debug": false, "encrypt": "", "log_level": "info", "rejoin_after_leave": true, "retry_interval": "15s", "retry_join": [ "10.0.0.22", "10.0.0.23", "10.0.0.24" ], "server": true, "start_join": [ "10.0.0.22", "10.0.0.23", "10.0.0.24" ], "ui": true } [root@mcw14 ~]# systemctl restart consul [root@mcw14 ~]#
再次curl访问,可以找到leader节点了
[root@mcw13 ~]# curl http://10.0.0.23:8500/v1/status/leader "10.0.0.22:8300"[root@mcw13 ~]#
consul页面使用
再次访问页面,提示要登录
登录一下
试试这个
用上面的登录成功了,点进去查看
是所有的节点,再点进去一个节点看看
再看这里,点进去leader查看下
现在还没有键值对
看下token
点击进入
点击这里,复制出我这里登录用的token
只读
常用命令
查看集群leader
任一节点,用当前节点ip看
[root@mcw13 ~]# curl http://10.0.0.23:8500/v1/status/leader "10.0.0.22:8300"[root@mcw13 ~]# [root@mcw13 ~]#
标签:10.0,部署,consul,52,mcw12,mcw,root From: https://www.cnblogs.com/machangwei-8/p/18187627