天天看點

NAGIOS+PNP4NAGIOS+SendEmail

1、最小化安裝Centos系統。

配置網絡位址使其可以上網。

2、安裝setup工具

yum  -y install   setuptool  ntsysv iptables system-config-securitylevel-tui system-config-network-tui system-config-firewall-tui make vim

3、修改顯示語言

[root@localhost ~]# more /etc/sysconfig/i18n

#LANG=”zh_CN.UTF-8″

LANG=”zh_CN.GB18030″

SYSFONT=”latarcyrheb-sun16″

4、安裝依賴包。

[root@KING ~]# yum -y install gcc glibc glibc-common gd gd-devel httpd

5、添加相應使用者及組

[root@KING conf]# groupadd nagcmd

[root@KING conf]# useradd -G nagcmd nagios

[root@KING conf]# useradd -G nagcmd apache

6、正式安裝nagios

#tar zxf nagios-3.4.1.tar.gz 

#cd nagios 

#./configure –prefix=/usr/local/nagios –with-command-group=nagcmd 

#make all                          

#make install                      

#make install-init                 

#make install-config              

#make install-commandmode          

#make install-webconf            

#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

7、編譯安裝nagios插件

#tar zvxf nagios-plugins-1.4.15.tar.gz 

#cd nagios-plugins-1.4.15 

#./configure –prefix=/usr/local/nagios –with-nagios-user=nagios –with-nagios-group=nagios 

#make && make install 

#chkconfig –add nagios

#chkconfig nagios on

#chkconfig httpd on

#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

#service nagios start

#vim /root/.bashrc

#添加一條alias check=’/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg’

#source /root/.bashrc

8、安裝後常見問題解決

問題1打開http://192.168.5.64/nagios輸入密碼驗證後出現“You don’t have permission to access /nagios/ on this server”

解決方法沒裝php導緻yum -y install php裝好重新開機httpd和nagios

問題2如果提示“Whoops!   Error: Could not read object configuration data! ”這是因為沒有啟動nagios背景程序執行以下指令

解決方法/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

問題3Nagios顯示類似錯誤HTTP WARNING: HTTP/1.1 403 Forbidden – 5240 bytes in 0.002 second response time。該錯誤表明在apache web根目錄沒有index.html檔案。

解決方法在web根目錄如:/var/www/html/目錄建立index.html檔案重新開機apache和nagios即可。

 問題4安裝nagios-pluginsmake時出現如下報錯

make[2]: *** [check_http.o] Error 1

make[2]: Leaving directory `/mnt/nagios-plugins-1.4.13/plugins’

make[1]: *** [all-recursive] Error 1

make[1]: Leaving directory `/mnt/nagios-plugins-1.4.13′

make: *** [all] Error 2

解決辦法yum -y install openssl openssl-devel然後重新執行./configure再編譯安裝。

9、設定nagios.cmd寫權限

chmod 777 /usr/local/nagios/var/rw/nagios.cmd

10、安裝nrpe用戶端

首先安裝SSL支援包[root@KING conf.d]# yum -y install openssl openssl-devel xinetd

安裝nrpe[root@KING nagios]# tar -zvxf nrpe-2.12.tar.gz

#cd nrpe-2.12

#./configure 

#make all

#make install-plugin

#make install-daemon

#make install-daemon-config

#make install-xinetd

vim /etc/xinetd.d/nrpe

only_from = 192.168.5.57

vim /etc/services

添加nrpe 5666/tcp #NRPE

重新開機xinetd服務。

測試下連通性在監控端執行

/usr/local/nagios/libexec/check_nrpe -H 被監控端的位址

如能顯示 “NRPE v2.12”表明NRPE可以和被監控端正常通信。

被監控端安裝nrpe

同監控端額外安裝插件

useradd -s /sbin/nologin nagios

#tar xzf nagios-plugins-1.4.15.tar.gz 

#cd nagios-plugins-1.4.15

#./configure –prefix=/usr/local/nagios –with-nagios-user=nagios –with-nagios-group=nagios

#make && make install

修改/usr/local/nagios/etc/objects/commands.cfg定義指令的檔案添加如下内容

define command {

    command_name    check_nrpe

    command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

11、定義監控

修改/usr/local/nagios/etc/nagios.cfg

去掉cfg_dir=/usr/local/nagios/etc/servers前面的注釋

mkdir //usr/local/nagios/etc/servers

添加檔案cacti_56.cfg

define host{                        

        use     linux-server             

        host_name    Cacti-56                

        alias     Cacti-56                    

        address    192.168.5.56           

define service{                      

        use     generic-service         

        host_name    Cacti-56               

        service_description   CPU Load 

        check_command    check_nrpe!check_load  

}                                             

define service{         

        use     generic-service

        host_name    Cacti-56

        service_description   Current Users

        check_command    check_nrpe!check_users

define service{

        service_description   Disk Free Space /

        check_command    check_nrpe!check_root

        service_description   Total Processes

        check_command    check_nrpe!check_total_procs

        service_description   Zombie Processes

        check_command    check_nrpe!check_zombie_procs

        use                             generic-service        

        host_name                       Cacti-56

        service_description             Swap Usage

        check_command                   check_nrpe!check_swap

        service_description             disk_/

        check_command                   check_nrpe!check_disk_/

        use                             generic-service      

        service_description             check_tcp_3306

        check_command                   check_tcp!3306

檢查配置檔案service nagios checkconfig

重新載入service nagios reload

12、修改聯系人配置檔案/usr/local/nagios/etc/objects/contacts.cfg

define contact{

        contact_name                    nagiosadmin            

        use                             generic-contact        

        alias                           Nagios Admin           

        host_notification_commands      notify-host-by-email

        service_notification_commands   notify-service-by-email

        email                           [email protected]       

        }

        contact_name                    nagios

        use                             generic-contact

        alias                           nagios

        email                           [email protected]

13、安裝圖形擴充工具pnp4nagios

安裝依賴包yum -y install php-gd rrdtool-perl rrdtool librrds-perl perl-Time-HiRes

tar zxf pnp4nagios-0.6.6.tar.gz

cd pnp4nagios-0.6.6.tar.gz

./configure –with-nagios-user=nagios –with-nagios-group=nagcmd     

make all                    

make install                 

make install-webconf         

make install-config          

make install-init           

[root@KING pnp4nagios-0.6.19]# cd /usr/local/pnp4nagios/etc

[root@KING etc]# rename .cfg-sample .cfg *.cfg-sample

[root@KING etc]# cd pages/

[root@KING pages]# rename .cfg-sample .cfg *.cfg-sample

[root@KING pages]# cd ../check_commands/

[root@KING check_commands]# rename .cfg-sample .cfg *.cfg-sample

service npcd restart

修改nagios的主配置檔案打開資料傳輸

vim nagios.cfg

process_performance_data=1                        

host_perfdata_command=process-host-perfdata                

service_perfdata_command=process-service-perfdata   #去掉注釋

修改nagios的指令配置檔案定義其使用的插件

vim commands.cfg

##添加

# ‘process-host-perfdata’ command definition

define command{

        command_name    process-host-perfdata

        command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl

# ‘process-service-perfdata’ command definition

        command_name    process-service-perfdata

        }             

配置nagios的樣本檔案定義後續要引用的類

vim templates.cfg

define host {

name       hosts-pnp

action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_

register   0

define service {

name       services-pnp

action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$

}                       

引用的類後面加上hosts-pnn或者services-pnp以“”隔開

重載nagios服務

/usr/local/pnp4nagios/var/perfdata/下生成以監控主機的cfg檔案名的檔案夾裡面會有.rrd和.xml的檔案

删除安裝檔案重新開機apache。

/usr/local/pnp4nagios/share/install.php

14、nagios報警郵件

關閉系統自身的郵件系統postfixservice postfix stop

wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.55.tar.gz

tar zxf sendEmail-v1.55.tar.gz

cd sendEmail-v1.55

cp sendEmail /usr/local/bin

chmod 755 /usr/local/bin/sendEmail

修改command.cfg檔案:

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.bobo365.com -u “**

$NOTIFICATIONTYPE$ alert – $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” -xu nagios -xp XXXXXX

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&7

1 永久方法 – 需要重新開機伺服器

修改/etc/selinux/config檔案中設定SELINUX=disabled 然後重新開機伺服器。

2 臨時方法 – 設定系統參數

使用指令setenforce 0

setenforce 1 設定SELinux 成為enforcing模式

setenforce 0 設定SELinux 成為permissive模式

繼續閱讀