1/ Lab Information: 03 node:
10.0.2.111 etcd1.mgiay.local etcd1
10.0.2.112 etcd2.mgiay.local etcd2
10.0.2.113 etcd3.mgiay.local etcd3
2/ Install ETCD on per node:
REF: https://www.mgiay.com/2020/10/how-to-install-etcd-from-source-code.html
3/ ETCD Cluster Initial:
#!/bin/bash
#/opt/script/etcd-initial.sh
#Chạy 1 lần DUY NHẤT trên từng NODE.
#LastUpdate: #14:21 2020.10.20
################################################################
#cat /opt/script/etcd-initial.sh | grep LastUpdate
################################################################
#RESTART ETCD: #\rm -rf /var/lib/etcd/*;
#sudo systemctl daemon-reload;sudo systemctl enable etcd;sudo systemctl restart etcd;sudo systemctl status etcd -l --no-pager
#STOP ETCD: sudo systemctl stop etcd;sudo systemctl status etcd -l --no-pager
#etcd1 10.0.2.111*
#etcd2 10.0.2.112
#etcd3 10.0.2.113
################################################################
ETCD_HOME="/opt/etcd"
mkdir -p $ETCD_HOME
/bin/rm -rf $ETCD_HOME
mkdir -p $ETCD_HOME
ETCD_DATA=$ETCD_HOME/data
mkdir -p $ETCD_DATA
ETCD_LOG=$ETCD_HOME/etcd.log
echo "------------------------------------------------------------"
echo "MAKING [ETCD_HOME]:"
sleep 2
echo "[ETCD_HOME: $ETCD_HOME]"
echo "[ETCD_DATA: $ETCD_DATA]"
echo "[ETCD_LOG : $ETCD_LOG]"
echo "------------------------------------------------------------"
echo "CREATING GROUP/USER: ETCD:"
sleep 2
GroupName=etcd
UserName=etcd
GroupID=6000
UserID=6000
userdel $UserName
#groupdel $GroupName
groupadd -g $GroupID $GroupName
useradd -u $UserID -s "/sbin/nologin" -d "/opt/$UserName" -c "ETCD.SUPER.ADMIN" -g $GroupName $UserName
echo "GROUP: [$(cat /etc/group | grep etcd)]"
sleep 1
echo "PWD: [$(cat /etc/passwd | grep etcd)]"
sleep 1
echo "------------------------------------------------------------"
echo "RESULT: [$(pwd)]"
sleep 2
chown -R $GroupName.$UserName $ETCD_HOME
chmod -R 700 $ETCD_HOME
ls -lh $ETCD_HOME
tree $ETCD_HOME
#THE_END
#/opt/script/etcd-initial.sh
#Chạy 1 lần DUY NHẤT trên từng NODE.
#LastUpdate: #14:21 2020.10.20
################################################################
#cat /opt/script/etcd-initial.sh | grep LastUpdate
################################################################
#RESTART ETCD: #\rm -rf /var/lib/etcd/*;
#sudo systemctl daemon-reload;sudo systemctl enable etcd;sudo systemctl restart etcd;sudo systemctl status etcd -l --no-pager
#STOP ETCD: sudo systemctl stop etcd;sudo systemctl status etcd -l --no-pager
#etcd1 10.0.2.111*
#etcd2 10.0.2.112
#etcd3 10.0.2.113
################################################################
ETCD_HOME="/opt/etcd"
mkdir -p $ETCD_HOME
/bin/rm -rf $ETCD_HOME
mkdir -p $ETCD_HOME
ETCD_DATA=$ETCD_HOME/data
mkdir -p $ETCD_DATA
ETCD_LOG=$ETCD_HOME/etcd.log
echo "------------------------------------------------------------"
echo "MAKING [ETCD_HOME]:"
sleep 2
echo "[ETCD_HOME: $ETCD_HOME]"
echo "[ETCD_DATA: $ETCD_DATA]"
echo "[ETCD_LOG : $ETCD_LOG]"
echo "------------------------------------------------------------"
echo "CREATING GROUP/USER: ETCD:"
sleep 2
GroupName=etcd
UserName=etcd
GroupID=6000
UserID=6000
userdel $UserName
#groupdel $GroupName
groupadd -g $GroupID $GroupName
useradd -u $UserID -s "/sbin/nologin" -d "/opt/$UserName" -c "ETCD.SUPER.ADMIN" -g $GroupName $UserName
echo "GROUP: [$(cat /etc/group | grep etcd)]"
sleep 1
echo "PWD: [$(cat /etc/passwd | grep etcd)]"
sleep 1
echo "------------------------------------------------------------"
echo "RESULT: [$(pwd)]"
sleep 2
chown -R $GroupName.$UserName $ETCD_HOME
chmod -R 700 $ETCD_HOME
ls -lh $ETCD_HOME
tree $ETCD_HOME
#THE_END
4/ ETCD Cluster Config on 3 node:
#!/bin/bash
#/opt/script/etcd-restart.sh
#Chú ý các tham số cấu hình của từng node:
#LastUpdate: #13:40 2020.10.20
################################################################
#cat /opt/script/etcd-restart.sh | grep LastUpdate
################################################################
#RESTART ETCD: #\rm -rf /var/lib/etcd/*;
#sudo systemctl daemon-reload;sudo systemctl enable etcd;sudo systemctl restart etcd;sudo systemctl status etcd -l --no-pager
#STOP ETCD: sudo systemctl stop etcd;sudo systemctl status etcd -l --no-pager
#etcd1 10.0.2.111*
#etcd2 10.0.2.112
#etcd3 10.0.2.113
#Line 56:
#--name etcd1 \
#--name etcd2 \
#--name etcd3 \
################################################################
ETCD_HOME="/opt/etcd"
mkdir -p $ETCD_HOME
ETCD_DATA=$ETCD_HOME/data
mkdir -p $ETCD_DATA
ETCD_LOG=$ETCD_HOME/etcd.log
echo "------------------------------------------------------------"
echo "ETCD TCP CONNECTION: CURRENT"
netstat -ntlup | egrep "PID|LISTEN" | sort -t: -k2 -n | egrep "PID|etcd"
sleep 1
fuser -k 2379/tcp
fuser -k 2380/tcp
GroupName=etcd
UserName=etcd
GroupID=6000
UserID=6000
# userdel $UserName
# groupdel $GroupName
# groupadd -g $GroupID $GroupName
# useradd -u $UserID -s "/sbin/nologin" -d "/opt/$UserName" -c "ETCD.SUPER.ADMIN" -g $GroupName $UserName
chown -R $GroupName.$UserName $ETCD_HOME
chmod -R 700 $ETCD_HOME
#check group, user xem da tao duoc chua:
#cat /etc/group | grep $GroupName; cat /etc/passwd | grep $UserName
#_______________________________________________________________ETCD_CONFIG:BEGIN
#REF: https://etcd.io/docs/v3.4.0/op-guide/clustering/
etcd \
--name etcd1 \
--data-dir=$ETCD_DATA \
--initial-advertise-peer-urls http://10.0.2.111:2380 \
--listen-peer-urls http://10.0.2.111:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://10.0.2.111:2379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster etcd1=http://10.0.2.111:2380,etcd2=http://10.0.2.112:2380,etcd3=http://10.0.2.113:2380 \
--initial-cluster-state new > $ETCD_LOG 2>&1 &
#_______________________________________________________________ETCD_CONFIG:END
sleep 1
echo "------------------------------------------------------------"
echo "ETCD TCP CONNECTION: NEW"
netstat -ntlup | egrep "PID|LISTEN" | sort -t: -k2 -n | egrep "PID|etcd"
sleep 1
echo "------------------------------------------------------------"
echo "ETCD PID:"
ps aux| egrep "PID|etcd"
echo "----"
echo "DONE"
#THE_END
5/ ETCD stop:
#!/bin/bash
#/opt/script/etcd-stop.sh
#LastUpdate: #13:41 2020.10.20
################################################################
#cat /opt/script/etcd-stop.sh | grep LastUpdate
################################################################
#RESTART ETCD: #\rm -rf /var/lib/etcd/*;
#sudo systemctl daemon-reload;sudo systemctl enable etcd;sudo systemctl restart etcd;sudo systemctl status etcd -l --no-pager
#STOP ETCD: #\rm -rf /var/lib/etcd/*;
#sudo systemctl stop etcd;sudo systemctl status etcd -l --no-pager
#etcd1 10.0.2.111*
#etcd2 10.0.2.112
#etcd3 10.0.2.113
################################################################
echo "------------------------------------------------------------"
echo "ETCD TCP CONNECTION: CURRENT"
netstat -ntlup | egrep "PID|LISTEN" | sort -t: -k2 -n | egrep "PID|etcd"
sleep 1
fuser -k 2379/tcp
fuser -k 2380/tcp
GroupName=etcd
UserName=etcd
GroupID=6000
UserID=6000
#chown -R $GroupName.$UserName $ETCD_HOME
#chmod -R 700 $ETCD_HOME
echo "------------------------------------------------------------"
echo "ETCD TCP CONNECTION: NEW"
netstat -ntlup | egrep "PID|LISTEN" | sort -t: -k2 -n | egrep "PID|etcd"
sleep 1
echo "------------------------------------------------------------"
echo "ETCD PID:"
ps aux| egrep "PID|etcd"
echo "----"
echo "DONE"
#THE_END
6/ ETCD check log realtime:
#!/bin/bash
#/opt/script/etcd-log.sh
#LastUpdate: #14:31 2020.10.20, #13:40 2020.10.20
################################################################
#cat /opt/script/etcd-log.sh | grep LastUpdate
################################################################
#RESTART ETCD: #\rm -rf /var/lib/etcd/*;
#sudo systemctl daemon-reload;sudo systemctl enable etcd;sudo systemctl restart etcd;sudo systemctl status etcd -l --no-pager
#STOP ETCD: sudo systemctl stop etcd;sudo systemctl status etcd -l --no-pager
#etcd1 10.0.2.111*
#etcd2 10.0.2.112
#etcd3 10.0.2.113
################################################################
ETCD_HOME="/opt/etcd"
#mkdir -p $ETCD_HOME
ETCD_DATA=$ETCD_HOME/data
#mkdir -p $ETCD_DATA
ETCD_LOG=$ETCD_HOME/etcd.log
echo "------------------------------------------------------------"
echo "ETCD TCP CONNECTION: "
netstat -ntlup | egrep "PID|LISTEN" | sort -t: -k2 -n | egrep "PID|etcd"
sleep 1
echo "------------------------------------------------------------"
echo "ETCD PID:"
ps aux| egrep "PID|etcd"
sleep 1
echo "------------------------------------------------------------"
echo "ETCD LOG: "
sleep 3
tail -f $ETCD_LOG
#THE_END
7/ ETCD cluster member list:
#!/bin/bash
#/opt/script/etcd-members.sh
#LastUpdate: #14:14 2020.10.20
################################################################
#cat /opt/script/etcd-members.sh | grep LastUpdate
################################################################
#RESTART ETCD: #\rm -rf /var/lib/etcd/*;
#sudo systemctl daemon-reload;sudo systemctl enable etcd;sudo systemctl restart etcd;sudo systemctl status etcd -l --no-pager
#STOP ETCD: sudo systemctl stop etcd;sudo systemctl status etcd -l --no-pager
#etcd1 10.0.2.111*
#etcd2 10.0.2.112
#etcd3 10.0.2.113
################################################################
ETCD_HOME="/opt/etcd"
echo "------------------------------------------------------------"
echo "ETCD TCP CONNECTION: "
netstat -ntlup | egrep "PID|LISTEN" | sort -t: -k2 -n | egrep "PID|etcd"
sleep 1
echo "------------------------------------------------------------"
echo "ETCD PID:"
ps aux| egrep "PID|etcd"
sleep 1
echo "------------------------------------------------------------"
echo "ETCD MEMBERs: "
sleep 1
etcdctl member list
#THE_END
8/ ETCD cluster status:
#!/bin/bash
#/opt/script/etcd-status.sh
#LastUpdate: #13:40 2020.10.20
################################################################
#cat /opt/script/etcd-status.sh | grep LastUpdate
################################################################
#RESTART ETCD: #\rm -rf /var/lib/etcd/*;
#sudo systemctl daemon-reload;sudo systemctl enable etcd;sudo systemctl restart etcd;sudo systemctl status etcd -l --no-pager
#STOP ETCD: sudo systemctl stop etcd;sudo systemctl status etcd -l --no-pager
#etcd1 10.0.2.111*
#etcd2 10.0.2.112
#etcd3 10.0.2.113
################################################################
ETCD_HOME="/opt/etcd"
#mkdir -p $ETCD_HOME
ETCD_DATA=$ETCD_HOME/data
#mkdir -p $ETCD_DATA
ETCD_LOG=$ETCD_HOME/etcd.log
echo "------------------------------------------------------------"
echo "ETCD TCP CONNECTION: "
netstat -ntlup | egrep "PID|LISTEN" | sort -t: -k2 -n | egrep "PID|etcd"
sleep 1
echo "------------------------------------------------------------"
echo "ETCD PID:"
ps aux| egrep "PID|etcd"
sleep 1
echo "------------------------------------------------------------"
echo "ETCD LOG: "
sleep 2
#tail -n10 -f $ETCD_LOG | more
tail -n 10 $ETCD_LOG
echo "/opt/script/etcd-log.sh"
echo ""
#<<DONE DONE DONE
9/ RESULT:
#
#
No comments:
Post a Comment