etcd集群部署
程序员文章站
2022-07-13 22:38:27
...
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
转载于:https://my.oschina.net/deepblue/blog/529390
上一篇: etcd集群部署
下一篇: WPF 在MVVM模式下弹出子窗体的方式