ETCD集群搭建
程序员文章站
2022-07-13 22:20:04
...
节点信息
节点名称 | IP | 备注 |
---|---|---|
etcd-1 | 192.168.122.137 | master |
etcd-2 | 192.168.122.126 | slave1 |
etcd-3 | 192.168.122.180 | slave2 |
下载ETCD安装文件。
-
我的系统是centos的,所以,下载了linux os的v2.2.3。
curl -L https://github.com/coreos/etcd/releases/download/v2.2.3/etcd-v2.2.3-linux-amd64.tar.gz -o etcd-v2.2.3-linux-amd64.tar.gz
-
解压
tar xf etcd-v2.2.3-linux-amd64.tar.gz
-
复制可执行文件(etcd是server端的,etcdctl是client端)到你想安装的位置,我放在了/opt/etcd/bin/。
cp etcd etcdctl /opt/etcd/bin/
准备配置文件。
-
etcd.conf,我放在了/opt/etcd/etc/下。
# [member] ETCD_NAME=etcd-1 #节点名称 ETCD_DATA_DIR="/data/etcd/data/etcd-1.etcd" ETCD_LISTEN_PEER_URLS="http://192.168.122.137:2380" ETCD_LISTEN_CLIENT_URLS="http://192.168.122.137:2379,http://127.0.0.1:2379" #[cluster] ETCD_INITIAL_CLUSTER="etcd-1=http://192.168.122.137:2380,etcd-2=http://192.168.122.126:2380,etcd-3=http://192.168.122.180:2380" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.122.137:2380" ETCD_INITIAL_CLUSTER_STATE="new" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" #集群名 ETCD_ADVERTISE_CLIENT_URLS="http://192.168.122.137:2379" #[logging] ETCD_DEBUG="false" # examples for -log-package-levels etcdserver=WARNING,security=DEBUG ETCD_LOG_PACKAGE_LEVELS="WARNING"
注:
1. 另外两个节点的配置文件类似,修改节点名称,集群名,以及和节点相关的IP即可。
2. ETCD_INITIAL_CLUSTER_STATE 的值在刚开始创建集群的时候应该为new,如果是长时间以后添加node,需要改为existing。
-
systemd的conf,即etcd.service
[Unit] Description=Etcd Server After=network.target After=network-online.target Wants=network-online.target [Service] Type=notify WorkingDirectory=/data/etcd/data User=root EnvironmentFile=-/opt/etcd/etc/etcd.conf # set GOMAXPROCS to number of processors ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /opt/etcd/bin/etcd --name=\"${ETCD_NAME}\" --initial-advertise-peer-urls=\"${ETCD_INITIAL_ADVERTISE_PEER_URLS}\" --listen-peer-urls=\"${ETCD_LISTEN_PEER_URLS}\" --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\" --advertise-client-urls=\"${ETCD_ADVERTISE_CLIENT_URLS}\" --initial-cluster-token=\"${ETCD_INITIAL_CLUSTER_TOKEN}\" --initial-cluster=\"${ETCD_INITIAL_CLUSTER}\" --initial-cluster-state=\"${ETCD_INITIAL_CLUSTER_STATE}\" --data-dir=\"${ETCD_DATA_DIR}\"" Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target
-
start。先在master节点启动,然后分别在slave节点上启动。
systemctl start etcd.service
-
验证
./etcdctl cluster-health