Nagios监控windows服务器
平台及所用组件,
简单介绍
1.Nagios的安装
1.安装基础支持套件
yum install httpd
yum install gcc
yum install glibc glibc-common
yum install gd gd-devel |
2.创建帐号及组
/usr/sbin/useradd -m nagios
passwd nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd daemon #daemon为运行apache的账号。 |
3.安装nagios
tar -zxvf nagios-3.0.5.tar.gz
cd nagios-3.0.5
./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --with-gd-lib=/usr/lib/ --with-gd-inc=/usr/include/
make all
make install
make install-init #在/etc/rc.d/init.d安装启动脚本
make install-config #在/usr/local/nagios/etc安装示例配置文件
make install-commandmode #配置目录权限 |
4.配置apache
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory> |
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
service httpd restart #重启apache |
5.安装nagios-plugins
tar zxvf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
make
make install |
6.其它设置
chkconfig --add nagios #配置机器启动时自动启动Nagios
chkconfig nagios on
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #检查Nagios配置文件
vi /etc/selinux/config #关闭SELinux
SELINUX=disabled
service iptables stop #关闭SELinux,或打开80,5666端口 |
7.启动并访问
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
service nagios start |
2.监控Windows服务器
1.windows设置
C:\>cd "NSClient++-Win32-0.3.5"
C:\NSClient++-Win32-0.3.5>nsclient++ /install
l \NSClient++.cpp(193) Service installed! |
[modules] #去掉注释符号”;”除了CheckWMI.dll和RemoteConfiguration.dll
FileLogger.dll
CheckSystem.dll
CheckDisk.dll
NSClientListener.dll
[Settings]
allowd_host=192.168.0.20/32 #些处为nagios服务的IP
[NSClient]
port=12489 #去掉注释就可以了! |
C:\NSClient++-Win32-0.3.5>netstat -an | more
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 0.0.0.0:5666 0.0.0.0:0 LISTENING
TCP 0.0.0.0:12489 0.0.0.0:0 LISTENING |
2.nagios设置
vi /usr/local/nagios/etc/nagios.cfg
# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
# Definitions for monitoring a Windows machine
cfg_file=/usr/local/nagios/etc/objects/windows.cfg #去掉这句话的注释 |
vi /usr/local/nagios/etc/objects/windows.cfg
define host{
use windows-server
host_name winserver #被监控主机名
alias My Windows Server
address 192.168.0.8 ; 被监控的windows地址
#把下面的host_name都改成winserver
define service{
use generic-service
host_name winserver
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90 #监控CPU使用
}
define service{
use generic-service
host_name winserver
service_description Memory Usage
check_command check_nt!MEMUSE!-w 80 -c 90 #监控内存
} |
service nagios start |
3.Nagios监控相关内容
1).nagios目录功能的简要说明
bin |
Nagios执行程序所在目录,nagios文件即为主程序 |
etc |
Nagios配置文件位置 |
sbin |
Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录 |
Share |
Nagios网页文件所在的目录 |
Var |
Nagios日志文件、spid 等文件所在的目录 |
var/archives |
日志归档目录 |
var/rw |
用来存放外部命令文件 |
libexec |
存放nagios插件 |
2)如何使用nagios插件
[root@cxy ~]# ls /usr/local/nagios/libexec/
check_apt check_ftp check_mailq check_overcr check_tcp
check_breeze check_http check_mrtg check_ping check_time
check_by_ssh check_icmp check_mrtgtraf check_pop check_udp
check_clamd check_ide_smart check_nagios check_procs check_ups
check_cluster check_ifoperstatus check_nntp check_real check_users
check_dhcp check_ifstatus check_nntps check_rpc check_wave
check_dig check_imap check_nrpe check_sensors negate
check_disk check_ircd check_nt check_simap urlize |
[root@cxy libexec]# pwd
/usr/local/nagios/libexec
[root@cxy libexec]# ./check_nt -h
Usage:check_nt -H host -v variable [-p port] [-w warning] [-c critical][-l params] [-d SHOWALL] [-t timeout]
#监控CPU写法
CPULOAD =
Average CPU load on last x minutes.
Request a -l parameter with the following syntax:
-l <minutes range>,<warning threshold>,<critical threshold>.
<minute range> should be less than 24*60.
Thresholds are percentage and up to 10 requests can be done in one shot.
ie: -l 60,90,95,120,90,95
#完整写法为
check_nt!CPULOAD!-l 5,80,90
check_nt调用cpuload,5分钟内负载平均达到80%为warning,负载达到90%为critical |
USEDDISKSPACE =
Size and percentage of disk use.
Request a -l parameter containing the drive letter only.
Warning and critical thresholds can be specified with -w and -c.
#如果要监控C盘,达到80%报警,达到90%为严重危险
check_nt!USEDDISKSPACE!-l c -w 80 -c 90 |