groupadd nagios
groupadd nagios
useradd nagios -g nagios -d /usr/local/nagios
chown nagios.nagios /usr/local/nagios/
chmod 755 /usr/local/nagios
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.2.tar.gz
tar -zxvf nagios-3.0.2.tar.gz
cd nagios-3.0.2
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
#編輯httpd.conf配置文件
ScriptAlias /nagios/cgi-bin "/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>
# 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>
killall httpd
wget plugins下載。
tar -zxvf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-gourp=nagios --with-mysql=/usr/local/mysql5/ --enable-perl-modules
make
make install
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
#對遠程一臺linux主機進行監控
#監控服務器上安裝nrpe
wget http://www.mirrors.wiretapped.net/security/network-monitoring/nagios/nrpe-2.8.1.tar.gz
#監控主機上安裝方法
tar -zxvf nrpe-2.8.1.tar.gz
cd nrpe-2.8.1
./configure
make all
make install
make install-plugin ---監控機需要安裝check_nrpe這個插件,被監控機並不需要
##########################################################################
#被監控主機上安裝方法
useradd nagios -d /usr/local/nagios
chown nagios.nagios /usr/local/nagios/
tar -zxvf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --enable-perl-modules --with-ping-command=ping
make
make install
tar -zxvf nrpe-2.8.1.tar.gz
cd nrpe-2.8.1
./configure
make all
make install
make install-plugin
make install-daemon
make install-daemon-config
vi /usr/local/nagios/etc/nrpe.conf
allowed_hosts=192.168.8.150
#爲了監控swap在nrpe.cfg中添加
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/sda1
#sdb1可根椐實際情況更改,我這裏的硬盤類型是scsi
#增加nrpe
nrpe 5666/tcp # nrpe
#啓動nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
netstat -an|grep 5666
#再對監控服務器進行設置
#添加nrpe的定義
vi /usr/local/nagios/etc/objects/commands.cfg
# 'check_nrpe ' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
把use_authentication=1修改爲use_authentication=0如果出現頁面無法顯示之類的
authorized_for_system_commands=nagiosadmin,kerry --kerry爲http訪問授權用戶
authorized_for_all_services=nagiosadmin,kerry
authorized_for_all_hosts=nagiosadmin,kerry
authorized_for_all_service_commands=nagiosadmin,kerry
authorized_for_all_host_commands=nagiosadmin,kerry
/usr/local/nagios/libexec/check_nrpe -H localhost
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
ehco "/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg" >>/etc/rc.local
#解決辦法:enable notifications for this service
#解決方法:ln -s /usr/local/lib/libgd.so.2 /usr/lib/libgd.so.2
#添加
cfg_file=/usr/local/nagios/etc/objects/emos-mailserver.cfg
#emos-mailserver.cfg這個文件名可以自定義
vi /usr/local/nagios/etc/objects/emos-mailserver.cfg
define host{
use linux-server
host_name emos-mailserver
alias emos-mailserver
address 192.168.8.151
}
define service{
use generic-service
host_name emos-mailserver
service_description HTTP
check_command check_http
}
define service{
use generic-service
host_name emos-mailserver
service_description SSH
check_command check_ssh
}
use generic-service
host_name emos-mailserver
service_description SMTP
check_command check_smtp
}
use generic-service
host_name emos-mailserver
service_description POP3
check_command check_pop
}
#define service{
# use generic-service
# host_name emos-mailserver
# service_description mysql
# check_command check_mysql
# }
define service{
use generic-service
host_name emos-mailserver
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name emos-mailserver
service_description check-load
check_command check_nrpe!check_load
use generic-service
host_name emos-mailserver
service_description check-disk
check_command check_nrpe!check_sda1
}
use generic-service
host_name emos-mailserver
service_description zombie_procs
check_command check_nrpe!check_zombie_procs
}
use generic-service
host_name emos-mailserver
service_description check-users
check_command check_nrpe!check_users
}
use generic-service
host_name emos-mailserver
service_description total_procs
check_command check_nrpe!check_total_procs
#配置完後,重啓nagios
killall nagios
service nagios start
pstree |grep nagios
cd /opt
tar zxvf pnp-0.4.12.tar.gz
cd pnp-0.4.12
./configure --with-nagios-user=nagios \
--with-nagios-group-nagios \
--with-rrdtool=/usr/local/rrdtool/bin/rrdtool \
--with-perfdata-dir=/usr/local/nagios/share/perfdata
make
make all
make install
make install-config
make install-init
#解決方法:ln -sv /usr/local/rrdtool/lib/perl/5.8.8/i386-linux-thread-multi/auto/RRDs/RRDs.so /usr/lib/perl5/5.8.8/i386-linux-thread-multi/
define command{
command_name process-service-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
process_performance_data=1
service_perfdata_command=process-service-perfdata
#監控windows服務器
wget [url]http://nchc.dl.sourceforge.net/sourceforge/nscplus/NSClient++-Win32-0.3.5.zip[/url]
解壓nsclient++0.3.3.zip到c盤根目錄
vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/windows.cfg 去掉這句話的註釋
CheckWMI.dll和RemoteConfiguration.dll
#[NSClient] 裏面,去掉port=12489的註釋!他靠端口12489偵聽,所以防火牆要打開這個端口!
nsclient++ /start
vi /usr/local/nagios/etc/objects/windows.cfg
define host{
use windows-server
host_name winserver alias
My Windows Server
address 192.168.8.151 --windows服務器的IP地址
}
#修改hostname和address,很重要!!
#重新啓動監控服務器上的nagios
killall nagios
service nagios start
#使用sendEmail發送報警郵件
cd /opt
wget [url]http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.55.tar.gz[/url]
tar -zxvf sendEmail-v1.55.tar.gz
cd sendEmail-v1.55
cp sendEmail /usr/local/bin
chmod +x /usr/local/bin/sendEmail
#sendEmail使用方法
/usr/local/bin/sendEmail –f [email protected] –t [email protected] –s mail.3aaa.com –u “from nagios” –xu [email protected] –xp 11111 –m happy
#解釋:-f 表示發送者的郵箱
-t 表示接收者的郵箱
-s 表示SMTP服務器的域名或者ip
-u 表示郵件的主題
-xu 表示SMTP驗證的用戶名
-xp 表示SMTP驗證的密碼(注意,這個密碼貌似有限制,例如我用d!5neyland就不能被正確識別)
-m 表示郵件的內容如果你不帶-m參數的話,就會提示你自行輸入
vi /usr/local/nagios/etc/objects/commands.cfg
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail –f [email protected] –t $CONTACTEMAIL$ –s mail.3aaa.com –u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" –xu[email protected] –xp 11111
}
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/local/bin/sendEmail –f [email protected] –t $CONTACTEMAIL$ –s mail.3aaa.com –u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" –xu[email protected] –xp 111111
}