2.2
操作过程
2.2.1
建立nagios账号
/usr/sbin/useradd nagios && passwd nagios
创建一个用户组名为nagcmd用于从Web接口执行外部命令。将nagios用户和apache用户都加到这个组中。
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nagios
/usr/sbin/usermod -G nagcmd apache
2.2.2
下载nagios和插件程序包
cd /usr/local/src
wget http://nchc.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.6.tar.gz
wget http://nchc.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz
2.2.3
编译与安装nagios
cd /usr/local/src
tar zxvf nagios-3.0.6.tar.gz
cd nagios-3.0.6
./configure --with-command-group=nagcmd --prefix=/usr/local/nagios
make all
make install
make install-init
make install-config
make install-commandmode
验证程序是否被正确安装。切换目录到安装路径(这里是/usr/local/nagios),
看是否存在 etc、bin、 sbin、 share、 var这五个目录,如果存在则可以表明程序被正确的安装到系统了。
后表是五个目录功能的简要说明:
bin Nagios执行程序所在目录,nagios文件即为主程序
etc Nagios配置文件位置,初始安装完后,只有几个*.cfg-sample文件,3与2区别 对象配置文件都在etc/objects目录下
sbin Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录
Share Nagios网页文件所在的目录
Var Nagios日志文件、spid 等文件所在的目录
var/archives Empty directory for the archived logs
var/rw Empty directory for the external command file
2.2.4
编译并安装nagios插件 nagios-plugins
cd /usr/local/src
tar zxvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure --with-nagios-user=nagios --with-nagios-group=nagios
--perfix=/usr/local/nagios
make && make install
验证:
ls /usr/local/nagios/libexec
会显示安装的插件文件,即所有的插件都安装在libexec这个目录下
2.2.5
配置WEB接口
方法一:直接在安装nagios时 make install-webconf
创建一个nagiosadmin的用户用于Nagios的WEB接口登录。记下你所设置的登录口令,一会儿你会用到它。
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
重启Apache服务以使设置生效。
service httpd restart
2.2.6
启动nagios
把Nagios加入到服务列表中以使之在系统启动时自动启动
chkconfig --add nagios
chkconfig nagios on
验证Nagios的样例配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果没有报错,可以启动Nagios服务
service nagios start
三:监控linux和windows主机
3.1 远程linux客户机的配置:
#useradd nagios
#passwd nagios
#tar -zxvf nagios-plugins-***.tar.gz
#cd nagios-plugins-***
#./configure
#make
#make install
#chown nagios.nagios /usr/local/nagios
#chown -R nagios.nagios /usr/local/nagios/libexec
#tar -zxvf nrpe-2.12.tar.gz
#cd nrpe-2.12
#./configure
#make all
#make install-plugin
#make install-daemon
#make install-daemon-config
#/usr/local/nagios/libexec/check_nrpe -H localhost
#/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
3.2监控机linux服务端的配置:
=================================
由于nrpe外构组件,所以必须在commands.cfg中定义(我这里的nagios版本是3.0.6和2。x的版本有些不一样)
[root@localhost etc]# vi /usr/local/nagios/etc/objects/commands.cfg
最下面添加
#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
========================================================