AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
**创建高可用etcd集群** kubernetes 使用 etcd 存储所有数据,这里使用3台机器搭建高可用etcd集群。etcd集群使用raft协议维护集群状态,保证任意时间都只有1台主节点,主节点负责写入数据,从节点提供查询,具体工作原理自行查询,太多了介绍不完。 **TLS证书** etcd集群内部通信使用双向TLS认证,每个节点都作为服务端提供访问接口,而集群内不同节点间通信每个节点又作为客户端,和这里调用之前创建好的etcd证书,此证书即作为服务端证书又作为客户端证书使用。 使用到的证书:etcd.pem,etcd-key.pem,ca.pem etcd节点:192.168.50.101,192.168.50.102,192.168.50.1 **3台节点同时安装** **下载etcd安装文件** [项目地址](https://github.com/coreos/etcd/releases) k8s1.10发布时官方推荐的是3.1.12版本,这里使用较新的版本也是可以支持的, ~~~ cd && wget https://github.com/coreos/etcd/releases/download/v3.2.21/etcd-v3.2.21-linux-amd64.tar.gz tar zxvf etcd-v3.2.21-linux-amd64.tar.gz mv etcd-v3.2.21-linux-amd64/etcd* /usr/local/bin ~~~ **创建 etcd 的service文件** ~~~ mkdir /var/lib/etcd vim /lib/systemd/system/etcd.service [Unit] Description=Etcd Server After=network.target After=network-online.target Wants=network-online.target Documentation=https://github.com/coreos [Service] Type=notify WorkingDirectory=/var/lib/etcd/ EnvironmentFile=-/etc/etcd/etcd.conf ExecStart=/usr/local/bin/etcd \ --name ${ETCD_NAME} \ --cert-file=/etc/kubernetes/ssl/etcd.pem \ --key-file=/etc/kubernetes/ssl/etcd-key.pem \ --peer-cert-file=/etc/kubernetes/ssl/etcd.pem \ --peer-key-file=/etc/kubernetes/ssl/etcd-key.pem \ --trusted-ca-file=/etc/kubernetes/ssl/ca.pem \ --peer-trusted-ca-file=/etc/kubernetes/ssl/ca.pem \ --initial-advertise-peer-urls ${ETCD_INITIAL_ADVERTISE_PEER_URLS} \ --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-cluster-token=etcd-cluster \ --initial-cluster infra1=https://192.168.50.101:2380,infra2=https://192.168.50.102:2380,infra3=https://192.168.50.1:2380 \ --initial-cluster-state new \ --data-dir=/var/lib/etcd Restart=on-failure RestartSec=5 LimitNOFILE=65536 [Install] WantedBy=multi-user.target ~~~ --initial-cluster 注意改成3台etcd的ip,其他配置不用改动。 已经将所有需要改动的配置放到了下面的环境变量文件中了。 **创建环境变量文件** ~~~ mkdir /etc/etcd vim /etc/etcd/etcd.conf #[member] ETCD_NAME=infra1 ETCD_LISTEN_PEER_URLS="https://192.168.50.101:2380" ETCD_LISTEN_CLIENT_URLS="https://192.168.50.101:2379" #[cluster] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.50.101:2380" ETCD_ADVERTISE_CLIENT_URLS="https://192.168.50.101:2379" ~~~ ETCD_NAME改成infra2 和 infra3 4个URLS改成每个节点的ip **启动 etcd 服务** ~~~ systemctl daemon-reload systemctl start etcd systemctl enable etcd ~~~ 注意:3台etcd要同时启动,每台etcd启动时会先检测集群的其他主机是否正常通讯并发起选举投票,逐个启动会启动失败。 注意:保证**系统初始化操作**章节的iptables规则已经生效,不然端口是被屏蔽的无法访问。 **查看服务** ~~~ systemctl status etcd #查看服务是否成功启动 journalctl -u etcd #查看日志是否有错误 ~~~ **配置etcdctl** k8s1.10默认是使用api v3版本操作etcd,而etcdctl默认是使用v2版本,两个版本差别很大,用v2版本无法查询到v3版本写入的数据,这里设置etcdctl使用v3版本。 ~~~ etcdctl -v #当前API版本为v2 echo "export ETCDCTL_API=3" >> /etc/profile source /etc/profile etcdctl v #API已经是v3版本 ~~~ **自定义etcdssl命令** ~~~ alias etcdssl='etcdctl --endpoints=https://192.168.50.101:2379,https://192.168.50.102:2379,https://192.168.50.1:2379 --cacert=/etc/kubernetes/ssl/ca.pem --cert=/etc/kubernetes/ssl/etcd.pem --key=/etc/kubernetes/ssl/etcd-key.pem' ~~~ etcdctl命令每次使用需要指定证书和服务器地址,为方便使用这里自定义一个带有参数的命令,以后使用etcdssl即可操作etcd,为保证下次登录仍然生效可写入到.bashrc中。 ~~~ etcdssl endpoint health #全部healthy https://172.16.50.3:2379 is healthy: successfully committed proposal: took = 1.28671ms https://172.16.50.2:2379 is healthy: successfully committed proposal: took = 1.901236ms https://172.16.50.1:2379 is healthy: successfully committed proposal: took = 1.554307ms etcdssl endpoint status #true为主节点 https://172.16.50.1:2379, dab1ee555a126d99, 3.2.11, 4.5 MB, false, 52, 27516556 https://172.16.50.2:2379, 2012b63f34de469c, 3.2.11, 4.5 MB, false, 52, 27516556 https://172.16.50.3:2379, f4bfef68d13648c1, 3.2.11, 4.5 MB, true, 52, 27516556 ~~~ 更多etcd操作查看 etcdssl -h