首先在一台主机上安装Nagios然后用它来监控一台windows server2003和一台Linux主机
1,安装Nagios
=============================================================================
首先是安装Nagios需要下列软件包
httpd
gcc
glibc glibc-common
gd gd-devel
openssl-devel(个人建议这个软件包是远程监控Linux服务器关键软件包)
======================================================================
开始安装
useradd nagios
passwd nagios
groupadd nagcmd
usermod -G nagcmd nagios./-
usermod -G nagcmd apache #创建Nagios用户 创建组 把用户加入组 并加入apche
=======================================================================
mkdir ~/downloads
cd ~/downloads
wget
wget #下载Nagios和插件
========================================================================
cd ~/downloads
tar xzf nagios-3.0rc1.tar.gz
cd nagios-3.0rc1
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode #安装并编译软件 默认安装路径 /usr/local/nagios
make install-webconf # 配置web接口
==========================================================================
vi /usr/local/nagios/etc/objects/contacts.cfg #更改email地址nagiosadmin 作为报警接受邮件组或邮件个人
make install-webconf #安装Nagios的WEB配置文件到Apache的conf.d目录下
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin #创建一个nagiosadmin的用户用于Nagios的WEB接口登录。记下你所设置的登录口令,一会儿你会用到它
service httpd restart #重启Apache服务以使设置生效
===========================================================================
编译安装Nagios插件
cd ~/downloads
tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
make
make install
chkconfig --add nagios
chkconfig nagios on #把Nagios加入到服务列表中以使之在系统启动时自动启动
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #验证Nagios的样例配置文件 如果没有报错,可以启动Nagios服务
service nagios start
chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/ #不关闭SELinux或是永久性变更它的方法是让CGI模块在SELinux下指定强制目标模式:
================================================================================
安装完毕 访问Web页面 若想收到邮件报警安装sendmail 软件包
===================================================================================
监控Windows主机
首要条件
vi /usr/local/nagios/etc/nagios.cfg #编辑Nagios的主配置文件
把下面这行最前面的#号去掉:
#cfg_file=/usr/local/nagios/etc/objects/windows.cfg
安装windows代理程序NSClient
vi /usr/local/nagios/etc/objects/windows.cfg #编译配置文件
define host{
use windows-server ; Inherit default values from a Windows server template (make sure you keep this line!)
host_name winserver
alias My Windows Server
address 192.168.1.2
}
define service{
use generic-service
host_name winserver
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
}
efine service{
use generic-service
host_name winserver
service_description Uptime
check_command check_nt!UPTIME
}
define service{
use generic-service
host_name winserver
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}
define service{
use generic-service
host_name winserver
service_description C:\ Drive Space
check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
define service{
use generic-service
host_name winserver
service_description W3SVC
check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
}
define service{
use generic-service
host_name winserver
service_description Explorer
check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
}
最后保存退出
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #验证配置物件
从启服务
==============================================================================
监控Linux服务器
首先安装被监控服务器
需要下列软件包
openssl-devel
nrpe
useradd nagios
passwd nagios
tar -zxvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure
make
make install
=======================
这一步完成后会在/usr/local/nagios/下生成两个目录libexec和share
======================================
chown nagios.nagios /usr/local/nagios
然后
tar -zxvf nagios-nrpe_2.12.tar.gz
cd nagios-nrpe_2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
========================================================
vi /usr/local/nagios/etc/nrpe.cfg
将allowed_hosts=127.0.0.1
修改成你的nagios服务器的ip
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
启动nrpe
netstat -an|grep 5666
察看是否在5666端口上监听
注意:防火墙 释放端口5666,很重要 #建议直接把防火墙关掉 就可以了
vi /usr/local/nagios/etc/nrpe.cfg
可以看到里面监控对象
# The following examples use hardcoded command arguments...
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_hda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
===================================================
然后再启动nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
这样子,在监控端算是设置完了!!!
================================================================
安装nagios 服务器端设置
安装nagios-nrpe_2.12.tar.gz
这里安装过程比上面再被监控服务安装少两部
=========================================
tar -zxvf nagios-nrpe_2.12.tar.gz
cd nagios-nrpe_2.12
./configure
make all
make install-plugin
================================
然后我们测试下连通性
/usr/local/nagios/libexec/check_nrpe -H 被监控端ip
如果返回nrpe版本号,那么正常!
如果返回拒绝连接!那么telnet ip 5666看是否正常
======================================================
配置:
=================================
由于nrpe外构组件,所以必须在commands.cfg中定义(我这里的nagios版本是3.0.3和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$
}
========================================================
[root@localhost etc]# vi /usr/local/nagios/etc/nagios.cfg
中间添加
cfg_file=/usr/local/nagios/etc/objects/aiyo-mailserver.cfg
最后面的 aiyo-mailserver.cfg你们可以自己改,或者Linux1.cfg也可以!
=================================================
新建aiyo-mailserver.cfg
[root@localhost etc]# vi /usr/local/nagios/etc/objects/aiyo-mailserver.cfg
添加
define host{
use linux-server
host_name aiyo-mailserver
alias aiyo-mailserver
address 210.51.47.213
}
define service{
use generic-service
host_name aiyo-mailserver
service_description HTTP
check_command check_http
}
define service{
use generic-service
host_name aiyo-mailserver
service_description FTP
check_command check_ftp
define service{
use generic-service
host_name aiyo-mailserver
service_description SSH
check_command check_ssh
}
define service{
use generic-service
host_name aiyo-mailserver
service_description SMTP
check_command check_smtp
}
define service{
use generic-service
host_name aiyo-mailserver
service_description POP3
check_command check_pop
}
define service{
use generic-service
host_name aiyo-mailserver
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name aiyo-mailserver
service_description check-load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name aiyo-mailserver
service_description check-disk
check_command check_nrpe!check_had1
define service{
use generic-service
host_name aiyo-mailserver
service_description zombie_procs
check_command check_nrpe!check_zombie_procs
}
define service{
use generic-service
host_name aiyo-mailserver
service_description check-users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name aiyo-mailserver
service_description total_procs
check_command check_nrpe!check_total_procs
}
保存,退出!
这个里面定义了对象和服务!
注意:
define host{
use linux-server
这个你要能在commands.cfg找到!如果是3.0.x版本,应该就对的
!如果是2。x版本,不一样定了!
=====================================================
我们来运行
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
检测下是不是都正确!
================================================
正确的话,那么我们重新启动nagios
那么在web页面里面就会出现!!
=====================================