部署环境三台机子: 10.42.5.187 10.42.5.188 10.42.5.189
在10.42.5.187机子上部署:
4.进入/etc/etcd-v3.3.2,并创建配置文件etcd.conf,内容: name: etcd-1 data-dir: /etc/etcd-v3.3.2/data listen-client-urls: http://0.0.0.0:2379 advertise-client-urls: http://10.42.5.187:2379 listen-peer-urls: http://0.0.0.0:2380 initial-advertise-peer-urls: http://10.42.5.187:2380 initial-cluster: etcd-1=http://10.42.5.187:2380,etcd-2=http://10.42.5.188:2380,etcd-3=http://10.42.5.189:2380 initial-cluster-token: etcd-cluster-my initial-cluster-state: new
注释:listen-client-urls: http://10.42.5.187:2379 会报错,所以直接用0.0.0.0; listen-peer-urls: http://10.42.5.187:2380 也会报错,所以直接用0.0.0.0; name:本member的名称; data-dir:存储的数据目录; listen-client-urls:用于监听客户端etcdctl或者curl连接;0.0.0.0表示监听本机所有地址; listen-peer-urls:用于监听集群中其它member的连接;0.0.0.0表示监听本机所有地址; advertise-client-urls: 本机地址, 用于通知客户端,客户端通过此IPs与集群通信; initial-advertise-peer-urls:本机地址,用于通知集群member,与member通信; initial-cluster:描述集群中所有节点的信息,描述每个节点名称、ip、端口,集群静态启动使用,本member根据此信息去联系其他member; initial-cluster-token:集群唯一标示; initial-cluster-state:集群状态,新建集群时候设置为new,若是想加入某个已经存在的集群设置为existing
5.设置etcd版本号,默认为2,我们安装的版本为3.3.2,所以此处设置为3 默认示例: [root@forimg system]# etcdctl NAME: etcdctl - A simple command line client for etcd.
WARNING: Environment variable ETCDCTL_API is not set; defaults to etcdctl v2. Set environment variable ETCDCTL_API=3 to use v3 API or ETCDCTL_API=2 to use v2 API.
USAGE: etcdctl [global options] command [command options] [arguments...]
VERSION: 3.3.2
在 文件~/.bashrc中加入一行改为3 export ETCDCTL_API=3
[Service] Type=notify WorkingDirectory=/etc/etcd-v3.3.2
ExecStart=/etc/etcd-v3.3.2/etcd --config-file /etc/etcd-v3.3.2/etcd.conf Restart=on-failure LimitNOFILE=65536
[Install] WantedBy=multi-user.target
注释: WorkingDirectory和ExecStart填写对应的目录和启动命令。
6.10.42.5.188,10.42.5.189部署如同上面步骤,只是将步骤4里面ip改为自己ip即可。
———————————————— 常用指令: etcd --version etcdctl member list
etcdctl endpoint health -- etcdctl put key1 value1 etcdctl get key1 etcdctl get foo --print-value-only
etcdctl get --prefix foo etcdctl del key
[root@pipeline-nj-2 etcd-v3.3.2]# etcdctl lease grant 30 lease 3c27623e1704580d granted with TTL(30s)
[root@pipeline-nj-2 etcd-v3.3.2]# etcdctl put key5 value5 --lease=3c27623e1704580d OK [root@pipeline-nj-2 etcd-v3.3.2]# etcdctl get key5 key5 value5
[root@pipeline-nj-2 etcd-v3.3.2]# etcdctl lease keep-alive 3c27623e1704580d lease 3c27623e1704580d keepalived with TTL(30)
[root@pipeline-nj-2 etcd-v3.3.2]# etcdctl lease revoke 3c27623e1704580d lease 3c27623e1704580d revoked