在上一篇文章里我们主要介绍docker的安装,这里我们主要介绍安装etcd集群安装。这里我们采用下载二进制binary制作linux systemd的方式安装,安装完成之后开启开启双向ssl验证。另外etcd集群的安装方式主要有3种,静态的集群安装(就是预先知道有集群中多少台etcd,在每一台etcd里都配置指向其它的etcd来形成集群)。基于已经存在的etcd利用服务发现机制安装。基于dns的服务发现机制安装。这里我们以学习为目的采用第一种方式安装,当然对于应用环境还是基于服务发现的机制比较好(这里我们机器有限,就不自己搭建一个bind dns服务来做服务发现安装了)。
创建etcd用户和用户组
代码语言:javascript复制cat /etc/group|grep etcd
cat /etc/passwd|grep etcd
groupadd etcd
useradd -c "This is etcd daemon account" -g etcd -s /sbin/nologin -r etcd
cat /etc/group|grep etcd
cat /etc/passwd|grep etcd
创建etcd配置目录
代码语言:javascript复制mkdir -p /etc/etcd
mkdir -p /opt/sw/etcd/data
mkdir -p /var/lib/etcd
chown -R etcd:etcd /etc/etcd
chown -R etcd:etcd /opt/sw/etcd
chown -R etcd:etcd /var/lib/etcd
下载并解压etcd:
注意这里在github下载etcd(etcd-v3.3.11-linux-amd64.tar.gz)。
代码语言:javascript复制mkdir -p /opt/sw/etcd/install
cd /opt/sw/etcd/install/
wget https://github.com/etcd-io/etcd/releases/download/v3.3.11/etcd-v3.3.11-linux-amd64.tar.gz
tar -xzvf etcd-v3.3.11-linux-amd64.tar.gz
cd /opt/sw/etcd/install/etcd-v3.3.11-linux-amd64/
ls
cp ./etcd /usr/bin/
cp ./etcdctl /usr/bin/
打开etcd访问端口2380和2379:
其中2380用于etcd集群内部通信,2379为etcd的服务端口
代码语言:javascript复制firewall-cmd --list-all
firewall-cmd --permanent --zone=public --add-port=2379/tcp
firewall-cmd --permanent --zone=public --add-port=2380/tcp
firewall-cmd --reload
firewall-cmd --list-all
创建etcd配置文件
这里面会开启etcd的双向ssl认证,不管是etcd集群内部通信还是etcd client和etcd集群通信。所以请提前制作好etcd server证书和etcd client证书(可以参考以前文章中制作docker的cert),并且copy到相应的配置目录里(这里是/etc/etcd)
代码语言:javascript复制touch /etc/etcd/etcd.conf
chown -R etcd:etcd /etc/etcd
cat > /etc/etcd/etcd.conf << EOF
#[Member]
ETCD_DATA_DIR="/opt/sw/etcd/data"
ETCD_LISTEN_PEER_URLS="https://172.20.11.43:2380"
ETCD_LISTEN_CLIENT_URLS="https://172.20.11.43:2379,http://127.0.0.1:2379"
ETCD_NAME="etcd_node_3"
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://172.20.11.43:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://172.20.11.43:2379"
ETCD_INITIAL_CLUSTER="etcd_node_1=https://172.20.11.41:2380,etcd_node_2=https://172.20.11.42:2380,etcd_node_3=https://172.20.11.43:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-token"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_ENABLE_V2="true"
#[Security]
ETCD_CERT_FILE="/etc/etcd/etcd-server.crt"
ETCD_KEY_FILE="/etc/etcd/etcd-server.key"
ETCD_CLIENT_CERT_AUTH="true"
ETCD_TRUSTED_CA_FILE="/etc/etcd/ca.crt"
ETCD_PEER_CERT_FILE="/etc/etcd/etcd-client.crt"
ETCD_PEER_KEY_FILE="/etc/etcd/etcd-client.key"
ETCD_PEER_CLIENT_CERT_AUTH="true"
ETCD_PEER_TRUSTED_CA_FILE="/etc/etcd/ca.crt"
EOF
source /etc/etcd/etcd.conf
创建etcd systemd unit文件
代码语言:javascript复制touch /usr/lib/systemd/system/etcd.service
cat > /usr/lib/systemd/system/etcd.service << EOF
[Unit]
Description=Etcd Server
After=network.target network-online.target
Wants=network-online.target
[Service]
Type=notify
WorkingDirectory=/var/lib/etcd
EnvironmentFile=/etc/etcd/etcd.conf
User=etcd
ExecStartPre=source /etc/etcd/etcd.conf
ExecStart=/usr/bin/etcd
--name=${ETCD_NAME}
--enable-v2=${ETCD_ENABLE_V2}
--data-dir=${ETCD_DATA_DIR}
--listen-client-urls=${ETCD_LISTEN_CLIENT_URLS}
--listen-peer-urls=${ETCD_LISTEN_PEER_URLS}
--initial-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS}
--advertise-client-urls=${ETCD_ADVERTISE_CLIENT_URLS}
--initial-cluster=${ETCD_INITIAL_CLUSTER}
--initial-cluster-token=${ETCD_INITIAL_CLUSTER_TOKEN}
--initial-cluster-state=${ETCD_INITIAL_CLUSTER_STATE}
--cert-file=${ETCD_CERT_FILE}
--key-file=${ETCD_KEY_FILE}
--trusted-ca-file=${ETCD_TRUSTED_CA_FILE}
--client-cert-auth=${ETCD_CLIENT_CERT_AUTH}
--peer-cert-file=${ETCD_PEER_CERT_FILE}
--peer-key-file=${ETCD_PEER_KEY_FILE}
--peer-trusted-ca-file=${ETCD_PEER_TRUSTED_CA_FILE}
--peer-client-cert-auth=${ETCD_PEER_CLIENT_CERT_AUTH}
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
cat /usr/lib/systemd/system/etcd.service
导入ca证书导入到系统信任库:
把ca证书导入到linux系统,因为所有的cert都是用这个ca签发的,导入到系统信任库之后,系统就会trust所有由这个证书签发的证书了(例如这里的etcd server cert)。
代码语言:javascript复制cp /etc/etcd/ca.crt /etc/pki/ca-trust/source/anchors
update-ca-trust extract
设置etcd开机启动,start etcd服务并检查状态
代码语言:javascript复制systemctl enable etcd
systemctl start etcd
systemctl status etcd
在其它2台vm环境上重复上述步骤完成etcd集群安装,并health-check
代码语言:javascript复制etcdctl --ca-file /etc/etcd/ca.crt --cert-file /etc/etcd/etcd-client.crt --key-file /etc/etcd/etcd-client.key cluster-health
设置kay-value数据对,并测试
代码语言:javascript复制etcdctl --ca-file /etc/etcd/ca.crt --cert-file /etc/etcd/etcd-client.crt --key-file /etc/etcd/etcd-client.key set /test-node '{"name":"rodney.qin"}'
etcdctl --ca-file /etc/etcd/ca.crt --cert-file /etc/etcd/etcd-client.crt --key-file /etc/etcd/etcd-client.key get /test-node
目前先写到这里,在下一篇文章里我们开始介绍安装flannel。