Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。
一.安装环境的配置
1.关闭防火墙
为了防止因为防火墙的原因影响我们安装的环境,我们对防火墙进行关闭,如果在实际的生产环境中,我们是不建议关闭防火墙的。
[root@Nagios ~]# service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
[root@Nagios ~]# chkconfig iptables off
2.关闭SELinux
如果未关闭SELinux,则可能在安装完成后,会出现Internal Server Error错误
编辑/etc/selinux/config
[root@Nagios ~]# vim /etc/selinux/config
将SELINUX=disabled
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
3.Nagios软件的解压
[root@Nagios ~]# tar zxvf nagios-3.5.0.tar.gz
[root@Nagios ~]# tar zxvf nagios-plugins-1.4.16.tar.gz
4.Nagios的编译与安装
首先进入Nagios解压后所在的目录
[root@Nagios ~]# cd nagios
[root@Nagios nagios]# ./configure --with-command-group=nagcmd
[root@Nagios nagios]# make all
[root@Nagios nagios]# make install
[root@Nagios nagios]# make install-init
[root@Nagios nagios]# make install-config
[root@Nagios nagios]# make install-commandmode
[root@Nagios nagios]# make install-webconf
测试nagios的配置文件
[root@Nagios nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果最后出现
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
就证明nagios配置无误可正常启动!
启动Nagios服务:
[root@Nagios nagios]# service nagios start
Starting nagios: done.
启动httpd服务:
[root@Nagios nagios]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
添加访问WEB服务的账户及密码
[root@Nagios nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users admin
New password:
Re-type new password:
Adding password for user admin
这个时候就已经添加好了访问web网站的用户了