etcd集群部署
1.环境准备
主机名 | IP地址 | CPU | 内存 | 硬盘 |
gztxy-prd-etcd01 | 192.168.1.1 | 2 | 4 | 100G |
gztxy-prd-etcd02 | 192.168.1.2 | 2 | 4 | 100G |
gztxy-prd-etcd03 | 192.168.1.3 | 2 | 4 | 100G |
2.安装并配置
yum安装
yum install etcd -y
配置
#etcd01 cat > /etc/etcd/etcd.conf <<EOF ETCD_NAME=etcd01 ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.11:2380" ETCD_INITIAL_CLUSTER="etcd001=http://192.168.1.11:2380,etcd002=http://192.168.1.12:2380,etcd003=http://192.168.1.13:2380" ETCD_INITIAL_CLUSTER_STATE="new" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-token" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.11:2379" EOF #etcd02 cat > /etc/etcd/etcd.conf <<EOF ETCD_NAME=etcd02 ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.12:2380" ETCD_INITIAL_CLUSTER="etcd001=http://192.168.1.11:2380,etcd002=http://192.168.1.12:2380,etcd003=http://192.168.1.13:2380" ETCD_INITIAL_CLUSTER_STATE="new" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-token" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.12:2379" EOF #etcd03 cat > /etc/etcd/etcd.conf <<EOF ETCD_NAME=etcd02 ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.13:2380" ETCD_INITIAL_CLUSTER="etcd001=http://192.168.1.11:2380,etcd002=http://192.168.1.12:2380,etcd003=http://192.168.1.13:2380" ETCD_INITIAL_CLUSTER_STATE="new" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-token" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.13:2379" EOF
启动并添加开机启动
systemctl start etcd systemctl enable etcd
3.测试
添加etcd数据并进行测试
#添加数据,添加一个behavior值的数据 etcdctl -C http://192.168.1.11:2379 set /behavior "[\"192.168.1.11:80\", \"192.168.1.12:80\"]" #查询数据 curl http://192.168.1.11:2379/v2/keys/behavior