您好,登錄后才能下訂單哦!
小編給大家分享一下shell腳本如何實(shí)現(xiàn)公司項(xiàng)目部署交付環(huán)境預(yù)檢查,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
示例代碼:
#!/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)大寫或特殊符號(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)磁盤掛載----------------------------------\033[0m" ansible dragon -m shell -a "df -h" echo -e "\033[1;32;31m----------------------------------以上為所有節(jié)點(diǎ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ī)磁盤掛載 |" 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
以上是“shell腳本如何實(shí)現(xiàn)公司項(xiàng)目部署交付環(huán)境預(yù)檢查”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。