標籤:nagios服務端 用戶端 使用者組
服務端指令碼:
#!//bin/bash#nagios一鍵安裝指令碼path=`pwd`yum_user(){echo -e "\033[32m開始安裝基礎支援套件和添加使用者......\033[0m"yum -y install httpd gcc glibc glibc-common gd gd-devel if [ $? -ne 0 ]then echo -e "\033[31mYUM安裝失敗!\033[0m" exit 1fiecho -e "\033[32mnagios相依元件安裝完成!\033[0m"/usr/sbin/useradd -m nagios &&/usr/sbin/groupadd nagcmd/usr/sbin/usermod -a -G nagcmd nagios/usr/sbin/usermod -a -G nagcmd apacheif [ $? -ne 0 ]then echo -e "\033[31m添加使用者失敗!\033[0m" exit 2fiecho -e "\033[32mnagios使用者組配置完成!\033[0m"}nagios_ins(){echo -e "\033[32m開始安裝nagios_cn程式......\033[0m"cd ${path}/downloadtar jxvf nagios-cn-*.tar.bz2cd nagios-cn-*./configure --with-command-group=nagcmdmake allmake installmake install-init make install-configmake install-commandmodemake install-webconfif [ $? -ne 0 ]then echo -e "\033[31mnagios_cn安裝失敗!\033[0m" exit 3fiecho -e "\033[32mnagios_cn程式安裝成功!\033[0m"echo -e "\033[32m開始設定nagios_cn程式......\033[0m"echo -en "\033[32m請輸入nagiosadmin使用者密碼:\033[0m"read passwdhtpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin ${passwd}service httpd restart chkconfig --add httpd &&chkconfig httpd onchkconfig --add nagios &&chkconfig nagios on cat>>/root/.bashrc<<EOFalias check_nagios=‘/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg‘EOFservice nagios restart if [ $? -ne 0 ]then echo -e "\033[31mnagios_cn設定失敗!\033[0m" exit 3fiecho -e "\033[32mnagios_cn程式設定成功!\033[0m"}nagios_plugins_ins(){echo -e "\033[32m開始安裝nagios_plugins程式......\033[0m"cd ${path}/downloadtar zxvf nagios-plugins-*.tar.gzcd nagios-plugins-*./configure --with-nagios-user=nagios --with-nagios-group=nagiosmake&&make install if [ $? -ne 0 ]then echo -e "\033[31mnagios_plugins安裝失敗!\033[0m" exit 2fiecho -e "\033[32mnagios_plugins程式安裝成功!\033[0m"}nrpe_ins(){echo -e "\033[32m開始安裝nagios_plugins程式......\033[0m"cd ${path}/downloadtar zxvf nrpe-*.tar.gzcd nrpe-*./configure --with-nagios-user=nagios --with-nagios-group=nagiosmake allmake install-pluginmake install-daemonmake install-daemon-configif [ $? -ne 0 ]then echo -e "\033[31mnrpe安裝失敗!\033[0m" exit 2fiecho -e "\033[32mnrpe程式安裝成功!\033[0m"echo -e "\033[32m開始設定nrpe程式......\033[0m"cat>>/usr/local/nagios/etc/objects/commands.cfg<<EOFdefine command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$ }EOF/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d cat >> /etc/rc.d/rc.local << EOF /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d EOFif [ $? -ne 0 ]then echo -e "\033[31mnrpe設定失敗!\033[0m" exit 2fiecho -e "\033[32mnrpe程式設定成功!\033[0m"}echo -e "\033[33m開始安裝nagios......\033[0m"echo -e "\033[32m\n\t(1)基礎套件與使用者添加\n\t(2)安裝nagios-cn\n\t(3)安裝nagios-plugins\n\t(4)安裝nrpe\n\t(5)退出程式(exit)\033[0m"read -p "請輸入選擇:" choicecase ${choice} in1) yum_user;;2) nagios_ins;;3) nagios_plugins_ins;;4) nrpe_ins;;5) break;;*) echo -e "\033[31m您輸入了:$num,設定沒有此選項,請重輸 \033[0m" break;;esac
用戶端指令碼:
#!/bin/bashpath=`pwd`nagios_server="192.168.1.1"yum_user(){echo -e "\033[32m開始安裝基礎支援套件和添加使用者......\033[0m"yum -y install gcc if [ $? -ne 0 ]then echo -e "\033[31mYUM安裝失敗!\033[0m" exit 1fiecho -e "\033[32mnagios相依元件安裝完成!\033[0m"/usr/sbin/useradd -m nagios if [ $? -ne 0 ]then echo -e "\033[31m添加使用者失敗!\033[0m" exit 2fiecho -e "\033[32mnagios使用者配置完成!\033[0m"}nagios_plugins_ins(){echo -e "\033[32m開始安裝nagios_plugins程式......\033[0m"cd ${path}tar zxvf nagios-plugins-*.tar.gzcd nagios-plugins-*./configure --with-nagios-user=nagios --with-nagios-group=nagiosmake&&make install chown nagios.nagios /usr/local/nagios/chown -R nagios.nagios /usr/local/nagios/libexec/if [ $? -ne 0 ]then echo -e "\033[31mnagios_plugins安裝失敗!\033[0m" exit 2fiecho -e "\033[32mnagios_plugins程式安裝成功!\033[0m"}nrpe_ins(){echo -e "\033[32m開始安裝nagios_plugins程式......\033[0m"cd ${path}tar zxvf nrpe-*.tar.gzcd nrpe-*./configure --with-nagios-user=nagios --with-nagios-group=nagiosmake allmake install-pluginmake install-daemonmake install-daemon-configif [ $? -ne 0 ]then echo -e "\033[31mnrpe安裝失敗!\033[0m" exit 2fiecho -e "\033[32mnrpe程式安裝成功!\033[0m"echo -e "\033[32m開始設定nrpe程式......\033[0m"cat >> /etc/rc.d/rc.local << EOF >/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d EOFsed -i ‘[email protected][email protected][email protected]‘ /usr/local/nagios/etc/nrpe.cfg/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d sleep 1/usr/local/nagios/libexec/check_nrpe -H ${nagios_server}if [ $? -ne 0 ]then echo -e "\033[31mnrpe設定失敗!\033[0m" exit 2fiecho -e "\033[32mnrpe程式設定成功!\033[0m"}echo -e "\033[33m開始安裝nagios_client......\033[0m"echo -e "\033[32m\n\t(1)基礎套件與使用者添加\n\t(2)安裝nagios-plugins\n\t(3)安裝nrpe\n\t(4)退出程式(exit)\033[0m"read -p "請輸入選擇:" choicecase ${choice} in1) yum_user;;2) nagios_plugins_ins;;3) nrpe_ins;;4) break;;*) echo -e "\033[31m您輸入了:$num,設定沒有此選項,請重輸 \033[0m" break;;esac
本文出自 “給我三顆痣” 部落格,請務必保留此出處http://wushuangjay.blog.51cto.com/3125450/1568555
nagios一鍵安裝指令碼V1.0(用戶端+服務端)