2017年11月最新Nagios4.3.4部署


一 ,需下載的安裝包 2017-11-22

1,nagios-4.3.4.tar.gz, 2, nagios-plugins-2.2.1.tar.gz  3,nrpe-2.15.tar.gz ,4,pnp4nagios-head.tar.gz

我的安裝目錄為/nagios    /magios/pnp4nagios   /nagios/nrpe

二,安裝環境

yum install -y wget httpd php php-devel php-gd gcc glibc glibc-common gd gd-devel make net-snmp

三,添加 用戶 創建 nagios安裝目錄

useradd nagios

mkdir /nagios

chown -R nagios.nagios /nagios

四,安裝nagios4.3.4

 ./configure --prefix=/nagios --with-command-group=nagios --with-nagios-group=nagios

 make all
 make install
 make install-init
 make install-config
 make install-commandmode
 make install-webconf

2,把文件復制到安裝目錄

cp -R contrib/eventhandlers/  /nagios/libexec/
chown -R nagios.nagios /nagios/

3,檢測配置文件是否正常  

/nagios/bin/nagios -v /nagios/etc/nagios.cfg

Total Warnings: 0  #警告0個
Total Errors: 0       #錯誤0個    沒有問題

五,配置httpd

htpasswd -c /nagios/etc/htpasswd.users nagiosadmin #添加登錄用戶名 和回車后輸入兩次密碼 #這里一定要用nagiosadmin(超級)用戶 可以使用其他用戶 以后再說

修改/etc/httpd/conf/httpd.conf  如下:

User =nagios  Group=nagios

#ServerName www.example.com:80 #解釋掉#號  修改端口號  使其大於1024 使普通用戶nagios可以啟動

Listen 8080 #這個也要修改 和上面使用一樣的端口

六,安裝 nagios-plugins

./configure --prefix=/nagios --with-nagios-user=nagios --with-nagios-group=nagios

make 

make install

 七,設置開機自啟並啟動服務

  chkconfig nagios on

   service nagios start

   chkconfig httpd on

   service httpd start

service nagios start #啟動nagios  或者 /nagios/bin/nagios -d /nagios/etc/nagios.cfg  啟動  #ps -ef|grep nagios 可以過濾出nagios進程

訪問: nagios http://IP:port/nagios

                    默認有一個localhost.cfg 監控本地  我的httpd_prot:8080 所以爆錯

                                   二、為nagios安裝圖標pnp4nagios

 1,安裝組件

    yum install perl-Time-HiRes rrdtool  rrdtool-perl

2,安裝pnp4nagios

mkdir /nagios/pnp4nagios  #創建pnp4nagios 目錄

./configure --prefix=/nagios/pnp4nagios --with-nagios-user=nagios --with-nagios-group=nagios

下方為輸出信息

   make all  #編譯

   make install

   make install-webconf

   make install-config

   make install-init

3、啟用配置文件

cp /nagios/pnp4nagios/contrib/ssi  /nagios/pnp4nagios/share/ -R #將ssi目錄復制到share下面,不然后面圖片顯示會報錯

cd /nagios/pnp4nagios/etc/

 mv misccommands.cfg-sample misccommands.cfg

 mv nagios.cfg-sample nagios.cfg
 mv rra.cfg-sample rra.cfg
 cd pages/
 mv web_traffic.cfg-sample web_traffic.cfg
 cd ../check_commands/
 mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
 mv check_nrpe.cfg-sample check_nrpe.cfg
mv check_nwstat.cfg-sample check_nwstat.cfg

4,啟動npcd 

service npcd start  # 或者 /nagios/pnp4nagios/bin/npcd -d  -f /nagios/pnp4nagios/etc/npcd.cfg 啟動

chconfig npcd on  #開機自啟

      三,nagios配置修改文檔 其中npn4nagios是圖片繪圖顯示可以查看歷史數據

1,vi /nagios/etc/nagios.cfg   #需要時請備份源文件

      將process_performance_data=0  修改為  process_performance_data=1

      將以下兩項的#去掉

      host_perfdata_command=process-host-perfdata

      service_perfdata_command=process-service-perfdata

2,vi /nagios/etc/objects/commands.cfg #命令文件 可以自己添加命令

注釋掉末尾兩個配置項  新添加兩個

# 'process-host-perfdata' command definition
#define command{
# command_name process-host-perfdata
# command_line /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /nagios/var/host-perfdata.out
# }


# 'process-service-perfdata' command definition
#define command{
# command_name process-service-perfdata
# command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /nagios/var/service-perfdata.out
# }

define command{
command_name process-service-perfdata-file
command_line /bin/mv /nagios/pnp4nagios/var/service-perfdata /nagios/pnp4nagios/var/spool/service-perfdata.$TIMET$
}
define command{
command_name process-host-perfdata-file
command_line /bin/mv /nagios/pnp4nagios/var/host-perfdata /nagios/pnp4nagios/var/spool/host-perfdata.$TIMET$
}

3,編輯vi /nagios/etc/objects/templates.cfg 添加兩個url

define service{
name generic-service ; The 'name' of this service template
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service 'freshness'
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
is_volatile 0 ; The service is not volatile
check_period 24x7 ; The service can be checked at any time of the day
max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state
check_interval 5 ; Check the service every 10 minutes under normal conditions
retry_interval 2 ; Re-check the service every two minutes until a hard state can be determined
contact_groups admins ; Notifications get sent out to everyone in the 'admins' group
notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
notification_interval 60 ; Re-notify about service problems every hour
notification_period 24x7 ; Notifications can be sent out at any time
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$  添加內容
}


# Local service definition template - This is NOT a real service, just a template!

define service{
name local-service ; The name of this service template
use generic-service ; Inherit default values from the generic-service definition
max_check_attempts 4 ; Re-check the service up to 4 times in order to determine its final (hard) state
check_interval 5 ; Check the service every 5 minutes under normal conditions
retry_interval 1 ; Re-check the service every minute until a hard state can be determined
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$  添加內容
}

4,編輯vi /nagios/etc/nagios.cfg

# Values: 1 = process performance data, 0 = do not process performance data

process_performance_data=1

 

host_perfdata_file=/nagios/pnp4nagios/var/host-perfdata            #指定路徑
service_perfdata_file=/nagios/pnp4nagios/var/service-perfdata   #指定路徑

host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$                                                                      #解釋
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$

                              #解釋

host_perfdata_file_mode=a        #解釋
service_perfdata_file_mode=a   #解釋

host_perfdata_file_processing_interval=15  #修改
service_perfdata_file_processing_interval=15  #修改

host_perfdata_file_processing_command=process-host-perfdata-file          #解釋
service_perfdata_file_processing_command=process-service-perfdata-file  #解釋

5,檢測配置文件是否有誤

/nagios/bin/nagios -v /nagios/etc/nagios.cfg

6,由於我是自定義目錄安裝所以要配置vi /etc/httpd/conf.d/pnp4nagios.conf

 指定它的目錄Alias /pnp4nagios "/nagios/pnp4nagios/share"  以及  AuthUserFile /nagios/etc/htpasswd.users 密碼文件,建議指定到nagios的密碼文件不然你每一次都要重新輸入pnp4nagios密碼

 7,  重啟  nagios     httpd  

會有下圖 1 圖形  點擊后是 pnp4nagios 2圖 有提示刪除install.pnp  刪除后就會有下圖3  可能會報錯 有可能正在生成圖片 也有可能是權限問題

1 圖形 2圖形 

3圖形 

 

 

 

      四,客戶端插件nrpe 被監控客戶機設置

1,安裝nrpe依賴包

  yum install openssl openssl-devel -y 

2,安裝nrpe

./configure  --prefix=/nagios/nrpe --enable-ssl --with-nagios-user=nagios --with-nagios-group=nagios --with-nrpe-user=nagios --with-nrpe-group=nagios

 make all

   make install-plugin

   make install-daemon

   make install-daemon-config

   make install-xinetd

3、編輯nrpe配置文件,增加監控機地址Nagios-ip和本機IP:

      vi /etc/xinetd.d/nrpe

      only_from = 192.168.8.10,127.0.0.1

4、編輯vi /nagios/nrpe/nrpe.cfg

      allowed_hosts=192.168.8.10,127.0.0.1

5、修改services文件,增加端口
          vi /etc/services
          nrpe            5666/tcp                        #NRPE

6、啟動 nrpe

   /nagios/bin/nrpe -c /nagios/etc/nrpe.cfg -d

   設置開機啟動 #如果你發現主機是存活的服務全部不在 那就是服務器重啟了 

   vi /etc/rc.d/rc.local

   加入/nagios/bin/nrpe -c /nagios/etc/nrpe.cfg -d

7,nagios主機設置

1、vi /usr/local/nagios/etc/nagios.cfg

   加入cfg_file=/usr/local/nagios/etc/objects/192.168.8.11.cfg

2、創建並編輯192.168.8.11.cfg

   vi /usr/local/nagios/etc/objects/192.168.8.11.cfg

define host{
use linux-server
host_name 192.168.8.11
alias my
address 192.168.8.11
}
define service{
use generic-service
host_name 192.168.8.11
service_description Swap Usage
check_command check_local_swap!20!10
}
define service{
use generic-service
host_name 192.168.8.11
service_description check-load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
define service{
use generic-service
host_name 192.168.8.11
service_description Root Partition
check_command check_local_disk!20%!10%!/

}
define service{
use generic-service
host_name 192.168.8.11
service_description Swap Usage
check_command check_local_swap!20!10
}
define service{
use generic-service
host_name 192.168.8.11
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
}
define service{
use generic-service ; Name of service template to use
host_name 192.168.8.11
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use generic-service ; Name of service template to use
host_name 192.168.8.11
service_description HTTP_11
check_command check_http
notifications_enabled 0
}

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$ 

3、service nagios restart

   五、郵件報警設置

1,安裝郵件組件

 yum install mailx senmail*  -y

2,編輯郵箱並發送測試

vi /etc/mail.rc

set bsdcompat
set from=jie_linux@163.com 
set smtp=smtp.163.com
set smtp-auth-user=jie_linux@163.com
set smtp-auth-password="XXXXXXXXXXX"
set smtp-auth=login

進行測試:

echo "測試郵件"|nail -s "測試" 717122108@qq.com  

 

3、編輯contacts.cfg(聯系人)     command.cfg----下列郵件定義信息無需修改(nagios 4.3.4)

vi contacts.cfg  #只需要修改email就行 

define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user

email 717122108@qq.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

下方是郵件內容 一分鍾就刷出服務器DOWN了但郵件好慢  服務器起來時郵件是秒發  還需要調監控頻率 和 發送郵件的設置   

 

注:本文參考Jim的ChinaUnix博客 http://blog.chinaunix.net/uid-25896650-id-5069857.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM