etcd 是基于 Raft 的分布式 key-value 存儲(chǔ)系統(tǒng),由 CoreOS 開(kāi)發(fā),常用于服務(wù)發(fā)現(xiàn)、共享配置以及并發(fā)控制(如 leader 選舉、分布式鎖等)。kubernetes 使用 etcd 存儲(chǔ)所有運(yùn)行數(shù)據(jù)。
創(chuàng)新互聯(lián)主營(yíng)雨花網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,手機(jī)APP定制開(kāi)發(fā),雨花h5微信小程序開(kāi)發(fā)搭建,雨花網(wǎng)站營(yíng)銷推廣歡迎雨花等地區(qū)企業(yè)咨詢所有操作都是在devops機(jī)器上操作,將相關(guān)腳本編輯好,然后通過(guò)ansible 腳本模塊統(tǒng)一執(zhí)行。
#################### Variable parameter setting ######################
ETCD_INSTALL_PATH="/data/apps/k8s/etcd"
ETCD_BIN_DIR="${ETCD_INSTALL_PATH}/bin"
ETCD_DATA_DIR="${ETCD_INSTALL_PATH}/data"
ETCD_WAL_DIR="${ETCD_INSTALL_PATH}/wal"
N01="master-k8s-n01=https://10.10.10.22:2380"
N02="master-k8s-n02=https://10.10.10.23:2380"
N03="master-k8s-n03=https://10.10.10.24:2380"
ETCD_ENPOIDTS="$N01,$N02,$N03"
CA_PATH="/etc/k8s/ssl"
SOFTWARE="/root/software"
VERSION=v3.3.13
PACKAGE="etcd-${VERSION}-linux-amd64.tar.gz"
HOSTNAME=`hostname`
DOWNLOAD_URL="https://github.com/devops-apps/download/raw/master/etcd/${PACKAG}"
ETH_INTERFACE=eth2
LISTEN_IP=$(ifconfig | grep -A 1 ${ETH_INTERFACE} |grep inet |awk '{print $2}')
USER=k8s
登錄devops訪問(wèn)etcd 的 release 頁(yè)面下載最新版本的發(fā)布包并通過(guò)ansible同步到三個(gè)master三個(gè)節(jié)點(diǎn)/root/software目錄下:
wget $DOWNLOAD_URL -P $SOFTWARE
在devops主機(jī)上使用ansible分別對(duì)三個(gè)master節(jié)點(diǎn)執(zhí)行以下操作:
### 1.Check if the install directory exists.
if [ ! -d $ETCD_BIN_DIR ]; then
mkdir -p $ETCD_BIN_DIR
mkdir -p $ETCD_DATA_DIR
mkdir -p $ETCD_WAL_DIR
fi
### 2.Install etcd binary of kubernetes.
if [ ! -f "$SOFTWARE/etcd-${VERSION}-linux-amd64.tar.gz" ]; then
sudo wget $DOWNLOAD_URL -P $SOFTWARE >>/tmp/install.log 2>&1
fi
cd $SOFTWARE && tar -xzf etcd-${VERSION}-linux-amd64.tar.gz -C ./
cp -fp etcd-${VERSION}-linux-amd64/etcd* $ETCD_BIN_DIR
ln -sf $ETCD_BIN_DIR/{etcd,etcdctl} /usr/local/bin
sudo chmod -R 755 $ETCD_INSTALL_PATH
sudo chown -R $USER:$USER $ETCD_INSTALL_PATH
cat >/usr/lib/systemd/system/etcd.service<<EOF
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
User=${USER}
WorkingDirectory=${ETCD_DATA_DIR}
# set GOMAXPROCS to number of processors
ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) ${ETCD_BIN_DIR}/etcd \\
--name=${HOSTNAME} \\
--data-dir=${ETCD_DATA_DIR} \\
--wal-dir=${ETCD_WAL_DIR} \\
--cert-file=${CA_PATH}/etcd.pem \\
--key-file=${CA_PATH}/etcd-key.pem \\
--trusted-ca-file=${CA_PATH}/ca.pem \\
--peer-cert-file=${CA_PATH}/etcd.pem \\
--peer-key-file=${CA_PATH}/etcd-key.pem \\
--peer-trusted-ca-file=${CA_PATH}/ca.pem \\
--peer-client-cert-auth=true \\
--client-cert-auth=true \\
--listen-peer-urls=https://${LISTEN_IP}:2380 \\
--initial-advertise-peer-urls=https://${LISTEN_IP}:2380 \\
--listen-client-urls=https://${LISTEN_IP}:2379,https://127.0.0.1:2379 \\
--advertise-client-urls=https://${LISTEN_IP}:2379 \\
--initial-cluster-token=etcd-cluster-0 \\
--initial-cluster=${ETCD_ENPOIDTS} \\
--initial-cluster-state=new \\
--auto-tls=true \\
--auto-compaction-mode=periodic \\
--auto-compaction-retention=1 \\
--max-request-bytes=33554432 \\
--quota-backend-bytes=6442450944 \\
--heartbeat-interval=250 \\
--election-timeout=2000 \\
--peer-auto-tls=true"
Restart=on-failure
RestartSec=5
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
systemctl etcd.service start
systemctl status etcd|grep Active
確保狀態(tài)為 active (running),否則查看日志,確認(rèn)原因:
sudo journalctl -u etcd
驗(yàn)證etcd服務(wù)狀態(tài)
ETCDCTL_API=3 etcdctl \
--endpoints=${ETCD_ENPOIDTS} \
--cacert=/etc/k8s/ssl/ca.pem \
--cert=/etc/k8s/ssl/etcd.pem \
--key=/etc/k8s/ssl/etcd-key.pem endpoint health
當(dāng)輸出值為以下?tīng)顟B(tài)即為正常:
https://10.10.10.22:2379 is healthy: successfully committed proposal: took = 3.693346ms
https://10.10.10.23:2379 is healthy: successfully committed proposal: took = 2.80687ms
https://10.10.10.24:2379 is healthy: successfully committed proposal: took = 4.493037ms
查看當(dāng)前l(fā)eader
ETCDCTL_API=3 etcdctl \
--endpoints=${ETCD_ENPOIDTS} \
--cacert=/etc/k8s/ssl/ca.pem \
--cert=/etc/k8s/ssl/etcd.pem \
--key=/etc/k8s/ssl/etcd-key.pem endpoint status
輸出:
https://10.10.10.22:2379, 641670f7677ceff, 3.3.13, 2.9 MB, false, 2, 6198986
https://10.10.10.23:2379, ce37122364c277fa, 3.3.13, 2.9 MB, true, 2, 6198986
https://10.10.10.24:2379, 4d1003897626ccde, 3.3.13, 2.9 MB, false, 2, 6198986
到這里,整個(gè)etcd集群就部署完成,關(guān)于更多的etcd操作可以閱讀etcd官方文檔,部署好etcd數(shù)據(jù)庫(kù),開(kāi)部署kubernetes master節(jié)點(diǎn)相關(guān)組件,請(qǐng)參考:kubernetes集群安裝指南:apiserver節(jié)點(diǎn)組件部署,關(guān)于etcd腳本請(qǐng)從此處獲取;
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站欄目:kubernetes集群安裝指南:etcd集群部署-創(chuàng)新互聯(lián)
URL分享:http://muchs.cn/article28/phgjp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、虛擬主機(jī)、品牌網(wǎng)站制作、企業(yè)建站、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容