标签:gre member failure server clu roo root service enable
第一步:先拉取etcd二进制压缩包
wget https://github.com/coreos/etcd/releases/download/v3.3.2/etcd-v3.3.2-linux-amd64.tar.gz
//解压压缩包
tar zxvf etcd-v3.3.2-linux-amd64.tar.gz
第二步:建立一个文件,分别存放bin文件,cfg配置文件,ssl验证文件
mkdir /opt/kubernetes/{bin,cfg,ssl}
//然后将etcd,etcdctl移动到bin目录下
mv etcd-v3.3.2-linux-amd64/etcd /opt/kubernetes/bin/
mv etcd-v3.3.2-linux-amd64/etcdctl /opt/kubernetes/bin/
第三步:创建etcd.service配置文件
vi /usr/lib/systemd/system/etcd.service
//内容为
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
EnvironmentFile=-/opt/kubernetes/cfg/etcd
ExecStart=/opt/kubernetes/bin/etcd --name=${ETCD_NAME} --data-dir=${ETCD_DATA_DIR} --listen-peer-urls=${ETCD_LISTEN_PEER_URLS} --listen-client-urls=${ETCD_LISTEN_CLIENT_URLS},http://127.0.0.1:2379 --advertise-client-urls=${ETCD_ADVERTISE_CLIENT_URLS} --initial-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} --initial-cluster=${ETCD_INITIAL_CLUSTER} --initial-cluster-token=${ETCD_INITIAL_CLUSTER} --initial-cluster-state=new --cert-file=/opt/kubernetes/ssl/server.pem --key-file=/opt/kubernetes/ssl/server-key.pem --peer-cert-file=/opt/kubernetes/ssl/server.pem --peer-key-file=/opt/kubernetes/ssl/server-key.pem --trusted-ca-file=/opt/kubernetes/ssl/ca.pem --peer-trusted-ca-file=/opt/kubernetes/ssl/ca.pem
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
第四步:创建etcd配置文件
#[Member]
ETCD_NAME="etcd01" //节点名字
ETCD_DATA_DIR="/var/lib/etcd/default.etcd" //数据目录
ETCD_LISTEN_PEER_URLS="https://172.16.163.131:2380" 当前节点的ip地址
ETCD_LISTEN_CLIENT_URLS="https://172.16.163.131:2379"
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://172.16.163.131:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://172.16.163.131:2379"
ETCD_INITIAL_CLUSTER="etcd01=https://172.16.163.131:2380,etcd02=https://172.16.163.130:2380,etcd03=https://172.16.163.129:2380" //集群所有的节点的ip地址
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
第五步:将TLS证书生成的pem文件,复制到/opt/kubernetes/ssl/目录下
cp ssl/server*pem ssl/ca*.pem /opt/kubernetes/ssl/
第六步:启动etcd
systemctl daemon-reload
systemctl start etcd
systemctl enable etcd
第七步:查看etcd是否启动
ps -ef |grep etcd
第八步:设置互信免密登录
//生成秘钥和私钥
ssh-keygen
//将秘钥和私钥复制到其他节点,这样就可以相互免密登录了
ssh-copy-id root@172.16.163.130
第九步:将所有在master节点上的配置文件都拷贝到node节点上,都使用同样的配置文件,不同的地方在于有些配置文件的内容不同。这些操作只需要在master做就可以。
scp -r /opt/kubernetes/bin/ root@172.16.163.130:/opt/kubernetes/
//将etcd配置文件拷贝到node节点
scp -r /opt/kubernetes/cfg/ root@172.16.163.130:/opt/kubernetes/
scp -r /opt/kubernetes/ssl/ root@172.16.163.130:/opt/kubernetes/
//将etcd.service配置文件也要拷贝到node节点
scp /usr/lib/systemd/system/etcd.service root@172.16.163.130:/usr/lib/systemd/system
第十步:因为etcd,etcdctl命令会常使用,所以将他们加入到PATH路径中
将etcd命令加入PATH
vi /etc/profile
在最后一行加入:PATH=$PATH:/opt/kubernetes/bin
让配置生效
source /etc/profile
第十一步:检查集群搭建成功与否
//执行这个命令需要进入到/opt/kubernetes/ssl目录,因为需要使用TLS证书
etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://172.16.163.130:2379,https://172.16.163.129:2379,https://172.16.163.131:2379" cluster-health
或者
etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem cluster-health
//输出这个表示成功
member 204f1af770aff3d9 is healthy: got healthy result from https://172.16.163.129:2379
member 81e41daa4ea73cbc is healthy: got healthy result from https://172.16.163.130:2379
member d2349ea355902626 is healthy: got healthy result from https://172.16.163.131:2379
cluster is healthy
报错:
这个报错是由数据目录引起的,只需要删除这个数据目录就可以了。
rm -rf /var/lib/etcd/default.etcd/
到这里错误处理完毕,etcd集群搭建完成。
标签:gre member failure server clu roo root service enable
原文地址:https://www.cnblogs.com/jasonboren/p/11483898.html