2)保证系统中sendmail服务器要开启
[iyunv@localhost ~]# yum install sendmail
[iyunv@localhost ~]# service sendmail status
sendmail (pid 3090) 正在运行...
B、编译安装Nagios
[iyunv@localhost ~]# cd /aaa/
[iyunv@localhost aaa]# tar zxf nagios-3.2.0.tar.gz
[iyunv@localhost aaa]# cd nagios-3.2.0
[iyunv@localhost nagios-3.2.0]# [url=]./configure--prefix=/usr/local/nagios/[/url]
[iyunv@localhost nagios-3.2.0]# [url=]make all ; make install ; make install-init ;make install-commandmode ; make install-config ;make install-webconf[/url]
[iyunv@localhost nagios-3.2.0]# chkconfig --add nagios
[iyunv@localhost nagios-3.2.0]# chkconfig nagios on
[iyunv@localhost nagios-3.2.0]# chkconfig --list nagios
nagios 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
C、安装Nagios插件
你可以从http://www.nagios.org官方网站上下载最新的nagios插件
[iyunv@localhostaaa]# tar zxf nagios-plugins-1.4.14.tar.gz
[iyunv@localhostaaa]# cd nagios-plugins-1.4.14
[root@localhostnagios-plugins-1.4.14]# [url=]./configure --prefix=/usr/local/nagios/ ; make ;make install[/url]
D、安装Nagios的汉化包
[iyunv@localhostaaa]# tar jxf nagios-cn-3.2.0.tar.bz2
[iyunv@localhostaaa]# cd nagios-cn-3.2.0
[root@localhostnagios-cn-3.2.0]#[url=]./configure ; make all ; makeinstall[/url]
E、修改apache配置文件
[url=][iyunv@localhost~]# vi /etc/httpd/conf/httpd.conf[/url]
231 User
232 Group apache
391 DirectoryIndex index.phpindex.html index.html.var
992 #setting for nagios
993 ScriptAlias/nagios/cgi-bin "/usr/local/nagios/sbin"
994
995 AuthType Basic
996 Options ExecCGI
997 AllowOverride None
998 Order allow,deny
999 Allow from all
1000 AuthName "nagiosaccess"
1001 AuthUserFile/usr/local/nagios/etc/htpasswd
1002 Require valid-user
1003
1004 Alias /nagios"/usr/local/nagios/share"
1005
1006 AuthType Basic
1007 Options ExecCGI
1008 AllowOverride None
1009 Order allow,deny
1010 Allow from all
1011 AuthName "nagiosaccess"
1012 AuthUserFile/usr/local/nagios/etc/htpasswd
1013 Require valid-user
1014
创建apache目录的验证文件“/usr/local/nagios/etc/htpasswd”
[iyunv@localhost~]# [url=]htpasswd -c /usr/local/nagios/etc/htpasswd benet[/url]
New password:
Re-type new password:
Adding password for user benet
三、Nagios的运行和维护
1)验证nagios主配置文件的语法正确性
[iyunv@localhostetc]#[url=]/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg[/url]
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during thepre-flight check
2)启动与停止nagios
[iyunv@localhostetc]# service nagios start
Starting nagios:This account is currently not available.
done.
[iyunv@localhostetc]# service nagios status
nagios (pid 5106) is running...
[iyunv@localhostetc]# service nagios stop
Stopping nagios: .done.
[iyunv@localhostetc]# service nagios restart
Running configuration check...done.
Stopping nagios: No lock file found in/usr/local/nagios//var/nagios.lock
Starting nagios:This account is currently not available.
done.
四、Nagios性能分析图表的实现
1)安装PNP支持包rrdtool工具
[iyunv@localhostaaa]# tar zxf rrdtool-1.4.5.tar.gz
[iyunv@localhostaaa]# cd rrdtool-1.4.5
[root@localhostrrdtool-1.4.5]#[url=]./configure--prefix=/usr/local/rrdtool ; make ; make install[/url]
安装rrdtool时候的报错:configure:error:Pleasefix thelibrary issues listed above and try again
解决办法:
yum -y install cairo-devel libxml2-devel pangopango-devel
如果上面执行后无果,请执行下面操作:
yum install cgiliblibart_lgpl-develpango-devel* cairo-devel* libxml2-devel
如果上面执行后无果,请执行下面操作:
yum -y install zlib libpng freetypelibart_lgpllibart_lgpl-devel libxml* pango*
通常编辑安装文件时,出现make无法安装,这其实是configure编译时出现了问题。
问题分析思路:先不要make,步骤分开进行,先configure编译,这样容易发现是哪一步出现的错误,并解决
2)安装PNP
[iyunv@localhost rrdtool-1.4.5]# cd /aaa/
[iyunv@localhost aaa]# tar zxf pnp-0.4.13.tar.gz
[iyunv@localhost aaa]# cd pnp-0.4.13
[iyunv@localhost pnp-0.4.13]# ./configure --with-nagios-user=nagios--with-nagios-group=nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata; make all ; make install ; make install-config ; make install-init
D、修改hosts.cfg文件和services.cfg文件
[iyunv@localhost~]# vi /usr/local/nagios/etc/objects/hosts.cfg
[url=]define host{[/url]
use linux-server,hosts-pnp
host_name web
alias benet-web
address 192.168.6.199
}
define host{
use linux-server,hosts-pnp
host_name mysql
alias benet-mysql
address 192.168.6.200
}
define hostgroup{
hostgroup_name sa-servers
alias sa servers
members web,mysql
}
[iyunv@localhost~]# vi /usr/local/nagios/etc/objects/services.cfg
################- benet web -##########################
define service{
use local-service,services-pnp
host_name web
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service,services-pnp
host_name web
service_description SSH
check_command check_ssh
}
注意项:别心急看小太阳数据,等会儿就有了。
访问http://localhost/nagios/pnp
点击小太阳,出现对主机或服务的监控页面
五,利用插件扩展Nagios的监控功能
下面我们通过在nagios服务端和客户端安装NRPE插件来搭建一个更加完善的Nagios监控系统。
1)配置nagios客户端(即远端被监控主机192.168.6.200)
A)安装Nagios插件
登陆192.168.6.200客户端
[iyunv@localhost~]# cd /aaa/
[iyunv@localhostaaa]# useradd -s /sbin/nologin nagios
[iyunv@localhostaaa]# tar zxf nagios-plugins-1.4.14.tar.gz
[iyunv@localhostaaa]# cd nagios-plugins-1.4.14
[root@localhostnagios-plugins-1.4.14]# ./configure ; make ;make install
[root@localhostnagios-plugins-1.4.14]# chown nagios:nagios /usr/local/nagios/
[root@localhostnagios-plugins-1.4.14]# chown -R nagios.nagios /usr/local/nagios/libexec/
B)安装NRPE插件
[iyunv@localhostaaa]# cd /aaa/
[iyunv@localhostaaa]# tar zxf nrpe-2.12.tar.gz
[iyunv@localhostaaa]# cd nrpe-2.12
[root@localhostnrpe-2.12]# ./configure ; make all ; make install-plugin ; make install-daemon; make install-daemon-config
2,配置nagios服务器端
登陆nagios服务器端:192.168.6.199
1)安装NRPE插件
[iyunv@localhostetc]# cd /aaa/
[iyunv@localhostaaa]# tar zxf nrpe-2.12.tar.gz
[iyunv@localhostaaa]# cd nrpe-2.12
[root@localhostnrpe-2.12]# ./configure ; make ; make install-plugin
4)添加远程主机监控项
[root@localhostnrpe-2.12]# vi /usr/local/nagios/etc/objects/services.cfg
define service{
use local-service
host_name mysql
service_description users
check_command check_nrpe!check_users_1
}
define service{
use local-service
host_name mysql
service_description load
check_command check_nrpe!check_load_1
}
define service{
use local-service
host_name mysql
service_description disk
check_command check_nrpe!check_sda1_1
}
define servicegroup{
servicegroup_name servergroup
alias server-group
members web,PING,web,SSH,web,SSHD,web,http,mysql,users,mysql,load,mysql,disk
}
6)测试并重新启动nagios服务
[iyunv@localhost~]# service nagios restart
测试中出现的错误
安装好nagios打开网页出现下面问题
The requested URL /nagios/cgi-bin/statusmap.cgiwas not found on this server
解决方案,确定安装下面的包。
1.安装
gd-devel
回到nagios安装时解压开的目录
#make devclean
# ./configure --with-gd-lib=/usr/lib --with-gd-inc=/usr/include
接下来
#./configure --with-command-group=nagios
#make all; make install; make install-init; make install-config;make install-commandmode; make install-webconf
重新回到你的nagios的sbin目录查看几个cgi脚本有没有生成。
因为没有配置yum源,所以自以为上面的lib库应该都安装了。然后直接重新编译安装。后来发现还是不行。没办法,配置yum源,发现第一个gd库就没装了。一个个查,一个个装。从头到位从新配置。最后搞定....看来还是要耐心点。错误