一件自动化安装nagios服务
声明
作者:昨夜星辰
博客:http://yestreenstars.blog.51cto.com/
本文由本人创作,如需转载,请注明出处,谢谢合作!
目的
一键自动化安装nagios服务。
环境
OS: CentOS 6.2 32
nagios: 4.0.7
nagios-plugins: 2.0.3
nrpe: 2.15
配置
#!/bin/bash # Script Name: One-key Automatic Install Nagios Service # Author: yestreenstars # Create Time: 2014-08-05 echo -n "Closing SELinux and Modifying /etc/selinux/config..." setenforce 0 > /dev/null 2>&1 sed -i ‘/^SELINUX=/s/=.*/=disabled/‘ /etc/selinux/config echo "Completed!" echo -n "Configuring iptables firewall..." iptables -F iptables -X iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT iptables -A INPUT -p icmp -j ACCEPT iptables -A INPUT -i lo -j ACCEPT iptables -P INPUT DROP iptables -P FORWARD DROP service iptables save > /dev/null 2>&1 echo "Completed!" echo -n "Adding nagios user..." useradd -s /sbin/nologin nagios && echo "Completed!" echo -n "Installing related software..." yum -y install gcc gd gd-devel glibc glibc-common httpd openssl openssl-devel php make net-snmp wget > /dev/null 2>&1 && echo "Completed!" echo -n "Downloading nagios, nagios-plugins and nrpe..." ( wget -P /tmp http://jaist.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.7/nagios-4.0.7.tar.gz && wget -P /tmp http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz && wget -P /tmp http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz ) > /dev/null 2>&1 && echo "Completed!" || (echo "Failure!" && exit) echo -n "Installing nagios..." tar xzf /tmp/nagios-4.0.7.tar.gz -C /usr/src/ cd /usr/src/nagios-4.0.7/ ( ./configure && make all && make install && make install-init && make install-commandmode && make install-config && make install-webconf ) > /dev/null 2>&1 && echo "Completed!" echo -n "Installing nagios-plugins..." tar xzf /tmp/nagios-plugins-2.0.3.tar.gz -C /usr/src/ cd /usr/src/nagios-plugins-2.0.3/ (./configure && make && make install) > /dev/null 2>&1 && echo "Completed!" echo -n "Installing nrpe..." tar xzf /tmp/nrpe-2.15.tar.gz -C /usr/src/ cd /usr/src/nrpe-2.15/ ( ./configure && make all && make install-plugin && make install-daemon && make install-daemon-config ) > /dev/null 2>&1 && echo "Completed!" chown -R nagios:nagios /usr/local/nagios/ echo -n "Starting httpd and nagios service..." (service httpd start && service nagios start) > /dev/null 2>&1 && echo "Completed!" echo -n "Adding httpd and nagios service to run on startup..." chkconfig httpd on chkconfig --add nagios chkconfig nagios on echo "Completed!"
运行完以上脚本后还需手动运行一下以下命令,为管理员用户设置密码:
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
客户端通过http://服务端IP/nagios来访问。
本文出自 “昨夜星辰” 博客,请务必保留此出处http://yestreenstars.blog.51cto.com/1836303/1536028
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。