系统环境
本文档主要实现nagios监控windows主机,nagios监控windows系统有三种实现方式:SNMP、NSClient++、NRPE。 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>
创建apache目录验证文件并重启apache
复制代码代码如下:
/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 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
访问nagios
1.windows设置
复制代码代码如下:
C:\>cd "NSClient++-Win32-0.3.5"
C:\NSClient++-Win32-0.3.5>nsclient++ /install l \NSClient++.cpp(193) Service installed!
编辑NES.ini
复制代码代码如下:
[modules] #去掉注释符号”;”除了CheckWMI.dll和RemoteConfiguration.dll
[Settings]
[NSClient]
启动nsclient服务并确认端口是否打开
复制代码代码如下:
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设置
复制代码代码如下:
# 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 #去掉这句话的注释
打开模块后配置windows.cfg
复制代码代码如下:
define host{
#把下面的host_name都改成winserver
define service{
打开windows模块,设置windows.cfg中相关被监控主机与监控内容后nagios服务器就配置完了,下面重启nagios然后看一下监控结果。
3.Nagios监控相关内容
etc
sbin
Share
Var
var/archives
var/rw
libexec
2)如何使用nagios插件 可以看到有很多插件我们也可以使用帮助来自己写监控代码
例如查看check_nt帮助
[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写法
#完整写法为
#监控磁盘使用
#如果要监控C盘,达到80%报警,达到90%为严重危险 (责任编辑:IT) |