您好,登錄后才能下訂單哦!
#!/bin/bash ##nagios監控軟件一件使用 ##date : 2016-08-23 ##作者:liuwenzhi #定義變量 YUMNUM=`yum repolist 2>/dev/null|grep repolist: |sed 's/[^0-9]//g'` NAGIOSzip=nagios.zip NAGIOS=nagios #定義yum源是否可用腳本 YUMREPO (){ echo -ne "3[34m正在檢測yum源3[0m" sleep 3 if [ $YUMNUM -eq 0 ];then echo -e "3[32myum源不可用,請先配置yum源3[0m" exit 10 else echo -e "3[34myum源檢測通過!3[0m" fi } #定義菜單 menu (){ echo " ##############----一鍵安裝菜單----##############" echo "# 1. 安裝nagios 監控端" echo "# 2. 安裝遠程被監控端" echo "# 3. 退出 " read -p "請輸入菜單【1-3】" select } #安裝nagios依賴環境 yilai_install (){ echo "----------正在安裝依賴包" case $select in 1) yum install -y httpd php gcc glibc unzip zip glibc-common gd gd-devel libpng libjpeg zlib openssl-devel &>/dev/null ;; 2) yum install -y gcc openssl-devel &>/dev/null ;; esac echo "----------依賴安裝完成" } #定義configure時是否出錯 configure_err(){ if [ $? -ne 0 ];then echo "cofigure失敗" exit 11 fi } #定義make時是否出錯 make_err(){ if [ $? -ne 0 ];then echo "make失敗" exit 12 fi } #定義make install 安裝時是否出錯 make_install_err(){ if [ $? -ne 0 ];then echo "make install失敗" exit 13 fi } #修改httpd文件支持php xiugai_httpd (){ sed -i '/^DirectoryIndex/s/$/& index.php/g' /etc/httpd/conf/httpd.conf service httpd start &>/dev/null chkconfig httpd on } #nagios安裝 nagios_install (){ echo "----------安裝nagios" groupadd nagcmd &>/dev/null useradd -s /sbin/nologin nagios &>/dev/null usermod -G nagcmd apache if [ -f $NAGIOS ];then rm -rf $NAGIOS fi unzip $NAGIOSzip &>/dev/null cd $NAGIOS tar -zxf nagios-3.2.1.tar.gz -C /usr/src &>/dev/null cd /usr/src/nagios-3.2.1/ echo "----------編譯中" ./configure --with-command-group=nagcmd &>/dev/null configure_err make all &>/dev/null make_err make install &>/dev/null make_install_err make install-init &>/dev/null make install-config &>/dev/null make install-commandmode &>/dev/null make install-webconf &>/dev/null } #nagios-plugins安裝 plugins(){ cd - &>/dev/null tar -zxf nagios-plugins-1.4.14.tar.gz cd nagios-plugins-1.4.14 ./configure --with-nagios-user=nagios \ --with-nagios-group=nagcmd &>/dev/null configure_err make &>/dev/null make_err make install &>/dev/null make_install_err #監控腳本資源在ls /usr/local/nagios/libexec/ 下 } #安裝nrpe nrpe_install (){ cd - &>/dev/null tar -zxf nrpe-2.12.tar.gz cd nrpe-2.12 ./configure &>/dev/null configure_err make &>/dev/null make_err make install &>/dev/null make_install_err make install-plugin &>/dev/null sed -i '$a\define command {' /usr/local/nagios/etc/objects/commands.cfg sed -i '$a\ command_name check_nrpe' /usr/local/nagios/etc/objects/commands.cfg sed -i '$a\ command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ ' /usr/local/nagios/etc/objects/commands.cfg sed -i '$a\ }' /usr/local/nagios/etc/objects/commands.cfg #cd /usr/local/nagios/etc/objects/ #read -p "請輸入需要監控的用戶名" u #cp localhost.cfg $u.cfg #sed -i '/host_name/s/localhost/$u/g' /usr/local/nagios/etc/objects/localhost.cfg #sed -i '$a\cfg_file=/usr/local/nagios/etc/objects/$u.cfg } #修改配置文件 abc (){ [ -f /usr/local/nagios/etc/objects/commands.cfg ] || \ cp /usr/src/nagios-3.2.1/sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/ [ -f /usr/local/nagios/etc/objects/localhost.cfg ] || \ cp /usr/src/nagios-3.2.1/sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/ [ -f /usr/local/nagios/etc/nagios.cfg ] || \ cp /usr/src/nagios-3.2.1/sample-config/nagios.cfg /usr/local/nagios/etc/ cp /usr/src/nagios-3.2.1/sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf echo "請設置頁面登入密碼,按回車設置" read htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin /etc/init.d/nagios start &>/dev/null service httpd restart &>/dev/null } #安裝被監控端主機 ggg (){ echo "----------安裝中" useradd nagios &>/dev/null groupadd nagcmd &>/dev/null usermod -G nagcmd nagios &>/dev/null unzip $NAGIOSzip &>/dev/dull cd $NAGIOS tar -zxf nagios-plugins-1.4.14.tar.gz cd nagios-plugins-1.4.14 ./configure &>/dev/null configure_err make &>/dev/null make_err make install &>/dev/null make_install_err cd .. tar -zxf nrpe-2.12.tar.gz cd nrpe-2.12 ./configure &>/dev/null configure_err make &>/dev/null make_err make install &>/dev/null make_install_err make install-plugin &>/dev/null make install-daemon &>/dev/null make install-daemon-config &>/dev/null make install-xinetd &>/dev/null yum install -y telnet-server &>/dev/null read -p "-----請輸入監控端的ip----- : " ip sed -i '/only_from/s/$/& "$ip"/' /etc/xinetd.d/nrpe grep -q nrpe /etc/services || \ sed -i '$a\nrpe 5666/tcp ' /etc/services /etc/init.d/xinetd restart &>/dev/null } while : do clear menu case $select in 1) YUMREPO yilai_install xiugai_httpd nagios_install plugins abc nrpe_install echo -e "3[32mOK,按回車繼續3[0m" read ;; 2) ggg echo -e "3[32mOK,按回車繼續3[0m" read ;; 3) exit 0 ;; *) echo "輸入有誤" ;; esac done 1.此腳本在多臺機器上測試成功。 2.nagios版本是nagios-3.2.1版本跑在httpd上 3.訪問時: 輸入: ip/nagios 4.頁面用httpd的密碼工具生成用戶密碼,用戶是nagiosadmin(腳本里設置的,可自己改)。 5.彈出自己輸入密碼 6.腳本可能還有瑕疵,不知道依賴包考慮的是不是 完全. 7. naios.zip文件10M ,傳不上來。上傳到百度云里。有興趣的可以下載,并在自己虛擬機上運行一次看下效果 下載地址:http://pan.baidu.com/s/1slJ5GIT 密碼nexl8.腳本運行使用 當需要遠程監控一臺機器時,先在被監控端運行2,然后再監控端運行3. 這是運行1大概 的過程------------ ##############----一鍵安裝菜單----############## # 1. 安裝nagios 監控端 # 2. 安裝遠程被監控端 #3.監控端修改被監控端文件 #4. 退出 請輸入菜單【1-4】1 正在檢測yum源yum源檢測通過! ----------正在安裝依賴包 ----------依賴安裝完成 ----------安裝nagios ----------編譯中 請設置頁面登入密碼,按回車設置 New password: Re-type new password: Adding password for user nagiosadmin OK,按回車繼續
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。