nagios一键安装脚本V1.0(客户端+服务端)-创新互联
服务端脚本:
创新互联公司凭借在网站建设、网站推广领域领先的技术能力和多年的行业经验,为客户提供超值的营销型网站建设服务,我们始终认为:好的营销型网站就是好的业务员。我们已成功为企业单位、个人等客户提供了成都网站设计、成都网站制作服务,以良好的商业信誉,完善的服务及深厚的技术力量处于同行领先地位。#!//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 1 fi echo -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 apache if [ $? -ne 0 ] then echo -e "\033[31m添加用户失败!\033[0m" exit 2 fi echo -e "\033[32mnagios用户组配置完成!\033[0m" } nagios_ins() { echo -e "\033[32m开始安装nagios_cn程序......\033[0m" cd ${path}/download tar jxvf nagios-cn-*.tar.bz2 cd nagios-cn-* ./configure --with-command-group=nagcmd make all make install make install-init make install-config make install-commandmode make install-webconf if [ $? -ne 0 ] then echo -e "\033[31mnagios_cn安装失败!\033[0m" exit 3 fi echo -e "\033[32mnagios_cn程序安装成功!\033[0m" echo -e "\033[32m开始设置nagios_cn程序......\033[0m" echo -en "\033[32m请输入nagiosadmin用户密码:\033[0m" read passwd htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin ${passwd} service httpd restart chkconfig --add httpd &&chkconfig httpd on chkconfig --add nagios &&chkconfig nagios on cat>>/root/.bashrc<>/usr/local/nagios/etc/objects/commands.cfg< > /etc/rc.d/rc.local << EOF /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d EOF if [ $? -ne 0 ] then echo -e "\033[31mnrpe设置失败!\033[0m" exit 2 fi echo -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 "请输入选择:" choice case ${choice} in 1) yum_user;; 2) nagios_ins;; 3) nagios_plugins_ins;; 4) nrpe_ins;; 5) break;; *) echo -e "\033[31m您输入了:$num,设定没有此选项,请重输 \033[0m" break;; esac
客户端脚本:
#!/bin/bash path=`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 1 fi echo -e "\033[32mnagios依赖组件安装完成!\033[0m" /usr/sbin/useradd -m nagios if [ $? -ne 0 ] then echo -e "\033[31m添加用户失败!\033[0m" exit 2 fi echo -e "\033[32mnagios用户配置完成!\033[0m" } nagios_plugins_ins() { echo -e "\033[32m开始安装nagios_plugins程序......\033[0m" cd ${path} tar zxvf nagios-plugins-*.tar.gz cd nagios-plugins-* ./configure --with-nagios-user=nagios --with-nagios-group=nagios make&&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 2 fi echo -e "\033[32mnagios_plugins程序安装成功!\033[0m" } nrpe_ins() { echo -e "\033[32m开始安装nagios_plugins程序......\033[0m" cd ${path} tar zxvf nrpe-*.tar.gz cd nrpe-* ./configure --with-nagios-user=nagios --with-nagios-group=nagios make all make install-plugin make install-daemon make install-daemon-config if [ $? -ne 0 ] then echo -e "\033[31mnrpe安装失败!\033[0m" exit 2 fi echo -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 EOF sed -i 's@allowed_hosts=127.0.0.1@allowed_hosts=192.168.1.1@' /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 2 fi echo -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 "请输入选择:" choice case ${choice} in 1) yum_user;; 2) nagios_plugins_ins;; 3) nrpe_ins;; 4) break;; *) echo -e "\033[31m您输入了:$num,设定没有此选项,请重输 \033[0m" break;; esac
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
本文标题:nagios一键安装脚本V1.0(客户端+服务端)-创新互联
当前地址:http://scjbc.cn/article/dpooee.html