1 # hostnamectl set-hostname etcd1.example.com 2 # hostnamectl set-hostname etcd2.example.com 3 # hostnamectl set-hostname etcd3.example.com 4 # vi /etc/hosts 5 #…… 6 172.24.8.31 etcd1.example.com 7 172.24.8.32 etcd2.example.com 8 172.24.8.33 etcd3.example.com
1 # etcd_ver=v3.3.9 2 # github_url=https://github.com/coreos/etcd/releases/download 3 # download_url=${github_url} 4 # rm -f /tmp/etcd-${etcd_ver}-linux-amd64.tar.gz 5 # rm -rf /tmp/etcd-download-test 6 # mkdir -p /tmp/etcd-download-test #创建下载保存目录 7 # curl -l ${download_url}/${etcd_ver}/etcd-${etcd_ver}-linux-amd64.tar.gz -o /tmp/etcd-${etcd_ver}-linux-amd64.tar.gz 8 # tar xzvf /tmp/etcd-${etcd_ver}-linux-amd64.tar.gz -c /tmp/etcd-download-test --strip-components=1 9 # cp /tmp/etcd-download-test/etcd /usr/local/bin/ 10 # cp /tmp/etcd-download-test/etcdctl /usr/local/bin/ 11 # rm -f /tmp/etcd-${etcd_ver}-linux-amd64.tar.gz 12 13 # rm -rf /tmp/etcd-download-test/ 14 # etcdctl_api=3 15 # etcd --version 16 # etcdctl --version #查看已安装版本
1 # mkdir -p /var/log/etcd/ #建议创建etcd日志保存目录 2 # mkdir -p /data/etcd #建议创建单独的etcd数据目录
1 [root@etcd1 ~]# etcd --name etcd1 --data-dir /data/etcd \ 2 --initial-advertise-peer-urls http://172.24.8.31:2380 \ 3 --listen-peer-urls http://172.24.8.31:2380 \ 4 --listen-client-urls http://172.24.8.31:2379,http://127.0.0.1:2379 \ 5 --advertise-client-urls http://172.24.8.31:2379 \ 6 --initial-cluster-token etcd-cluster-1 \ 7 --initial-cluster etcd1=http://172.24.8.31:2380,etcd2=http://172.24.8.32:2380,etcd3=http://172.24.8.33:2380 \ 8 --initial-cluster-state new
1 [root@etcd2 ~]# etcd --name etcd2 --data-dir /data/etcd \ 2 --initial-advertise-peer-urls http://172.24.8.32:2380 \ 3 --listen-peer-urls http://172.24.8.32:2380 \ 4 --listen-client-urls http://172.24.8.32:2379,http://127.0.0.1:2379 \ 5 --advertise-client-urls http://172.24.8.32:2379 \ 6 --initial-cluster-token etcd-cluster-1 \ 7 --initial-cluster etcd1=http://172.24.8.31:2380,etcd2=http://172.24.8.32:2380,etcd3=http://172.24.8.33:2380 \ 8 --initial-cluster-state new 9 10 [root@etcd3 ~]# etcd --name etcd3 --data-dir /data/etcd \ 11 --initial-advertise-peer-urls http://172.24.8.33:2380 \ 12 --listen-peer-urls http://172.24.8.33:2380 \ 13 --listen-client-urls http://172.24.8.33:2379,http://127.0.0.1:2379 \ 14 --advertise-client-urls http://172.24.8.33:2379 \ 15 --initial-cluster-token etcd-cluster-1 \ 16 --initial-cluster etcd1=http://172.24.8.31:2380,etcd2=http://172.24.8.32:2380,etcd3=http://172.24.8.33:2380 \ 17 --initial-cluster-state new
1 [root@etcd1 ~]# vi /root/startetcd.sh 2 #!/bin/sh 3 #****************************************************************# 4 # scriptname: /root/startetcd.sh 5 # author: xiang hongying 6 # create date: 2018-09-10 01:14 7 # modify author: xiang hongying 8 # e-mail: x120952576@126.com 9 # version: 10 #***************************************************************# 11 logfile=/var/log/etcd/etcd.log 12 /usr/local/bin/etcd --name etcd1 --data-dir /data/etcd \ 13 --initial-advertise-peer-urls http://172.24.8.31:2380 \ 14 --listen-peer-urls http://172.24.8.31:2380 \ 15 --listen-client-urls http://172.24.8.31:2379,http://127.0.0.1:2379 \ 16 --advertise-client-urls http://172.24.8.31:2379 \ 17 --initial-cluster-token etcd-cluster-1 \ 18 --initial-cluster etcd1=http://172.24.8.31:2380,etcd2=http://172.24.8.32:2380,etcd3=http://172.24.8.33:2380 \ 19 -initial-cluster-state new >> $logfile 2>&1 & 20 [root@etcd1 ~]# chmod u+x startetcd.sh
1 [root@etcd1 ~]# etcdctl cluster-health
1 [root@etcd1 ~]# vi /lib/systemd/system/etcd.service 2 [unit] 3 description=etcd 4 documentation=https://github.com/coreos/etcd 5 conflicts=etcd.service 6 7 [service] 8 type=notify 9 restart=always 10 restartsec=5s 11 limitnofile=40000 12 timeoutstartsec=0 13 14 execstart=/usr/local/bin/etcd --name etcd1 --data-dir /data/etcd \ 15 --initial-advertise-peer-urls http://172.24.8.31:2380 \ 16 --listen-peer-urls http://172.24.8.31:2380 \ 17 --listen-client-urls http://172.24.8.31:2379,http://127.0.0.1:2379 \ 18 --advertise-client-urls http://172.24.8.31:2379 \ 19 --initial-cluster-token etcd-cluster-1 \ 20 --initial-cluster etcd1=http://172.24.8.31:2380,etcd2=http://172.24.8.32:2380,etcd3=http://172.24.8.33:2380 \ 21 --initial-cluster-state new 22 23 [install] 24 wantedby=multi-user.target 25 [root@etcd1 ~]# systemctl daemon-reload 26 [root@etcd1 ~]# systemctl start etcd.service 27 [root@etcd1 ~]# systemctl enable etcd.service
1 [root@etcd1 ~]# systemctl stop etcd
1 [root@etcd1 ~]# etcdctl member list
1 [root@etcd3 ~]# ifconfig eth0 2 inet 172.24.8.40 3 [root@etcd3 ~]# vi /lib/systemd/system/etcd.service #将所有旧ip改为最新ip。
1 [root@etcd3 ~]# systemctl restart etcd 2 [root@etcd1 ~]# etcdctl member list #在leader节点查看所有节点
1 [root@etcd1 ~]# etcdctl member update 14ff148c62a24fb2 http://172.24.8.40:2380 #更新对等url
1 [root@localhost ~]# hostnamectl set-hostname etcd4.example.com
1 [root@etcd1 ~]# etcdctl member add etcd4 http://172.24.8.34:2380
1 [root@etcd4 ~]# export etcd_name="etcd4" 2 [root@etcd4 ~]# export etcd_initial_cluster="etcd4=http://172.24.8.34:2380,etcd3=http://172.24.8.40:2380,etcd1=http://172.24.8.31:2380,etcd2=http://172.24.8.32:2380" 3 [root@etcd4 ~]# export etcd_initial_cluster_state="existing" 4 [root@etcd4 ~]# etcd --listen-client-urls http://172.24.8.34:2379,http://127.0.0.1:2379 --advertise-client-urls http://172.24.8.34:2379 --listen-peer-urls http://172.24.8.34:2380 --initial-advertise-peer-urls http://172.24.8.34:2380 --data-dir /data/etcd 5 [root@etcd1 ~]# etcdctl member list 6 [root@etcd1 ~]# etcdctl cluster-health
1 # rm -rf /var/lib/etcd/default.etcd/ 2 # systemctl start etcd
1 [root@etcd1 ~]# etcdctl member remove 5a6397499417250 2 removed member 5a6397499417250 from cluster
如对本文有疑问, 点击进行留言回复!!
linux下文本编辑器vim的使用方法(复制、粘贴、替换、行号、撤销、多文件操作)
网友评论