标签:agent release bin arc word 网络配置 lis syn color
本示例基于Centos 7,在阿里云的三台机器上部署consul集群,假设目前使用的账号为release,拥有sudo权限。
由于Docker官方镜像下载较慢,可以开启阿里云的Docker镜像下载加速器,可参考此文进行配置。
假设三台主机的ip分别为:
三台主机的安装步骤相似,以主机一为例:
1. 安装docker服务:
sudo yum install -y docker
2. 启动docker服务:
sudo service docker start
3. 查找consul镜像:
sudo docker search consul
4. 下载官方consul镜像:
sudo docker pull docker.io/consul
5. 下载完后可检查镜像:
sudo docker images
6. 三台主机上建立数据目录和配置目录,目录为空即可:
mkdir -p /data/consul_data/data
mkdir -p /data/consul_data/conf
7. 三台主机依次启动容器:
主机一的命令为:
sudo docker run --net=host --name consul -v /data/consul_data/data:/consul/data -v /data/consul_data/conf:/consul/config -d docker.io/consul consul agent -server -bind=192.168.0.1 -bootstrap-expect=3 -data-dir /consul/data -config-dir /consul/config
主机二的命令为:
sudo docker run --net=host --name consul -v /data/consul_data/data:/consul/data -v /data/consul_data/conf:/consul/config -d docker.io/consul consul agent -server -bind=192.168.0.1 -bootstrap-expect=3 -data-dir /consul/data -config-dir /consul/config -join 192.168.0.1
主机三的命令为:
sudo docker run --net=host --name consul -v /data/consul_data/data:/consul/data -v /data/consul_data/conf:/consul/config -d docker.io/consul consul agent -server -bind=192.168.0.3 -bootstrap-expect=3 -data-dir /consul/data -config-dir /consul/config -join 192.168.0.1
命令说明:
都启动完成后,可以通过如下命令观察consul日志,了解启动情况:
sudo docker logs 容器id/容器名称
日志情况示例如下:
[release@sh-lbs02 data]$ sudo docker logs consul [sudo] password for release: bootstrap_expect > 0: expecting 3 servers ==> Starting Consul agent... ==> Joining cluster... Join completed. Synced with 1 initial agents ==> Consul agent running! Version: ‘v1.2.3‘ Node ID: ‘56e5b37e-b636-3cfa-6a9b-2ce47e0dfbd1‘ Node name: ‘sh-lbs02‘ Datacenter: ‘dc1‘ (Segment: ‘<all>‘) Server: true (Bootstrap: false) Client Addr: [127.0.0.1] (HTTP: 8500, HTTPS: -1, DNS: 8600) Cluster Addr: 192.168.0.1 (LAN: 8301, WAN: 8302) Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false
8. 检查集群状态:
sudo docker exec -it 容器id /bin/sh
通过该命令进入容器,查看集群信息:
[release@sh-lbs02 data]$ sudo docker exec -it 8a /bin/sh / # consul members Node Address Status Type Build Protocol DC Segment lbs02 192.168.0.1:8301 alive server 1.2.3 2 dc1 <all> web01 192.168.0.2:8301 alive server 1.2.3 2 dc1 <all> web02 192.168.0.3:8301 alive server 1.2.3 2 dc1 <all> / #
至此,集群已启动完成,consul的端口打开较多,可以在主机上观察其端口情况:
[release@sh-web02 ~]$ sudo netstat -tlnp|grep consul [sudo] password for release: tcp 0 0 192.168.0.1:8300 0.0.0.0:* LISTEN 330/consul tcp 0 0 192.168.0.1:8301 0.0.0.0:* LISTEN 330/consul tcp 0 0 192.168.0.1:8302 0.0.0.0:* LISTEN 330/consul tcp 0 0 127.0.0.1:8500 0.0.0.0:* LISTEN 330/consul tcp 0 0 127.0.0.1:8600 0.0.0.0:* LISTEN 330/consul
9. 如何启动consul客户端?假设consul客户端与服务端在同一个主机上:
首先,建立客户端的配置目录和数据目录:
mkdir -p /data/consul_data_cli/data mkdir -p /data/consul_data_cli/conf
其次,在配置目录下分配客户端使用的端口,避免与服务端的端口冲突:
cd /data/consul_data_cli/conf touch basic.json vi basic.json #内容如下: { "ports": { "http":18501, "dns":18601, "rpc":18401, "serf_lan":18301, "serf_wan":18302, "server":18300 } }
最后,启动客户端:
sudo docker run --net=host --name consul-cli -v /data/consul_data_cli/data:/consul/data -v /data/consul_data_cli/conf:/consul/config -d docker.io/consul consul agent -bind=192.168.0.2 -data-dir /consul/data -config-dir /consul/config -join 192.168.0.1:8301
标签:agent release bin arc word 网络配置 lis syn color
原文地址:https://www.cnblogs.com/hutao722/p/9668202.html