因为最近在学习kubernetes,etcd做为kubernetes集群的主数据库,必须先启动。node
etcds实例名称 | IP地址 | Hostname |
---|---|---|
etcd 1 | 192.168.142.161 | kubernetes-node1.example.com |
etcd 2 | 192.168.142.162 | kubernetes-node2.example.com |
etcd 3 | 192.168.142.163 | kubernetes-node3.example.com |
vim /usr/lib/systemd/system/etcd.service 内容以下: [Unit] Description=Etcd Server After=network.target [Service] Type=simple WorkingDirectory=/var/lib/etcd/ EnvironmentFile=-/etc/etcd/etcd.conf #配置文件路径 ExecStart=/usr/bin/etcd Type=notify [Install] WantedBy=multi-user.target
vim /etc/etcd/etcd.conf # [member] ETCD_NAME=etcd1 #etcd实例名称 ETCD_DATA_DIR="/var/lib/etcd" #etcd数据保存目录 ETCD_LISTEN_CLIENT_URLS="http://192.168.142.161:2379,http://127.0.0.1:2379" #供外部客户端使用的url ETCD_ADVERTISE_CLIENT_URLS="http://192.168.142.161:2379,http://127.0.0.1:2379" #广播给外部客户端使用的url #[cluster] ETCD_LISTEN_PEER_URLS="http://192.168.142.161:2380" #集群内部通讯使用的URL ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.142.161:2380" #广播给集群内其余成员访问的URL ETCD_INITIAL_CLUSTER="etcd1=http://192.168.142.161:2380,etcd2=http://192.168.142.162:2380,etcd3=http://192.168.142.163:2380" #初始集群成员列表 ETCD_INITIAL_CLUSTER_STATE="new" #初始集群状态,new为新建集群 ETCD_INITIAL_CLUSTER_TOKEN="k8s-etcd-cluster" #集群的名称
启动etcd1服务器上的etcd服务。git
systemctl restart etcdetcd2和etcd3为加入k8s-etcd-cluster集群的实例,须要将其ETCD_INITIAL_CLUSTER_STATE设置为"exist"。etcd2的完整配置以下:github
# [member] ETCD_NAME=etcd2 ETCD_DATA_DIR="/var/lib/etcd" ETCD_LISTEN_CLIENT_URLS="http://192.168.142.162:2379,http://127.0.0.1:2379" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.142.162:2379,http://127.0.0.1:2379" #[cluster] ETCD_LISTEN_PEER_URLS="http://192.168.142.162:2380" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.142.162:2380" ETCD_INITIAL_CLUSTER="etcd1=http://192.168.142.161:2380,etcd2=http://192.168.142.162:2380,etcd3=http://192.168.142.163:2380" ETCD_INITIAL_CLUSTER_STATE="exist" ETCD_INITIAL_CLUSTER_TOKEN="k8s-etcd-cluster"
启动etcd2和etcd3服务器上的etcd服务。数据库
systemctl restart etcdvim
启动完成后,在任意节点执行etcdctl cluster-healthy命令来查看运行状态。服务器
使用etcdctl member list 来查看集群中的成员列表。学习
etcd集群搭建 下载二进制软件包 https://github.com/coreos/etcd/releases 解压 将两个执行文件复制到/usr/bin/ etcd和etcdctl文件复制到/usr/bin目录 配置etcd-1 vi /etc/etcd/etcd.yml name: etcd-1 data-dir: /var/lib/etcd listen-client-urls: http://163.44.167.92:2379,http://127.0.0.1:2379 advertise-client-urls: http://163.44.167.92:2379,http://127.0.0.1:2379 listen-peer-urls: http://163.44.167.92:2380 initial-advertise-peer-urls: http://163.44.167.92:2380 initial-cluster: etcd-1=http://163.44.167.92:2380,etcd-2=http://150.95.148.52:2380,etcd-3=http://133.130.122.48:2380 initial-cluster-token: etcd-cluster-token initial-cluster-state: new 配置etcd-2 vi /etc/etcd/etcd.yml name: etcd-2 data-dir: /var/lib/etcd listen-client-urls: http://150.95.148.52:2379,http://127.0.0.1:2379 advertise-client-urls: http://150.95.148.52:2379,http://127.0.0.1:2379 listen-peer-urls: http://150.95.148.52:2380 initial-advertise-peer-urls: http://150.95.148.52:2380 initial-cluster: etcd-1=http://163.44.167.92:2380,etcd-2=http://150.95.148.52:2380,etcd-3=http://133.130.122.48:2380 initial-cluster-token: etcd-cluster-token initial-cluster-state: new 配置etcd-3 name: etcd-3 data-dir: /var/lib/etcd listen-client-urls: http://133.130.122.48:2379,http://127.0.0.1:2379 advertise-client-urls: http://133.130.122.48:2379,http://127.0.0.1:2379 listen-peer-urls: http://133.130.122.48:2380 initial-advertise-peer-urls: http://133.130.122.48:2380 initial-cluster: etcd-1=http://163.44.167.92:2380,etcd-2=http://150.95.148.52:2380,etcd-3=http://133.130.122.48:2380 initial-cluster-token: etcd-cluster-token initial-cluster-state: new 最后启动 etcd --config-file=/etc/etcd/etcd.yml & 查当作员 etcdctl member list 每一个节点上执行查看健康状态 etcdctl cluster-health