003.etcd集群部署-静态发现
2019-01-10 07:45:10来源:博客园 阅读 ()
一 etcd集群概述
1.1 概述
1.2 集群容错能力
1.3 集群基础
1.4 引导机制
- 静态的
- etcd Discovery
- DNS发现
二 集群部署-静态
2.1 环境准备
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
2.2 安装etcd
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 #查看已安装版本
2.3 启动前准备
1 # mkdir -p /var/log/etcd/ #建议创建etcd日志保存目录 2 # mkdir -p /data/etcd #建议创建单独的etcd数据目录
2.4 启动集群
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
2.5 集群健康检测
1 [root@etcd1 ~]# etcdctl cluster-health
附录:使用systemd管理etcd。
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
2.6 关闭集群
1 [root@etcd1 ~]# systemctl stop etcd
三 集群管理
3.1 集群成员检测
1 [root@etcd1 ~]# etcdctl member list
3.2 更新成员url
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
3.3 添加新成员
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
3.4 删除成员
1 [root@etcd1 ~]# etcdctl member remove 5a6397499417250 2 Removed member 5a6397499417250 from cluster
四 集群部署-发现
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:Linux操作随笔
- keepalived 实现LVS负载均衡高可用集群(一) 2020-06-04
- 附020.Nginx-ingress部署及使用 2020-06-02
- corosync v1 + pacemaker高可用集群部署(二)资源配置(VIP+ 2020-05-28
- Nginx + Docker 多阶段构建的部署学习 2020-05-25
- 私有云技术 2020-05-23
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash