1.机器3台centos7
192.168.2.15 node1
192.168.2.14 node2
192.168.2.13 node3
node1上脚本
#!/bin/bash
service etcd stop
yum remove etcd -y
sudo rm -rf /var/lib/etcd
sudo rm -rf /etc/etcd
sudo rm -rf /usr/lib/systemd/system/etcd.service
sudo rm -rf /usr/bin/etcd*
yum install etcd -y
echo '192.168.2.15 node1' >> /etc/hosts
echo '192.168.2.14 node2' >> /etc/hosts
echo '192.168.2.13 node3' >> /etc/hosts
cat /etc/hosts
#-------------node1 conf----------------
cat <<EOF > /etc/etcd/etcd.conf
# [member]
ETCD_NAME=node1
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
#ETCD_WAL_DIR=""
#ETCD_SNAPSHOT_COUNT="10000"
#ETCD_HEARTBEAT_INTERVAL="100"
#ETCD_ELECTION_TIMEOUT="1000"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001"
#ETCD_MAX_SNAPSHOTS="5"
#ETCD_MAX_WALS="5"
#ETCD_CORS=""
#
#[cluster]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://node1:2380"
# if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."
ETCD_INITIAL_CLUSTER="node1=http://node1:2380,node2=http://node2:2380,node3=http://node3:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="mritd-etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://node1:2379,http://node1:4001"
EOF
systemctl restart etcd
etcdctl member list
etcdctl --version
node2上脚本
#!/bin/bash
service etcd stop
yum remove etcd -y
sudo rm -rf /var/lib/etcd
sudo rm -rf /etc/etcd
sudo rm -rf /usr/lib/systemd/system/etcd.service
sudo rm -rf /usr/bin/etcd*
yum install etcd -y
echo '192.168.2.15 node1' >> /etc/hosts
echo '192.168.2.14 node2' >> /etc/hosts
echo '192.168.2.13 node3' >> /etc/hosts
cat /etc/hosts
#-------------node2 conf----------------
cat <<EOF > /etc/etcd/etcd.conf
# [member]
ETCD_NAME=node2
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
#ETCD_WAL_DIR=""
#ETCD_SNAPSHOT_COUNT="10000"
#ETCD_HEARTBEAT_INTERVAL="100"
#ETCD_ELECTION_TIMEOUT="1000"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001"
#ETCD_MAX_SNAPSHOTS="5"
#ETCD_MAX_WALS="5"
#ETCD_CORS=""
#
#[cluster]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://node2:2380"
# if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."
ETCD_INITIAL_CLUSTER="node1=http://node1:2380,node2=http://node2:2380,node3=http://node3:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="mritd-etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://node2:2379,http://node2:4001"
EOF
systemctl restart etcd
etcdctl member list
etcdctl --version
node3上脚本
#!/bin/bah
service etcd stop
yum remove etcd -y
sudo rm -rf /var/lib/etcd
sudo rm -rf /etc/etcd
sudo rm -rf /usr/lib/systemd/system/etcd.service
sudo rm -rf /usr/bin/etcd*
yum install etcd -y
echo '192.168.2.15 node1' >> /etc/hosts
echo '192.168.2.14 node2' >> /etc/hosts
echo '192.168.2.13 node3' >> /etc/hosts
cat /etc/hosts
#-------------node3 conf----------------
cat <<EOF > /etc/etcd/etcd.conf
# [member]
ETCD_NAME=node3
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
#ETCD_WAL_DIR=""
#ETCD_SNAPSHOT_COUNT="10000"
#ETCD_HEARTBEAT_INTERVAL="100"
#ETCD_ELECTION_TIMEOUT="1000"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001"
#ETCD_MAX_SNAPSHOTS="5"
#ETCD_MAX_WALS="5"
#ETCD_CORS=""
#
#[cluster]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://node3:2380"
# if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test=http://..."
ETCD_INITIAL_CLUSTER="node1=http://node1:2380,node2=http://node2:2380,node3=http://node3:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="mritd-etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://node3:2379,http://node3:4001"
EOF
systemctl restart etcd
etcdctl member list
etcdctl --version
三台机器上运行相应脚本,集群搭建即可完毕
2.下面介绍使用docker创建etcd集群,一条命令搞定
#更改相应的ip和端口
docker run --name etcd1 --restart always\
-p 2379:2379 -p 2380:2380 \
-d 10.10.101.199:5000/etcd:v3.1.10 \
/usr/local/bin/etcd \
--data-dir /etcd-data.etcd \
--name etcd1 \
--initial-advertise-peer-urls "http://192.168.2.12:2380" \
--listen-peer-urls "http://0.0.0.0:2380" \
--advertise-client-urls http://192.168.2.12:2379 \
--listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
--initial-cluster "etcd1=http://192.168.2.12:2380,etcd2=http://192.168.2.13:2380,etcd3=http://192.168.2.14:2380" \
--initial-cluster-state "new" \
--initial-cluster-token "etcd-cluster"
参考:http://www.cnblogs.com/breg/p/5728237.html