etcd集群部署
etcd集群部署
张富贵 发表于2年前
etcd集群部署
  • 发表于 2年前
  • 阅读 1034
  • 收藏 5
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

摘要: etcd集群部署

etcd clustering guide

##架构设计 etcd架构设计如下图: 由3个节点的etcd node构建,服务端通过haproxy进行访问

###服务器列表 |Name|Address|HostName| |-----|-----|-----| |node1|10.10.0.11|niub-etcd1| |node2|10.10.0.12|niub-etcd2| |node3|10.10.0.13|niub-etcd3| |haproxy|10.10.0.14|haproxy|

##etcd配置 ###node1 编辑etcd启动脚本/usr/local/etcd/start.sh

/usr/local/etcd/etcd -name niub1 -debug \
-initial-advertise-peer-urls http://niub-etcd-1:2380 \
-listen-peer-urls http://niub-etcd-1:2380 \
-listen-client-urls http://niub-etcd-1:2379,http://127.0.0.1:2379 \
-advertise-client-urls http://niub-etcd-1:2379 \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster niub1=http://niub-etcd-1:2380,niub2=http://niub-etcd-2:2380,niub3=http://niub-etcd-3:2380 \
-initial-cluster-state new  >> /niub/etcd_log/etcd.log 2>&1 &

###node2 编辑etcd启动脚本/usr/local/etcd/start.sh

/usr/local/etcd/etcd -name niub2 -debug \
-initial-advertise-peer-urls http://niub-etcd-2:2380 \
-listen-peer-urls http://niub-etcd-2:2380 \
-listen-client-urls http://niub-etcd-2:2379,http://127.0.0.1:2379 \
-advertise-client-urls http://niub-etcd-2:2379 \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster niub1=http://niub-etcd-1:2380,niub2=http://niub-etcd-2:2380,niub3=http://niub-etcd-3:2380 \
-initial-cluster-state new  >> /niub/etcd_log/etcd.log 2>&1 &

###node3 编辑etcd启动脚本/usr/local/etcd/start.sh

/usr/local/etcd/etcd -name niub3 -debug \
-initial-advertise-peer-urls http://niub-etcd-3:2380 \
-listen-peer-urls http://niub-etcd-3:2380 \
-listen-client-urls http://niub-etcd-3:2379,http://127.0.0.1:2379 \
-advertise-client-urls http://niub-etcd-3:2379 \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster niub1=http://niub-etcd-1:2380,niub2=http://niub-etcd-2:2380,niub3=http://niub-etcd-3:2380 \
-initial-cluster-state new  >> /niub/etcd_log/etcd.log 2>&1 &

##防火墙 在这3台node服务器开放2379、2380端口,命令:

iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 2379 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 2380 -j ACCEPT

##haproxy配置 haproxy配置过程略 编辑/etc/haproxy/haproxy.cfg文件,增加:

frontend etcd
    bind 10.10.0.14:2379
    mode tcp
    option tcplog
    default_backend etcd
    log 127.0.0.1 local3
    backend etcd
    balance roundrobin
    fullconn 1024
    server etcd1 10.10.0.11:2379 check port 2379 inter 300 fall 3
    server etcd2 10.10.0.12:2379 check port 2379 inter 300 fall 3
    server etcd3 10.10.0.13:2379 check port 2379 inter 300 fall 3

##检查etcd服务运行状态 使用curl访问:

curl http://10.10.0.14:2379/v2/members

返回以下结果为正常(3个节点):

{
  "members": [
    {
      "id": "1f890e0c67371d24",
      "name": "niub1",
      "peerURLs": [
        "http://niub-etcd-1:2380"
      ],
      "clientURLs": [
        "http://niub-etcd-1:2379"
      ]
    },
    {
      "id": "b952ccccefdd8a93",
      "name": "niub3",
      "peerURLs": [
        "http://niub-etcd-3:2380"
      ],
      "clientURLs": [
        "http://niub-etcd-3:2379"
      ]
    },
    {
      "id": "d6dbdb24d5bfc20f",
      "name": "niub2",
      "peerURLs": [
        "http://niub-etcd-2:2380"
      ],
      "clientURLs": [
        "http://niub-etcd-2:2379"
      ]
    }
  ]
}

##etcd备份 使用etcd自带命令etcdctl进行etc备份,脚本如下:

#!/bin/bash
 
date_time=`date +%Y%m%d`
etcdctl backup --data-dir /usr/local/etcd/niub3.etcd/ --backup-dir /niub/etcd_backup/${date_time}
 
find /niub/etcd_backup/ -ctime +7 -exec rm -r {} \;

##其他

###查看版本命令

curl http://10.10.0.14:2379/version
标签: etcd
共有 人打赏支持
粉丝 15
博文 16
码字总数 10690
×
张富贵
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: