#!/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 "請按回車繼續(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正在為您檢測umask值,請耐心等待。。。\033[0m"
echo
if [ ${UMASK_NUM} -ne ${ALL_HOSTS} ];then
echo -e "\033[1;32;31m檢測到節(jié)點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é)點umask值-------------------------------\033[0m"
ansible dragon -m shell -a "umask"
echo -e "\033[1;32;31m提示:如果以上返回結果非0022,那就是自動設置失敗,請手動調整umask值!\033[0m"
else
clear
echo -e "\033[1;32;31m所有節(jié)點umask值全部為022\033[0m"
echo
fi
}
CK_NETWORK_NAME(){
echo
echo -e "\033[1;32;31m-------------------------------檢測所有節(jié)點主機網(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提示:請您把網(wǎng)卡名復制到dragonrc配置~\033[0m"
echo -e "\033[1;32;31m-------------------------------以上為所有節(jié)點主機網(wǎng)卡名-------------------------------\033[0m"
echo
}
CK_HOST_NAME(){
echo
echo -e "\033[1;32;31m-------------------------------檢測所有節(jié)點主機名-------------------------------\033[0m"
ansible dragon -m shell -a "hostname"
echo -e "\033[1;32;31m提示:檢查主機名,不能是出現(xiàn)大寫或特殊符號~\033[0m"
echo -e "\033[1;32;31m-------------------------------以上為所有節(jié)點主機名-------------------------------\033[0m"
echo
}
CK_HOSTS(){
echo
echo -e "\033[1;32;31m-------------------------------檢測所有節(jié)點Hosts配置-------------------------------\033[0m"
sh ${root}/scripts/hostname.sh
echo -e "\033[1;32;31m-------------------------------以上為所有節(jié)點Hosts配置-------------------------------\033[0m"
echo
}
CK_TIME(){
echo
echo -e "\033[1;32;31m----------------------------------檢測所有節(jié)點時間----------------------------------\033[0m"
ansible dragon -m shell -a "date"
echo -e "\033[1;32;35m提示:誤差為1~2秒為正常情況,如差距太大則需要做ntpd時間同步~\033[0m"
echo -e "\033[1;32;31m----------------------------------以上為所有節(jié)點時間----------------------------------\033[0m"
echo
}
CK_DISK(){
echo
echo -e "\033[1;32;31m----------------------------------檢測所有節(jié)點磁盤掛載----------------------------------\033[0m"
ansible dragon -m shell -a "df -h"
echo -e "\033[1;32;31m----------------------------------以上為所有節(jié)點磁盤掛載----------------------------------\033[0m"
echo
}
CK_SYSTEM(){
echo
echo -e "\033[1;32;31m----------------------------------檢測所有節(jié)點系統(tǒng)版本信息----------------------------------\033[0m"
ansible dragon -m shell -a "cat /etc/redhat-release"
echo -e "\033[1;32;31m----------------------------------以上為所有節(jié)點系統(tǒng)版本信息----------------------------------\033[0m"
echo
}
CK_FIREWALLD(){
echo
echo -e "\033[1;32;31m----------------------------------檢測所有節(jié)點防火墻是否關閉----------------------------------\033[0m"
ansible dragon -m shell -a "firewall-cmd --state"
echo -e "\033[1;32;35m提示:如果發(fā)現(xiàn)防火墻狀態(tài)為Running,不用擔心,all_sh.sh環(huán)境初始化配置已經(jīng)配好永久關閉哦~\033[0m"
echo -e "\033[1;32;31m----------------------------------以上為所有節(jié)點防火墻狀態(tài)信息----------------------------------\033[0m"
echo
}
CK_SELINUX(){
echo
echo -e "\033[1;32;31m----------------------------------檢測所有節(jié)點SELINUX是否關閉----------------------------------\033[0m"
ansible dragon -m shell -a "sestatus"
echo -e "\033[1;32;35m提示:如果發(fā)現(xiàn)狀態(tài)為enabled,不用擔心,all_sh.sh環(huán)境初始化配置已經(jīng)配好永久關閉哦~\033[0m"
echo -e "\033[1;32;31m----------------------------------以上為所有節(jié)點SELINUX狀態(tài)信息----------------------------------\033[0m"
echo
}
while true
do
clear
echo "-------------------------------------------------------"
echo "| |"
echo "| XXXXXXXXXXX部署預檢查環(huán)境 |"
echo "| |"
echo "-------------------------------------------------------"
echo " ***** 檢測到您的機器配置為:${CPU} ${MEM} ***** "
echo "-------------------------------------------------------"
echo "| 1. 一鍵SSH免密互信 |"
echo "| 2. 檢查各節(jié)點主機umask |"
echo "| 3. 檢查各節(jié)點網(wǎng)卡名 |"
echo "| 4. 檢查各節(jié)點主機名 |"
echo "| 5. 檢查各節(jié)點hosts配置 |"
echo "| 6. 檢查各節(jié)點主機時間 |"
echo "| 7. 檢查各節(jié)點主機磁盤掛載 |"
echo "| 8. 檢查各節(jié)點主機系統(tǒng)版本 |"
echo "| 9. 檢查各節(jié)點防火墻是否關閉 |"
echo "| 10. 檢查各節(jié)點SELINUX是否關閉 |"
echo "-------------------------------------------------------"
echo
echo " // 當前時間:${TIME} //"
echo
read -p "請您選擇[1-10/q退出]選項:" 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 "請您選擇[1-10/q退出],輸入回車繼續(xù):"
;;
esac
done
到此這篇關于shell腳本實現(xiàn)公司項目部署交付環(huán)境預檢查的思路的文章就介紹到這了,更多相關shell腳本部署交付環(huán)境內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!