Nagios是一款LInux上成熟的監視系統運行狀態和網絡信息的開源IT基礎設施監控系統。Nagios可以監控所指定的本地或遠程主機及服務,同時提供異常通知、事件處理等功能。它能夠運行在Linux平臺,同時還提供了基於瀏覽器的web界面,以方便系統管理人員查看系統的運行狀態,網絡狀態,各類系統問題及日誌異常等。php
Nagios的功能是監控服務和主機,可是其自身並不包含這些功能,全部的監控、檢測功能都是經過各類插件來完成的。啓動Nagios後,它會週期性地自動調用插件去檢測服務器狀態,同時Nagios會維持一個隊列,全部插件返回的狀態信息都進入隊列,Nagios每次都從隊列讀取信息,進行處理後,再把狀態結果經過Web界面顯示出來,這是被動模式。經常使用於監控主機的系統資源,好比系統負載、磁盤使用率、內存使用率、網絡狀態、系統進程數等。另外一種是主動模式,主要是Nagios服務器主動去獲取數據,經常使用於探測URL的監控和服務的狀態監控。html
主機名 | 操做系統 | IP地址 | 服務名 |
---|---|---|---|
nagios | centos7.4 | 192.168.96.81 | nagios-4.3.4.tar.gz、nagios-cn.4.3.4.tar.gz、nagios-plugins-2.2.1.tar.gz、pnp4nagios-0.6.26.tar.gz |
www | centos7.4 | 192.168.96.11 | nrpe-3.1.0.tar.gz |
客戶端 | windows 10 | 192.168.96.2 | 網頁瀏覽器 |
nagios/www服務器均關閉防火牆及SElinux功能linux
setenforece 0 systemctl stop firewalld
軟件包下載 密碼:yfdiios
yum install -y wget httpd php php-devel php-gd gcc glibc glibc-common gd gd-devel make net-snmp
useradd -s /sbin/nologin nagios
mkdir /usr/local/nagios chown -R nagios.nagios /usr/local/nagios/
#解壓 tar zxvf nagios-4.3.4.tar.gz cd nagios-4.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
cp -R contrib/eventhandlers /usr/local/nagios/libexec/
tar zxvf nagios-plugins-2.2.1.tar.gz cd nagios-plugins-2.2.1/
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make && make install
tar zxvf nagios-cn.4.3.4.tar.gz cd nagios-4.3.4/
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make all make install
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
vim /etc/httpd/conf/httpd.confweb
Listen 192.168.96.81:80 #41行,監聽地址及端口 #Listen 80 #42行,註釋該行 User nagios #66行,用戶爲nagios Group nagios #67行,用戶組爲nagios ServerName www.test01.com:80 #95行,域名 DirectoryIndex index.html index.php #164行,主頁類型添加index.php類型 AddType application/x-httpd-php .php #285行,添加php支持
systemctl enable httpd systemctl start httpd
netstat -tunlp
systemctl enable nagios systemctl start nagios
systemctl status nagios
yum install perl-Time-HiRes rrdtool rrdtool-perl -y
mkdir /usr/local/nagios/pnp4nagios
tar zxvf pnp4nagios-0.6.26.tar.gz cd pnp4nagios-0.6.26/
./configure --prefix=/usr/local/nagios/pnp4nagios --with-nagios-user=nagios --with-nagios-group=nagios
make all make fullinstall
cp -R contrib/ssi /usr/local/nagios/pnp4nagios/share/
cd /usr/local/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
chkconfig npcd on service npcd start
cd /usr/local/nagios/pnp4nagios/etc/ vim /usr/local/nagios/pnp4nagios/etc/process_perfdata.cfg #調整日誌級別 LOG_LEVEL = 2
vim /usr/local/nagios/etc/nagios.cfgapache
process_performance_data=1 enable_environment_macros=1 增長以下(若是不直接增長也能夠去掉註釋本身改) service_perfdata_command=process-service-perfdata host_perfdata_command=process-host-perfdata host_perfdata_file=/usr/local/nagios/pnp4nagios/var/host-perfdata service_perfdata_file=/usr/local/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
vim /usr/local/nagios/etc/objects/commands.cfg vim
把原有的兩個註釋掉,加入下面的 define command{ command_name process-host-perfdata command_line /usr/bin/perl /usr/local/nagios/pnp4nagios/libexec/process_perfdata.pl } define command{ command_name process-service-perfdata command_line /usr/bin/perl /usr/local/nagios/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA } define command{ command_name process-service-perfdata-file command_line /usr/local/nagios/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/service-perfdata } define command{ command_name process-host-perfdata-file command_line /usr/local/nagios/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/host-perfdata }
vim /usr/local/nagios/etc/objects/templates.cfg windows
define host { name host-pnp action_url /pnp4nagios/share/index.php/graph?host=$HOSTNAME$ register 0 } define service { name srv-pnp action_url /pnp4nagios/share/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$ register 0 }
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
systemctl restart nagios systemctl restart httpd
cd /usr/local/nagios/pnp4nagios/share/ rm -rf install.php
chown -R nagios.root /var/lib/php/session/