Etcd v3.3.10 版本部署(3台集群)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Etcd v3.3.10 版本部署(3台集群)相关的知识,希望对你有一定的参考价值。
Etcd v3.3.10 版本部署(3台集群)
规划
etcd01 | etcd02 | etc03 |
---|---|---|
192.168.100.100 | 192.168.100.101 | 192.168.100.102 |
软件包
安装证书生成工具cfssl:
mkdir /data/ssl -p
cd /data/
wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
wget https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64
chmod +x cfssl_linux-amd64 cfssljson_linux-amd64 cfssl-certinfo_linux-amd64
mv cfssl_linux-amd64 /usr/local/bin/cfssl
mv cfssljson_linux-amd64 /usr/local/bin/cfssljson
mv cfssl-certinfo_linux-amd64 /usr/bin/cfssl-certinfo
cd /data/ssl/
二进制包下载地址:https://github.com/etcd-io/etcd/releases/tag/v3.3.10
下载 etcd-v3.3.10-linux-amd64.tar.gz
生成key
mkdir /data/ssl/etcd
cd /data/ssl/etcd
vim etcd.sh
# etcd
# cat ca-config.json
cat > ca-config.json <<EOF
{
"signing": {
"default": {
"expiry": "87600h"
},
"profiles": {
"www": {
"expiry": "87600h",
"usages": [
"signing",
"key encipherment",
"server auth",
"client auth"
]
}
}
}
}
EOF
# cat ca-csr.json
cat > ca-csr.json <<EOF
{
"CN": "etcd CA",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"L": "Beijing",
"ST": "Beijing"
}
]
}
EOF
# cat server-csr.json
cat > server-csr.json <<EOF
{
"CN": "etcd",
"hosts": [
"192.168.100.100",
"192.168.100.101",
"192.168.100.102"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"L": "BeiJing",
"ST": "BeiJing"
}
]
}
EOF
sh etcd.sh
cfssl gencert -initca ca-csr.json | cfssljson -bare ca -
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=www server-csr.json | cfssljson -bare server
# ls *pem
ca-key.pem ca.pem server-key.pem server.pem
部署
3个节点 都操作
mkdir /data/src/
cd /data/src/
mkdir /opt/etcd/{bin,cfg,ssl} -p
tar xf etcd-v3.3.10-linux-amd64.tar.gz
mv etcd-v3.3.10-linux-amd64/{etcd,etcdctl} /opt/etcd/bin/
vim /opt/etcd/cfg/etcd
# 3台机器 ETCD_NAME 名字不一样 本机IP不一样
#[Member]
ETCD_NAME="etcd01"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.100.100:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.100.100:2379"
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.100.100:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.100.100:2379"
ETCD_INITIAL_CLUSTER="etcd01=https://192.168.100.100:2380,etcd02=https://192.168.100.101:2380,etcd03=https://192.168.100.102:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
* ETCD_NAME 节点名称
* ETCD_DATA_DIR 数据目录
* ETCD_LISTEN_PEER_URLS 集群通信监听地址
* ETCD_LISTEN_CLIENT_URLS 客户端访问监听地址
* ETCD_INITIAL_ADVERTISE_PEER_URLS 集群通告地址
* ETCD_ADVERTISE_CLIENT_URLS 客户端通告地址
* ETCD_INITIAL_CLUSTER 集群节点地址
* ETCD_INITIAL_CLUSTER_TOKEN 集群Token
* ETCD_INITIAL_CLUSTER_STATE 加入集群的当前状态,new是新集群,existing表示加入已有集群
vim /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/etcd/cfg/etcd
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
cp /data/ssl/etcd/ca*pem /opt/etcd/ssl/
cp /data/ssl/etcd/server*pem /opt/etcd/ssl/
scp /data/ssl/etcd/ca*pem [email protected]:/opt/etcd/ssl/
scp /data/ssl/etcd/ca*pem [email protected]:/opt/etcd/ssl/
scp /data/ssl/etcd/server*pem [email protected]:/opt/etcd/ssl/
scp /data/ssl/etcd/server*pem [email protected]:/opt/etcd/ssl/
## 最后再启动
systemctl enable etcd
systemctl start etcd
检查
查看集群状态:
cd /data/ssl/etcd/
/opt/etcd/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.100.100:2379,https://192.168.100.101:2379,https://192.168.100.102:2379" cluster-health
member 65f49728d3d54972 is healthy: got healthy result from https://192.168.100.100:2379
member d94ba21c17c75ffb is healthy: got healthy result from https://192.168.100.101:2379
member dc51f874259f7894 is healthy: got healthy result from https://192.168.100.102:2379
cluster is healthy
# 如果有问题第一步先看日志:/var/log/message 或 journalctl -u etcd
以上是关于Etcd v3.3.10 版本部署(3台集群)的主要内容,如果未能解决你的问题,请参考以下文章