服务器先安装好Apache。
从 http://www.nagios.org 下载以下软件:
nagios-3.2.3.tar.gz
nagios-plugins-1.4.15.tar.gz
nrpe-2.12.tar.gz
安装Nagios Core
#切换到root用户
su -l
#添加nagios用户
useradd -m nagios
passwd nagios
#创建nagcmd组,允许用户在web上执行命令.
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
tar xzvf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
configure完成后会显示如下提示
General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /bin/traceroute
配置文件目录/usr/local/nagios/etc
修改/usr/local/nagios/etc/objects/contacts.cfg中的邮箱地址为
nagios@xxx.edu.cn。该邮箱设置了过滤规则,所有信件转发到 xxx@139.com
将/root/nagios-3.2.3/sample-config/httpd.conf中的片段拷贝到/usr/local/apache2/conf/httpd.conf中
添加nagiosadmin用户
/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
安装Nagios Plugins
tar xzvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
命令安装在/usr/local/nagios/libexec/目录下
启动Nagios
chkconfig --add nagios #将nagios添加到服务中
chkconfig nagios on #开启该服务
chkconfig --list nagios #查看服务启动状态
#检查脚本正确性
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios start
访问 http://ip/nagios/
安装NRPE
先安装Nagios Plugins,如果是在被监控主机上安装,需要先添加nagios用户。
tar xzvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
安装NRPE Daemon
NRPE Daemon的端口5666
先按照上一步安装NRPE
make install-daemon
make install-daemon-config
make install-xinetd
安装完毕后NRPE的配置文件在/usr/local/nagios/etc/nrpe.cfg
编辑/etc/xinetd.d/nrpe
only_from = 127.0.0.1 #这里只能加一个IP
编辑/etc/services,在最后一行加上
nrpe 5666/tcp # NRPE
重启xinetd服务
service xinetd restart
执行下面命令,检查服务有无正常启动
netstat -at | grep nrpe
#应该出现以下提示
tcp 0 0 *:nrpe *:* LISTEN
测试NRPE Deamon服务
#测试本机
/usr/local/nagios/libexec/check_nrpe -H localhost
#测试远程
/usr/local/nagios/libexec/check_nrpe -H 202.195.160.46
#正常会显示
NRPE v2.12
在监控主机上编辑/usr/local/nagios/etc/objects/commands.cfg,加入下面的command。
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
重启监控主机的Nagios服务
service nagios restart
测试接收邮件
首先需要将nagios监控主机的IP加入到邮件系统的信任主机列表中。否则必须使用外部邮件系统账号发送邮件。
新建/root/testmail文件
/bin/mail -v -s "test" nagios@xxx.edu.cn < /root/testmail -- -f nagios@xxx.edu.cn -F nagios
/usr/bin/printf "%b" "test" | /bin/mail -v -s "test Alert" nagios@xxx.edu.cn -- -f nagios@xxx.edu.cn -F nagios
修改commands.cfg
notify-host-by-email 和 notify-service-by-email 末尾均加上以下语句。为了便于通过学校邮箱转139邮箱时不被139邮箱过滤。
-- -f nagios@xxx.edu.cn -F nagios
check_http
./check_http -H www.xxx.edu.cn -w 5 -c 8 -u /index.php -s "www.xxx.edu.cn"
define command{
command_name check_http
command_line $USER1$/check_http -H $ARG1$ -w $ARG2$ -c $ARG3$ -u $ARG4$ -s $ARG5$
}
define service{
use generic-service
host_name server-www-8
service_description website-www-8
check_command check_http!www.xxx.edu.cn!5!8!/index.php!"www.xxx.edu.cn"
}
check_dns
./check_http -H www.xxx.edu.cn -a site's ip -w 5 -c 8
define command {
command_name check_dns
command_line $USER1$/check_dns -s $HOSTADDRESS$ -H $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$
}
define service{
use generic-service
host_name server-dns-95
service_description network-dns-95
check_command check_dns!www.xxx.edu.cn!site's ip!5!8!
}
check_squid
./check_squid.pl -u http://www.xxx.edu.cn -p proxy_server_ip -l 3128 -o username -m password -e 200
./check_squid.pl -u http://www.xxx.edu.cn -p proxy_server_ip -l 3128 -o username -m password -e 200
./check_squid.pl -u http://www.xxx.edu.cn -p proxy_server_ip -l 3128 -e 200
define command {
command_name check_squid
command_line $USER1$/check_squid.pl -u $ARG1$ -p $ARG2$ -l $ARG3$ -o $ARG4$ -m $ARG5$ -e $ARG6$
}
define service{
use generic-service
host_name server-proxy-68
service_description network-proxy-68
check_command check_squid!http://www.xxx.edu.cn!proxy_server_ip!3128!username!password!200!
}
check_dhcp
/usr/local/nagios/libexec/check_dhcp -s dhcp_server_ip -i eth2 -u
define command{
command_name check_dhcp
command_line $USER1$/check_dhcp -s $ARG1$ -i eth2 -u
}
define service{
use generic-service
host_name server-dhcp-13
service_description network-dhcp-13
check_command check_dhcp!dhcp_server_ip!
}
DHCP服务器必须加上配置
host nagios {
hardware ethernet 00:d0:b7:c2:76:fd;
fixed-address nagios_server_ip;
}
subnet nagios_server_net netmask 255.255.255.0 {
}
check_smtp
./check_smtp -H mailserverip -A LOGIN -U username -P passworddefine command{command_name check_smtpcommand_line $USER1$/check_smtp -H $HOSTADDRESS$ -A LOGIN -U $ARG1$ -P $ARG2$}define service{use generic-servicehost_name server-mail3-17service_description ecampus-mail3-smtp-17check_command check_smtp!username!password!}
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com