yum install httpd
yum install gcc
yum install glibc glibc-common
yum install gd gd-devel
|
/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的账号。
|
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
#
配置目录权限
|
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
|
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
|
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
端口
|
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
service nagios start
|
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
|
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
|
bin
|
Nagios
执
行程序所在目
录
,
nagios
文件即
为
主程序
|
etc
|
Nagios
配置文件位置
|
sbin
|
Nagios Cgi
文件所在目
录
,也就是
执
行外部
命令所需文件所在的目
录
|
Share
|
Nagios
网
页
文件所在的目
录
|
Var
|
Nagios
日志文件、
spid
等文件所在的目
录
|
var/archives
|
日志
归
档目
录
|
var/rw
|
用来存放外部命令文件
|
libexec
|
存放
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
|