设为首页 收藏本站
查看: 1362|回复: 0

[经验分享] etcd集群的部署

[复制链接]

尚未签到

发表于 2019-1-31 11:40:25 | 显示全部楼层 |阅读模式
node1  192.168.56.173
node2 192.168.56.174
node3 192.168.56.200
node* 为主机名称
[root@node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@node1 ~]#  

https://github.com/coreos/etcd/releases/download/v3.0.15/etcd-v3.0.15-linux-amd64.tar.gz
tar xf  etcd-v3.0.15-linux-amd64.tar.gz
cd etcd-v3.0.15-linux-amd64
cp etcd  /usr/bin/
cp etcdctl /usr/bin/  192.168.56.173(node1)

  cat  /etc/systemd/system/etcd2.service
[Unit]
Description=etcd2.service
[Service]
Type=notify
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/mkdir -p /data/etcd2
ExecStart=/usr/bin/etcd \
  --data-dir /data/etcd2 \
  --name etcd0 \
  --advertise-client-urls http://192.168.56.173:2379,http://192.168.56.173:4001 \
  --listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
  --initial-advertise-peer-urls http://192.168.56.173:2380 \
  --listen-peer-urls http://0.0.0.0:2380 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-cluster etcd0=http://192.168.56.173:2380,etcd1=http://192.168.56.174:2380,etcd2=http://192.168.56.200:2380
[Install]
WantedBy=multi-user.target# 设置服务自启动
systemctl enable /etc/systemd/system/etcd2.service
# 启动etcd1  (先不要做 三个节点都部署完毕 在分别启动 否则启动会hang)
systemctl restart etcd2.service192.168.56.174(node2)
  [root@node2 ~]# cat  /etc/systemd/system/etcd2.service
[Unit]
Description=etcd2.service
[Service]
Type=notify
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/mkdir -p /data/etcd2
ExecStart=/usr/bin/etcd \
  --data-dir /data/etcd2 \
  --name etcd1 \
  --advertise-client-urls http://192.168.56.174:2379,http://192.168.56.174:4001 \
  --listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
  --initial-advertise-peer-urls http://192.168.56.174:2380 \
  --listen-peer-urls http://0.0.0.0:2380 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-cluster etcd0=http://192.168.56.173:2380,etcd1=http://192.168.56.174:2380,etcd2=http://192.168.56.200:2380
[Install]
WantedBy=multi-user.target# 设置服务自启动
systemctl enable /etc/systemd/system/etcd2.service
# 启动etcd2  (先不要做 三个节点都部署完毕 在分别启动 否则启动会hang)
systemctl restart etcd2.service192.168.56.200(node2)
[root@node3~]# cat  /etc/systemd/system/etcd2.service
[root@node3 ~]# cat  /etc/systemd/system/etcd2.service
[Unit]
Description=etcd2.service
[Service]
Type=notify
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/mkdir -p /data/etcd2
ExecStart=/usr/bin/etcd \
  --data-dir /data/etcd2 \
  --name etcd2 \
  --advertise-client-urls http://192.168.56.200:2379,http://192.168.56.200:4001 \
  --listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
  --initial-advertise-peer-urls http://192.168.56.200:2380 \
  --listen-peer-urls http://0.0.0.0:2380 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-cluster etcd0=http://192.168.56.173:2380,etcd1=http://192.168.56.174:2380,etcd2=http://192.168.56.200:2380
[Install]
WantedBy=multi-user.target# 设置服务自启动
systemctl enable /etc/systemd/system/etcd2.service
# 启动etcd3  (先不要做 三个节点都部署完毕 在分别启动 否则启动会hang)
systemctl restart etcd2.service  备注:启动的方式一个一个启动 否则systemctl  restart   etcd2.service 会hang住
  

  查看状态
[root@node3 ~]# systemctl  status etcd2.service
● etcd2.service
   Loaded: loaded (/etc/systemd/system/etcd2.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2017-09-02 23:43:59 CST; 10min ago
  Process: 2673 ExecStartPre=/usr/bin/mkdir -p /data/etcd2 (code=exited, status=0/SUCCESS)
Main PID: 2675 (etcd)
   CGroup: /system.slice/etcd2.service
           └─2675 /usr/bin/etcd --data-dir /data/etcd2 --name etcd2 --advertise-client-urls http://192.168.56.200:2379,http://192.168.56.200:4001 --listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001...
Sep 02 23:44:45 node3 etcd[2675]: established a TCP streaming connection with peer e37f661be0f0e44a (stream Message reader)
Sep 02 23:44:45 node3 etcd[2675]: established a TCP streaming connection with peer 161efc88633d5fd4 (stream MsgApp v2 reader)
Sep 02 23:44:45 node3 etcd[2675]: established a TCP streaming connection with peer 161efc88633d5fd4 (stream Message reader)
Sep 02 23:44:45 node3 etcd[2675]: closed an existing TCP streaming connection with peer 161efc88633d5fd4 (stream Message writer)
Sep 02 23:44:45 node3 etcd[2675]: established a TCP streaming connection with peer 161efc88633d5fd4 (stream Message writer)
Sep 02 23:44:46 node3 etcd[2675]: 52aafe548d51c9ea [term: 25] received a MsgVote message with higher term from e37f661be0f0e44a [term: 26]
Sep 02 23:44:46 node3 etcd[2675]: 52aafe548d51c9ea became follower at term 26
Sep 02 23:44:46 node3 etcd[2675]: 52aafe548d51c9ea [logterm: 20, index: 623, vote: 0] voted for e37f661be0f0e44a [logterm: 20, index: 623] at term 26
Sep 02 23:44:46 node3 etcd[2675]: 52aafe548d51c9ea [term: 26] ignored a MsgVote message with lower term from 161efc88633d5fd4 [term: 24]
Sep 02 23:44:46 node3 etcd[2675]: raft.node: 52aafe548d51c9ea elected leader e37f661be0f0e44a at term 26
[root@node3 ~]#[root@node3 ~]# netstat  -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      869/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1132/master         
tcp6       0      0 :::2379                 :::*                    LISTEN      2675/etcd           
tcp6       0      0 :::2380                 :::*                    LISTEN      2675/etcd           
tcp6       0      0 :::22                   :::*                    LISTEN      869/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1132/master         
tcp6       0      0 :::4001                 :::*                    LISTEN      2675/etcd           
[root@node3 ~]#  查看相关主体的状态

[root@node1 etcd-v3.0.15-linux-amd64]# etcdctl member list
161efc88633d5fd4: name=etcd0 peerURLs=http://192.168.56.173:2380 clientURLs=http://192.168.56.173:2379,http://192.168.56.173:4001 isLeader=false
52aafe548d51c9ea: name=etcd2 peerURLs=http://192.168.56.200:2380 clientURLs=http://192.168.56.200:2379,http://192.168.56.200:4001 isLeader=false
e37f661be0f0e44a: name=etcd1 peerURLs=http://192.168.56.174:2380 clientURLs=http://192.168.56.174:2379,http://192.168.56.174:4001 isLeader=true
[root@node1 etcd-v3.0.15-linux-amd64]#  集群的状态监控(可以结合zabbix做监控)
[root@node1 etcd-v3.0.15-linux-amd64]# etcdctl cluster-health
member 161efc88633d5fd4 is healthy: got healthy result from http://192.168.56.173:2379
member 52aafe548d51c9ea is healthy: got healthy result from http://192.168.56.200:2379
member e37f661be0f0e44a is healthy: got healthy result from http://192.168.56.174:2379
cluster is healthy
[root@node1 etcd-v3.0.15-linux-amd64]#  etcd基本操作

[root@node1 ~]# etcdctl set testkey "hello world"
hello world
[root@node1 ~]# etcdctl   get  testkey
hello world
[root@node1 ~]# curl -L http://localhost:2379/v2/keys/testkey
{"action":"get","node":{"key":"/testkey","value":"hello world","modifiedIndex":11,"createdIndex":11}}
[root@node1 ~]# curl -L http://192.168.56.173:2379/v2/keys/testkey
{"action":"get","node":{"key":"/testkey","value":"hello world","modifiedIndex":11,"createdIndex":11}}
[root@node1 ~]#  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-670004-1-1.html 上篇帖子: 使用kubeadm部署k8s集群02-配置etcd高可用 下篇帖子: 配置Etcd集群
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表