近段時間一直在研究nagios監控系統,借鑑了很多高手的文章,費了很多功夫總算把它搞定了,如下就是具體的安裝過程,更深層的監控項目還有待進一步研究,但願你們給點建設!!
#===========================安裝 Nagios ========================================
cd /opt
groupadd nagios
groupadd nagcmd
useradd nagios -g nagcmd -d /usr/local/nagios
chown nagios.nagios /usr/local/nagios/
chmod 755 /usr/local/nagios
wget
[url]http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.2.tar.gz[/url]
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
/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#編輯httpd.conf配置文件
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
killall httpd
#配置和啓動nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#若是提示「Whoops! Error: Could not read object configuration data! 」,這是由於沒有啓動nagios後臺進程,執行如下命令
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
#=============================安裝nrpe 插件==============================
#對遠程一臺linux主機進行監控
#監控服務器上安裝設置
cd /opt
wget
[url]http://www.mirrors.wiretapped.net/security/network-monitoring/nagios/nrpe-2.8.1.tar.gz[/url]
#監控主機上安裝方法
tar -zxvf nrpe-2.8.1.tar.gz
cd nrpe-2.8.1
./configure
make all
make install
make install-plugin ---監控機須要安裝check_nrpe這個插件,被監控機並不須要
##########################################################################
#被監控主機上安裝方法
cd /opt
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
cd /opt
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
vi /etc/services
#增長nrpe
nrpe 5666/tcp # nrpe
#啓動nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
netstat -at|grep nrpe
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$
}
vi /usr/local/nagios/etc/cgi.cfg
把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
#測試NRPE是不然正常工做
/usr/local/nagios/libexec/check_nrpe -H localhost
killall nagios
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d" >> /etc/rc.local
ehco "/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg" >>/etc/rc.local
#問題:notifications for this service have been disabled
#解決辦法:enable notifications for this service
#問題:Status Map頁面沒法顯示
#解決方法:ln -s /usr/local/lib/libgd.so.2 /usr/lib/libgd.so.2
vi /usr/local/nagios/etc/nagios.cfg
#添加
cfg_file=/usr/local/nagios/etc/objects/emos-mailserver.cfg
#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
}
define service{
use generic-service
host_name emos-mailserver
service_description SMTP
check_command check_smtp
}
define service{
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
}
define service{
use generic-service
host_name emos-mailserver
service_description check-disk
check_command check_nrpe!check_sda1
}
define service{
use generic-service
host_name emos-mailserver
service_description zombie_procs
check_command check_nrpe!check_zombie_procs
}
define service{
use generic-service
host_name emos-mailserver
service_description check-users
check_command check_nrpe!check_users
}
define service{
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
#=============================安裝 pnp===============================================
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
#錯誤提示:RRDs Perl Modules: *** NOT FOUND ***
#解決方法: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/
#要產生圖形數據還需在commands.cfg中重定義命令:
define command{
command_name process-service-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
#產生圖形數據還要設定nagios.cfg文件:
process_performance_data=1
service_perfdata_command=process-service-perfdata
#在nagios監控服務器上
vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/windows.cfg 去掉這句話的註釋
#到win服務器上,打開命令窗口,cd到剛纔解壓的目錄
#在命令行界面執行 nsclient++ /install
#而後 nsclient++ SysTray 若是出錯不用管!
#此時在「服務」裏面已經有了nsclient的服務
雙擊打開,點"登陸"標籤,在"容許服務與桌面交互"前打勾
#編輯NES.ini,在 [modules] 選項裏,去掉全部的註釋符號; 除了
CheckWMI.dll和RemoteConfiguration.dll
#the [Settings] 選項裏
修改allowd_host=192.168.8.150(nagios服務器的ip)
#[NSClient] 裏面,去掉port=12489的註釋!他靠端口12489偵聽,因此防火牆要打開這個端口!
在[Settings]部分設置'password'選項來設置密碼,做用是在nagios鏈接過來時要求提供密碼.這一步是可選的,我這裏方便起見跳過它,不要密碼.
#而後啓動nsclient
nsclient++ /start
#接下來咱們開始配置nagios服務器裏面的內容
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
#編輯配置文件,nagios使用sendEmail來發警告郵件
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]kerry.hu@3aaa.com[/email] –t $CONTACTEMAIL$ –s mail.3aaa.com –u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" –xu
[email]kerry.hu@3aaa.com[/email] –xp 11111
}
# 'notify-service-by-email' command definition
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]kerry.hu@3aaa.com[/email] –t $CONTACTEMAIL$ –s mail.3aaa.com –u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" –xu
[email]kerry.hu@3aaa.com[/email] –xp 111111
}
#注:在使用sendEmail的過程當中沒法發送報警郵件,不知是什麼緣由,只好改用系統自帶的sendmail發郵件!!