企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
一、服务管理脚本在哪儿 1、centos7 /usr/lib/systemd/system 2、centos6 /etc/rc.d/rcN.d 二、下载etcd https://github.com/etcd-io/etcd/releases 链接:https://pan.baidu.com/s/13-e8zYVNKgz0g2Q67Xjvag?pwd=h8o5 提取码:h8o5 --来自百度网盘超级会员V5的分享 三、 上传etcd.tar.gz 四、解压 ``` tar -xzvf etcd.tar.gz ``` 五、 etcd.service ``` [Unit] Description=Etcd Server After=network.target After=network-online.target Wants=network-online.target [Service] Type=notify EnvironmentFile=/opt/etcd/cfg/etcd.conf ExecStart=/opt/etcd/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_TOKEN} \         --initial-cluster-state=new \   --cert-file=/opt/etcd/ssl/server.pem \         --key-file=/opt/etcd/ssl/server-key.pem \         --peer-cert-file=/opt/etcd/ssl/server.pem \         --peer-key-file=/opt/etcd/ssl/server-key.pem \         --trusted-ca-file=/opt/etcd/ssl/ca.pem \         --peer-trusted-ca-file=/opt/etcd/ssl/ca.pem Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target ``` 上面在启动参数中指定了etcd的工作目录和数据目录是/data/etcd --cert-file和--key-file分别指定etcd的公钥证书和私钥 --peer-cert-file和--peer-key-file分别指定了etcd的Peers通信的公钥证书和私钥。 --trusted-ca-file指定了客户端的CA证书 --peer-trusted-ca-file指定了Peers的CA证书 --initial-cluster-state new表示这是新初始化集群,--name指定的参数值必须在--initial-cluster中 六、移动文件 ``` mv etcd /opt mv etcd.service /usr/lib/systemd/system ``` 七、 vi /opt/etcd/cfg/etcd.conf ``` #[Member] ETCD_NAME="etcd-1" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https://192.168.72.166:2380" #和其它etcd同步数据 ETCD_LISTEN_CLIENT_URLS="https://192.168.72.166:2379" #前端发送数据 #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.72.166:2380" ETCD_ADVERTISE_CLIENT_URLS="https://192.168.72.166:2379" ETCD_INITIAL_CLUSTER="etcd-1=https://192.168.72.166:2380,etcd-2=https://192.168.72.168:2380,etcd-3=https://192.168.72.169:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new" ``` 八、拷贝文件 TLS/etcd/ssl/{ca,server,server-key}.pem 进入到TLS/etcd文件下进行拷贝文件 ``` cp {ca,server,server-key}.pem /opt/etcd/ssl/ ``` 这里的TLS/etcd十我们离线安装SSL证书时上传的文件, /opt/etcd/ssl/是文件etcd.service中指定的目录 ![](https://img.kancloud.cn/22/1b/221b457c89c76671b07ba1e05a6636da_554x143.png) 九、拷贝其它机器上 ``` scp -r /opt/etcd root@192.168.72.168:/opt scp -r /opt/etcd root@192.168.72.169:/opt scp  /usr/lib/systemd/system/etcd.service root@192.168.72.168:/usr/lib/systemd/system scp  /usr/lib/systemd/system/etcd.service root@192.168.72.169:/usr/lib/systemd/system ``` 十、修改其它配置文件 ``` vi /opt/etcd/cfg/etcd.conf ``` 位置分别为两台node节点 1、第二台机器配置文件 ``` #[Member] ETCD_NAME="etcd-2" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https://192.168.254.203:2380" ETCD_LISTEN_CLIENT_URLS="https://192.168.254.203:2379" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.254.203:2380" ETCD_ADVERTISE_CLIENT_URLS="https://192.168.254.203:2379" ETCD_INITIAL_CLUSTER="etcd-1=https://192.168.254.201:2380,etcd-2=https://192.168.254.203:2380,etcd-3=https://192.168.254.204:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new" ``` 2、第三台配置文件 ``` #[Member] ETCD_NAME="etcd-3" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https://192.168.254.204:2380" ETCD_LISTEN_CLIENT_URLS="https://192.168.254.204:2379" #[Clustering] ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.254.204:2380" ETCD_ADVERTISE_CLIENT_URLS="https://192.168.254.204:2379" ETCD_INITIAL_CLUSTER="etcd-1=https://192.168.254.201:2380,etcd-2=https://192.168.254.203:2380,etcd-3=https://192.168.254.204:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new" ``` 十一、 重启etcd ``` systemctl daemon-reload systemctl start etcd systemctl enable etcd ``` 十二、 日志 ``` tail /var/log/messages tail -f /var/log/messages ``` 十三、验证 ``` /opt/etcd/bin/etcdctl --ca-file=/opt/etcd/ssl/ca.pem --cert-file=/opt/etcd/ssl/server.pem --key-file=/opt/etcd/ssl/server-key.pem --endpoints="https://192.168.72.166:2379,https://192.168.72.168:2379,https://192.168.72.169:2379" cluster-health member 37f20611ff3d9209 is healthy: got healthy result from https://192.168.254.201:2379 member b10f0bac3883a232 is healthy: got healthy result from https://192.168.254.202:2379 member b46624837acedac9 is healthy: got healthy result from https://192.168.254.203:2379 cluster is healthy ``` 在主节点验证 ![](https://img.kancloud.cn/4f/cf/4fcf2ecfa7d7526610020f3b306652da_1674x122.png) ![](https://img.kancloud.cn/c1/ba/c1ba4f2e2e22adb99ff07efb73d35121_1456x162.png)