排版不太好,没有图文详解有的地方可能比较难理解,会不定期的更新详解,等我有空了
注意:nagios插件nagios-plugins+nrpe安装在被监控linux主机上,否则,不能被监控.别外因为它们间的通信是加密的SSL,所以在 编译安装时都要加上选项, ./configure --enable-ssl --with-ssl-lib=/lib/,否则也会出错.
1、 环境搭建
Server: nagios nagios-plugins nrpe 192.168.1.20
client: nagios-plugins nrpe 192.168.1.21
nagios服务器端(监控端192.168.1.20)
yum install httpd gettext mysql mysql-server mysql-devel php php-mysql php-pear glibc glibc-common gd gd-devel
在线下载nagios程序和插件,我个人是把nagios,nagios-plugins,nrpe下载到win7上通过winscp上传到linux主机上进行编译的,下面的这两个地址可以使用,版本和我使用的不太一样,请耐心
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
wget http://sourceforge.net/projects/nagios-cn/files/sourcecode/zh_CN%203.2.3/nagios-cn-3.2.3.tar.bz2/download
[root@localhost src]# useradd nagios
[root@localhost src]# groupadd nagcmd
[root@localhost src]# usermod -G nagcmd nagios
[root@localhost src]# usermod -G nagcmd apache
tar zxvf nagios-3.5.0.tar.gz
cd nagios
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
tar zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib=/usr/lib/
make all
make install-plugin
make install-daemon
make install-daemon-config
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
十、配置本机监控
根据如下配置,完成本机监控的配置,能实现nagios对本机的监控支持。
1、新建monitor文件夹,拷贝示例配置文件到该文件夹下
cd /usr/local/nagios/etc
cp -rf ./objects/* monitor
2、删除不需要得配置文件
cd /usr/local/nagios/etc/monitor
rm windows.cfg switch.cfg printer.cfg
3、修改contacts.cfg(联系人配置文件)
define contact{
contact_name nagios
use generic-contact
alias nagios
email [email protected]
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagios
}
4、修改cgi.cfg
default_user_name=nagios
5、修改nagios.cfg
将所有cfg_file=都注释掉添加如下一行
cfg_dir=/usr/local/nagios/etc/monitor
6、使用命令:/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg检查配置是否有误
7、重启nagios:/etc/init.d/nagios start
一定要记得启动http
/etc/init.d/httpd start
此时登录到nagios的web界面,就能查看到监控界面左侧的主机和服务中有我们配置好的本地监控的信息啦
nagios安装完后,使用check_http报HTTP WARNING: HTTP/1.1 403 Forbidden - 5240 bytes in 0.001 second response time |time=0.001260s;;;0.000000 size=5240B;;;0
原因是因为在webserver的发布目录中,没有找到index.html的文件
touch /var/www/html/index.html
在nagios的etc目录中增加check_nrpe检测
vim /usr/local/nagios/etc/monitor/commands.cfg
#'check_nrpe' command definition
define command{
command_name check_nrpe
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
增加21.cfg监控192.168.1.21服务器,这个配置在nagios服务端(监控端192.168.1.20端)
define host{
use linux-server
host_name test-1
alias test-1
address 192.168.1.21
}
define service{
use generic-service
host_name test-1
service_description ping
check_command check_nrpe!check_ping
}
define service{
use generic-service
host_name test-1
service_description check-disk
check_command check_nrpe!check_disk
}
define service{
use generic-service
host_name test-1
service_description check-users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name test-1
service_description check-procs
check_command check_nrpe!check_procs
}
define service{
use generic-service
host_name test-1
service_description check-load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name test-1
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name test-1
service_description check-ssh
check_command check_nrpe!check_ssh
}
vim /usr/local/nagios/etc/nrpe.cfg
allowed_host=192.168.1.21,127.0.0.1
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
lsof -i :5666
/usr/local/nagios/libexec/check_nrpe -H localhost
/etc/init.d/nagios restart
/etc/init.d/httpd restart
/etc/init.d/mysqld start(可以启动也可以不用启动)
有的时候多重启服务是没有错的,也许是某一个服务没有打开导致打不开监控页面
配置被监控服务器(被监控端192.168.1.21)
yum install openssl-devel
useradd nagios
tar zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib=/usr/lib/
make all
make install-plugin
make install-daemon
make install-daemon-config
vim /usr/local/nagios/etc/nrpe.cfg
allowed_host=192.168.1.20,127.0.0.1
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1 /dev/sda3
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
command[check_ssh]=/usr/local/nagios/libexec/check_ssh -4 127.0.0.1
command[check_ping]=/usr/local/nagios/libexec/check_ping -H 192.168.1.20 -w 40,20% -c 100,50% -p 3 -t 2
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
如果什么地方有错,请指正,我会改的
本文出自 “牛在天上飞” 博客,谢绝转载!