大型項(xiàng)目環(huán)境預(yù)檢查腳本,根據(jù)自己實(shí)際情況修改腳本中變量,給大家一個(gè)思路,轉(zhuǎn)載請(qǐng)注明出處~
#!/usr/bin/env bash
root=$(
cd $(dirname $0)
pwd
)
source "$root"/dragonrc
CPU=$(echo "`cat /proc/cpuinfo | grep "physical id" | uniq | wc -l`H")
MEM=$(echo "$((`cat /proc/meminfo | grep MemTotal |awk '{print $2}'` / 1000000))G")
TIME=$(date)
rpm -q ansible > /dev/null
if [ $? -ne 0 ];then
sh ${root}/scripts/install_ansible.sh > /dev/null
fi
HINT(){
read -p "請(qǐng)按回車?yán)^續(xù):"
}
COPY_KEY(){
echo
echo
sh ${root}/scripts/copy-key.sh
echo
echo
}
CK_UMASK(){
UMASK_NUM=$(ansible dragon -m shell -a "umask"|grep 0022|wc -l)
ALL_HOSTS=$(echo "${ALL_NODES}"|awk -F"," '{for(i=1;i=NF;i++) print $i}'|wc -l)
echo
echo -e "\033[5;32;31m正在為您檢測(cè)umask值,請(qǐng)耐心等待。。。\033[0m"
echo
if [ ${UMASK_NUM} -ne ${ALL_HOSTS} ];then
echo -e "\033[1;32;31m檢測(cè)到節(jié)點(diǎn)umask值非022,將為您執(zhí)行修改操作!\033[0m"
sleep 3
ansible dragon -m shell -a "sed -i 's/^.*umask.*/umask 022/g' /etc/profile"
ansible dragon -m shell -a "source /etc/profile"
ansible dragon -m shell -a "sed -i 's/^.*umask.*/umask 022/g' /etc/bashrc"
ansible dragon -m shell -a "source /etc/bashrc"
echo -e "\033[1;32;31m-------------------------------以下為各節(jié)點(diǎn)umask值-------------------------------\033[0m"
ansible dragon -m shell -a "umask"
echo -e "\033[1;32;31m提示:如果以上返回結(jié)果非0022,那就是自動(dòng)設(shè)置失敗,請(qǐng)手動(dòng)調(diào)整umask值!\033[0m"
else
clear
echo -e "\033[1;32;31m所有節(jié)點(diǎn)umask值全部為022\033[0m"
echo
fi
}
CK_NETWORK_NAME(){
echo
echo -e "\033[1;32;31m-------------------------------檢測(cè)所有節(jié)點(diǎn)主機(jī)網(wǎng)卡名-------------------------------\033[0m"
IFS=',' read -r -a nodes "${ALL_NODES}"
for p in "${nodes[@]}"; do
echo
ssh -q -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile /dev/null' -T $p ip addr |grep $p | awk '{print $2,$7}'
echo
done
echo -e "\033[1;32;35m提示:請(qǐng)您把網(wǎng)卡名復(fù)制到dragonrc配置~\033[0m"
echo -e "\033[1;32;31m-------------------------------以上為所有節(jié)點(diǎn)主機(jī)網(wǎng)卡名-------------------------------\033[0m"
echo
}
CK_HOST_NAME(){
echo
echo -e "\033[1;32;31m-------------------------------檢測(cè)所有節(jié)點(diǎn)主機(jī)名-------------------------------\033[0m"
ansible dragon -m shell -a "hostname"
echo -e "\033[1;32;31m提示:檢查主機(jī)名,不能是出現(xiàn)大寫(xiě)或特殊符號(hào)~\033[0m"
echo -e "\033[1;32;31m-------------------------------以上為所有節(jié)點(diǎn)主機(jī)名-------------------------------\033[0m"
echo
}
CK_HOSTS(){
echo
echo -e "\033[1;32;31m-------------------------------檢測(cè)所有節(jié)點(diǎn)Hosts配置-------------------------------\033[0m"
sh ${root}/scripts/hostname.sh
echo -e "\033[1;32;31m-------------------------------以上為所有節(jié)點(diǎn)Hosts配置-------------------------------\033[0m"
echo
}
CK_TIME(){
echo
echo -e "\033[1;32;31m----------------------------------檢測(cè)所有節(jié)點(diǎn)時(shí)間----------------------------------\033[0m"
ansible dragon -m shell -a "date"
echo -e "\033[1;32;35m提示:誤差為1~2秒為正常情況,如差距太大則需要做ntpd時(shí)間同步~\033[0m"
echo -e "\033[1;32;31m----------------------------------以上為所有節(jié)點(diǎn)時(shí)間----------------------------------\033[0m"
echo
}
CK_DISK(){
echo
echo -e "\033[1;32;31m----------------------------------檢測(cè)所有節(jié)點(diǎn)磁盤(pán)掛載----------------------------------\033[0m"
ansible dragon -m shell -a "df -h"
echo -e "\033[1;32;31m----------------------------------以上為所有節(jié)點(diǎn)磁盤(pán)掛載----------------------------------\033[0m"
echo
}
CK_SYSTEM(){
echo
echo -e "\033[1;32;31m----------------------------------檢測(cè)所有節(jié)點(diǎn)系統(tǒng)版本信息----------------------------------\033[0m"
ansible dragon -m shell -a "cat /etc/redhat-release"
echo -e "\033[1;32;31m----------------------------------以上為所有節(jié)點(diǎn)系統(tǒng)版本信息----------------------------------\033[0m"
echo
}
CK_FIREWALLD(){
echo
echo -e "\033[1;32;31m----------------------------------檢測(cè)所有節(jié)點(diǎn)防火墻是否關(guān)閉----------------------------------\033[0m"
ansible dragon -m shell -a "firewall-cmd --state"
echo -e "\033[1;32;35m提示:如果發(fā)現(xiàn)防火墻狀態(tài)為Running,不用擔(dān)心,all_sh.sh環(huán)境初始化配置已經(jīng)配好永久關(guān)閉哦~\033[0m"
echo -e "\033[1;32;31m----------------------------------以上為所有節(jié)點(diǎn)防火墻狀態(tài)信息----------------------------------\033[0m"
echo
}
CK_SELINUX(){
echo
echo -e "\033[1;32;31m----------------------------------檢測(cè)所有節(jié)點(diǎn)SELINUX是否關(guān)閉----------------------------------\033[0m"
ansible dragon -m shell -a "sestatus"
echo -e "\033[1;32;35m提示:如果發(fā)現(xiàn)狀態(tài)為enabled,不用擔(dān)心,all_sh.sh環(huán)境初始化配置已經(jīng)配好永久關(guān)閉哦~\033[0m"
echo -e "\033[1;32;31m----------------------------------以上為所有節(jié)點(diǎn)SELINUX狀態(tài)信息----------------------------------\033[0m"
echo
}
while true
do
clear
echo "-------------------------------------------------------"
echo "| |"
echo "| XXXXXXXXXXX部署預(yù)檢查環(huán)境 |"
echo "| |"
echo "-------------------------------------------------------"
echo " ***** 檢測(cè)到您的機(jī)器配置為:${CPU} ${MEM} ***** "
echo "-------------------------------------------------------"
echo "| 1. 一鍵SSH免密互信 |"
echo "| 2. 檢查各節(jié)點(diǎn)主機(jī)umask |"
echo "| 3. 檢查各節(jié)點(diǎn)網(wǎng)卡名 |"
echo "| 4. 檢查各節(jié)點(diǎn)主機(jī)名 |"
echo "| 5. 檢查各節(jié)點(diǎn)hosts配置 |"
echo "| 6. 檢查各節(jié)點(diǎn)主機(jī)時(shí)間 |"
echo "| 7. 檢查各節(jié)點(diǎn)主機(jī)磁盤(pán)掛載 |"
echo "| 8. 檢查各節(jié)點(diǎn)主機(jī)系統(tǒng)版本 |"
echo "| 9. 檢查各節(jié)點(diǎn)防火墻是否關(guān)閉 |"
echo "| 10. 檢查各節(jié)點(diǎn)SELINUX是否關(guān)閉 |"
echo "-------------------------------------------------------"
echo
echo " // 當(dāng)前時(shí)間:${TIME} //"
echo
read -p "請(qǐng)您選擇[1-10/q退出]選項(xiàng):" THING
case $THING in
1)
COPY_KEY
HINT
;;
2)
CK_UMASK
HINT
;;
3)
CK_NETWORK_NAME
HINT
;;
4)
CK_HOST_NAME
HINT
;;
5)
CK_HOSTS
HINT
;;
6)
CK_TIME
HINT
;;
7)
CK_DISK
HINT
;;
8)
CK_SYSTEM
HINT
;;
9)
CK_FIREWALLD
HINT
;;
10)
CK_SELINUX
HINT
;;
q)
exit
;;
*)
read -p "請(qǐng)您選擇[1-10/q退出],輸入回車?yán)^續(xù):"
;;
esac
done
到此這篇關(guān)于shell腳本實(shí)現(xiàn)公司項(xiàng)目部署交付環(huán)境預(yù)檢查的思路的文章就介紹到這了,更多相關(guān)shell腳本部署交付環(huán)境內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!