Nagios是一款開源電腦系統和網絡監視工具,能夠有效監控windows,linux,Uninx的主機狀態,交換機路由器等網絡設置,打印機等.在系統或服務狀態異常時發出郵件或短信報警第一時間通知運維人員,在狀態恢復后發出正常的郵件或短信報警通知。
Nagios Core 是一個開源的系統,Nagios XI是收費的。我們這里安裝前者。
一、Nagios 結構說明
Nagios 結構上來說, 可分為核心和插件兩個部分。Nagios 的核心部分只提供了很少的監控功能,因此要搭建一個完善的 IT 監控管理系統,用戶還需要在 Nagios 服務器安裝相應的插件,插件可以從 Nagios 官方網站下載 http://www.nagios.org/,也可以根據實際要求自己編寫所需的插件。
Nagios 可實現的功能特性:
????監控網絡服務(SMTP、POP3、HTTP、FTP、PING 等);
????監控本機及遠程主機資源(CPU 負荷、磁盤利用率、進程 等);
????允許用戶編寫自己的插件來監控特定的服務,方便地擴展自己服務的檢測方法,支持多種開發語言(Shell、Perl、Python、PHP 等)
????具備定義網絡分層結構的能力,用"parent"主機定義來表達網絡主機間的關系,這種關系可被用來發現和明晰主機宕機或不可達狀態;
????當服務或主機問題產生與解決時將告警發送給聯系人(通過 EMail、短信、用戶定義方式);
????可以支持并實現對主機的冗余監控;
????可用 WEB 界面用于查看當前的網絡狀態、通知和故障歷史、日志文件等;
二.Nagios工作原理
Nagiosq的功能是監控服務和主機,但也是 他 自身并不包括這部分功能,所有的監控,檢測功能都是通過各種插件來完成的。
啟動Nagios后他會周期性的自動調用插件去檢查服務器狀態 ,同時Nagios會維持一個列隊,所有插件返回來的狀態信息都進入列隊 ,Nagios每次都從隊首開始讀取信息,并進行處理,把狀態結果通過web結果通過顯示出來
Nagios提供了許多插件,利用這些插件可以方便的監控很多服務狀態,安裝完成 后,在Nagios主目錄下的/libexec里放有nagios自的可以使用的所有插件,如,check_disk是檢查磁盤空間的插件,check_load是檢查CPU負載的,等等。每一個插件可以通過運行 ./check_xxx –h 來查看使用方法和功能;
Nagios可以識別4種狀態返回信息,即0(OK)表示狀態正常/綠色,1(WARNING)表示出現警告/X色,2(CRITTCAL)表示出現 非常嚴重 的錯誤/紅色,3(UNKNOWN)表示未知錯誤 、深X色。Nagios根據插件返回來的值,來判斷 監控對象的狀態,并通過web顯示出來,以提供管理員及時發現故障
再說報警功能,如果 監控系統發現問題不能報警那就沒有意義了,所以報警也是nagios很重要的功能之一,但是,同樣的,Nagios自身業沒有報警部分的代碼,甚至沒有插件,而是交給用戶或者其他 相關開源項目組去完成
Nagios安裝,是指基本平臺,也就是Nagios軟件包的安裝,它是監控體系的框架,也是所有監控基礎。
Nagios通過NRPE來遠端管理服務
????Nagios執行安裝在它里面的check_nrpe插件,并告訴check_nrpe去檢測哪些服務。
????通過SSL,check_nrpe連接遠端 機子上的NRPE daemon
????NRPE運行本地的各種插件去檢測本地的服務和狀態
????最后,NRPE把檢測的結果傳給主機端check_nrpe,check_nrpe在把結果 送到Nagios狀態隊列中,
????Nagios依次讀取隊列中信息,再把結果顯示出來
二.Nagios部署
備注:默認情況下Nagios沒有數據庫,可以安裝NDOUtils保存Nagios數據到Mysql數據庫中。
1、環境準備
設置或停止防火墻:
[root@localhost?~]#?systemctl?stop?firewalld.service [root@localhost?~]#?systemctl?disable?firewalld.service
關閉selinux:
臨時關閉: [root@localhost?~]#?setenforce?0 永久關閉(修改配置文件): [root@localhost?~]#?vi?/etc/selinux/config 改成SELINUX=disabled
[root@localhost?~]#?rpm?-qa?httpd* [root@localhost?~]#?rpm?-e?--nodeps?包名 有多個httpd*,用腳本刪除for?name?in?`rpm?-qa?httpd*`;do?rpm?-e?--nodeps?$name;done
[root@localhost?~]#?rpm?-Uvh?https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm [root@localhost?~]#?yum?install?wget?lrzsz?vim?lynx?lsof?netstat-tools?unzip?-y
時區設置:
[root@localhost?~]timedatectl [root@localhost?~]timedatectl?list-timezones??#該命令列出了所有的時區 [root@localhost?~]timedatectl?set-timezone?Asia/Shanghai?#該命令把時區設置為上海
時間同步:
[root@localhost?~]#?ntpdate?time.nist.gov?#如果沒有yum安裝此命令 [root@localhost?~]#?/usr/sbin/ntpdate?time.nist.gov [root@localhost?~]#?crontab?-e */10****?/usr/sbin/ntpdate?time.nist.gov?>/dev/null?2>&1
2、源碼安裝nagios core(主程序)
參考:https://support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html#_ga=2.130440076.2034626946.1559144380-1378811618.1556870555
[root@localhost?~]#?yum?install?-y?gcc?glibc?glibc-common?wget?unzip?httpd?php?gd?php-gd?gd-devel?perl?postfix [root@localhost?~]#?cd?/tmp [root@localhost?tmp]#?wget?-O?nagioscore.tar.gz?https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.3.tar.gz [root@localhost?tmp]#?tar?zxvf?nagioscore.tar.gz [root@localhost?tmp]#?cd?/tmp/nagioscore-nagios-4.4.3/ [root@localhost?nagioscore-nagios-4.4.3]#?./configure [root@localhost?nagioscore-nagios-4.4.3]#?make?all [root@localhost?nagioscore-nagios-4.4.3]#?make?install-groups-users [root@localhost?nagioscore-nagios-4.4.3]#?usermod?-a?-G?nagios?apache
#安裝主程序
[root@localhost?nagioscore-nagios-4.4.3]#?make?install [root@localhost?nagioscore-nagios-4.4.3]#?make?install-daemoninit [root@localhost?nagioscore-nagios-4.4.3]#?systemctl?enable?httpd.service
#配置目錄權限
[root@localhost?nagioscore-nagios-4.4.3]#?make?install-commandmode
#安裝示例配置文件
[root@localhost?nagioscore-nagios-4.4.3]#?make?install-config
#安裝nagios的web接口,會在/etc/httpd/conf.d目錄中創建nagios.conf文件
[root@localhost?nagioscore-nagios-4.4.3]#?make?install-webconf
執行上述操作后,會在/usr/local/nagios目錄下產生如下目錄:
bin:nagios執行程序所在的目錄,nagios文件即為主程序。
etc:nagios配置文件目錄,當make install-config完以后etc下面就會出現默認的配置文件。
sbin:nagios CGI文件所在目錄,這里存放的是一些外部命令執行程序。
share:nagios網頁文件目錄,存放一些html文件。
var:nagios日志文件、pid等文件目錄。
Libexec:系統默認插件的存儲位置
修改nagios警告信息的郵件地址
[root@localhost?~]#?vi?/usr/local/nagios/etc/objects/contacts.cfg ????email???????????????????442102293@qq.com?;?<<*****?CHANGE?THIS?TO?YOUR?EMAIL?ADDRESS?******
nagiosadmin設置密碼
root@localhost?~]#?htpasswd?-c?/usr/local/nagios/etc/htpasswd.users?nagiosadmin [root@localhost?~]#?systemctl?start?httpd.service [root@localhost?~]#?systemctl?start?nagios.service
http://192.168.146.128/nagios
不使用默認nagiosadmin賬號,新增gxm賬號并配置權限,如果不配置點擊Hosts會報紅色錯誤。
[root@localhost?~]#?htpasswd?-bc?/usr/local/nagios/etc/htpasswd.users?gxm?123456
[root@localhost?~]#?cd?/usr/local/nagios/etc/ [root@localhost?etc]#?sed?-i?'s#nagiosadmin#gxm#g'?cgi.cfg [root@localhost?etc]#?grep?gxm?cgi.cfg authorized_for_system_information=gxm authorized_for_configuration_information=gxm authorized_for_system_commands=gxm authorized_for_all_services=gxm authorized_for_all_hosts=gxm authorized_for_all_service_commands=gxm authorized_for_all_host_commands=gxm [root@localhost?etc]#?systemctl?restart??httpd.service
#檢查語法錯誤
[root@localhost?etc]#?/usr/local/nagios/bin/nagios?-v?/usr/local/nagios/etc/nagios.cfg Nagios?Core?4.4.3 Copyright?(c)?2009-present?Nagios?Core?Development?Team?and?Community?Contributors Copyright?(c)?1999-2009?Ethan?Galstad Last?Modified:?2019-01-15 License:?GPL Website:?https://www.nagios.org Reading?configuration?data... ???Read?main?config?file?okay... ???Read?object?config?files?okay... Running?pre-flight?check?on?configuration?data... Checking?objects... ????Checked?8?services. ????Checked?1?hosts. ????Checked?1?host?groups. ????Checked?0?service?groups. ????Checked?1?contacts. ????Checked?1?contact?groups. ????Checked?24?commands. ????Checked?5?time?periods. ????Checked?0?host?escalations. ????Checked?0?service?escalations. Checking?for?circular?paths... ????Checked?1?hosts ????Checked?0?service?dependencies ????Checked?0?host?dependencies ????Checked?5?timeperiods Checking?global?event?handlers... Checking?obsessive?compulsive?processor?commands... Checking?misc?settings... Total?Warnings:?0 Total?Errors:???0 Things?look?okay?-?No?serious?problems?were?detected?during?the?pre-flight?check
3、安裝nagios插件(監控功能通過插件完成)
上述安裝的Nagios主程序只是一個控制中心,而能夠起到服務監測和系統監測等功能的是眾多Nagios的插件,沒有插件的Nagios系統其實只是一個空殼。因此在安裝了Nagios平臺之后我們還需要安裝插件。
[root@localhost?~]#?yum?install?-y?gcc?glibc?glibc-common?make?gettext?automake?autoconf?wget?openssl-devel?net-snmp?net-snmp-utils?epel-release [root@localhost?~]#?yum?install?-y?perl-Net-SNMP 或者 [root@localhost?~]#?cd?/tmp [root@localhost?~]#?wget?https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm [root@localhost?~]#?rpm?-ihv?epel-release-latest-7.noarch.rpm [root@localhost?~]#?subscription-manager?repos?--enable=rhel-7-server-optional-rpms [root@localhost?~]#?yum?install?-y?gcc?glibc?glibc-common?make?gettext?automake?autoconf?wget?openssl-devel?net-snmp?net-snmp-utils [root@localhost?~]#?yum?install?-y?perl-Net-SNMP [root@localhost?~]#?cd?/tmp [root@localhost?~]#?wget?--no-check-certificate?-O?nagios-plugins.tar.gz?https://github.com/nagios-plugins/nagios-plugins/archive/release-2.2.1.tar.gz [root@localhost?~]#?tar?zxvf?nagios-plugins.tar.gz [root@localhost?~]#?cd?/tmp/nagios-plugins-release-2.2.1/ [root@localhost?nagios-plugins-release-2.2.1]#?./tools/setup [root@localhost?nagios-plugins-release-2.2.1]#?./configure [root@localhost?nagios-plugins-release-2.2.1]#?make [root@localhost?nagios-plugins-release-2.2.1]#?make?install [root@localhost?nagios-plugins-release-2.2.1]#?systemctl?start?nagios.service [root@localhost?nagios-plugins-release-2.2.1]#?systemctl?stop?nagios.service [root@localhost?nagios-plugins-release-2.2.1]#?systemctl?restart?nagios.service [root@localhost?nagios-plugins-release-2.2.1]#?systemctl?status?nagios.service [root@localhost?libexec]#?ll?/usr/local/nagios/libexec -rwxr-xr-x?1?root?root?210656?5月??31?11:54?check_apt -rwxr-xr-x?1?root?root???2354?5月??31?11:54?check_breeze -rwxr-xr-x?1?root?root?214653?5月??31?11:54?check_by_ssh lrwxrwxrwx?1?root?root??????9?5月??31?11:54?check_clamd?->?check_tcp -rwxr-xr-x?1?root?root?163022?5月??31?11:54?check_cluster -r-sr-xr-x?1?root?root?211527?5月??31?11:54?check_dhcp -rwxr-xr-x?1?root?root?227293?5月??31?11:54?check_disk -rwxr-xr-x?1?root?root???9477?5月??31?11:54?check_disk_smb -rwxr-xr-x?1?root?root?127110?5月??31?11:54?check_dummy -rwxr-xr-x?1?root?root???3868?5月??31?11:54?check_file_age -rwxr-xr-x?1?root?root???6512?5月??31?11:54?check_flexlm lrwxrwxrwx?1?root?root??????9?5月??31?11:54?check_ftp?->?check_tcp -rwxr-xr-x?1?root?root?209501?5月??31?11:54?check_hpjd -rwxr-xr-x?1?root?root?375004?5月??31?11:54?check_http -r-sr-xr-x?1?root?root?227225?5月??31?11:54?check_icmp -rwxr-xr-x?1?root?root?169900?5月??31?11:54?check_ide_smart -rwxr-xr-x?1?root?root??15283?5月??31?11:54?check_ifoperstatus -rwxr-xr-x?1?root?root??13435?5月??31?11:54?check_ifstatus lrwxrwxrwx?1?root?root??????9?5月??31?11:54?check_imap?->?check_tcp -rwxr-xr-x?1?root?root???6992?5月??31?11:54?check_ircd lrwxrwxrwx?1?root?root??????9?5月??31?11:54?check_jabber?->?check_tcp -rwxr-xr-x?1?root?root?187685?5月??31?11:54?check_load -rwxr-xr-x?1?root?root???6673?5月??31?11:54?check_log -rwxr-xr-x?1?root?root??22741?5月??31?11:54?check_mailq -rwxr-xr-x?1?root?root?173210?5月??31?11:54?check_mrtg -rwxr-xr-x?1?root?root?170431?5月??31?11:54?check_mrtgtraf -rwxr-xr-x?1?root?root?186817?5月??31?11:54?check_nagios lrwxrwxrwx?1?root?root??????9?5月??31?11:54?check_nntp?->?check_tcp lrwxrwxrwx?1?root?root??????9?5月??31?11:54?check_nntps?->?check_tcp -rwxr-xr-x?1?root?root?219815?5月??31?11:54?check_nt -rwxr-xr-x?1?root?root?218463?5月??31?11:54?check_ntp -rwxr-xr-x?1?root?root?208212?5月??31?11:54?check_ntp_peer -rwxr-xr-x?1?root?root?207193?5月??31?11:54?check_ntp_time -rwxr-xr-x?1?root?root?250160?5月??31?11:54?check_nwstat -rwxr-xr-x?1?root?root???9461?5月??31?11:54?check_oracle -rwxr-xr-x?1?root?root?193042?5月??31?11:54?check_overcr -rwxr-xr-x?1?root?root?223263?5月??31?11:54?check_ping lrwxrwxrwx?1?root?root??????9?5月??31?11:54?check_pop?->?check_tcp -rwxr-xr-x?1?root?root?224192?5月??31?11:54?check_procs -rwxr-xr-x?1?root?root?185576?5月??31?11:54?check_real -rwxr-xr-x?1?root?root???9687?5月??31?11:54?check_rpc -rwxr-xr-x?1?root?root???1537?5月??31?11:54?check_sensors lrwxrwxrwx?1?root?root??????9?5月??31?11:54?check_simap?->?check_tcp -rwxr-xr-x?1?root?root?268781?5月??31?11:54?check_smtp -rwxr-xr-x?1?root?root?269786?5月??31?11:54?check_snmp lrwxrwxrwx?1?root?root??????9?5月??31?11:54?check_spop?->?check_tcp -rwxr-xr-x?1?root?root?185227?5月??31?11:54?check_ssh lrwxrwxrwx?1?root?root??????9?5月??31?11:54?check_ssmtp?->?check_tcp -rwxr-xr-x?1?root?root?166806?5月??31?11:54?check_swap -rwxr-xr-x?1?root?root?252843?5月??31?11:54?check_tcp -rwxr-xr-x?1?root?root?186950?5月??31?11:54?check_time lrwxrwxrwx?1?root?root??????9?5月??31?11:54?check_udp?->?check_tcp -rwxr-xr-x?1?root?root?199442?5月??31?11:54?check_ups -rwxr-xr-x?1?root?root?163288?5月??31?11:54?check_uptime -rwxr-xr-x?1?root?root?157647?5月??31?11:54?check_users -rwxr-xr-x?1?root?root???3040?5月??31?11:54?check_wave -rwxr-xr-x?1?root?root?157770?5月??31?11:54?negate -rwxr-xr-x?1?root?root?151307?5月??31?11:54?urlize -rwxr-xr-x?1?root?root???1914?5月??31?11:54?utils.pm -rwxr-xr-x?1?root?root???2791?5月??31?11:54?utils.sh
4、安裝nrpe(在需要監控的服務器上部署)
NRPE依賴于nagios-plugins,所以要一起安裝。
可參考:https://support.nagios.com/kb/article.php?id=515
[root@localhost?~]#?yum?install?-y?gcc?glibc?glibc-common?openssl?openssl-devel?perl?wget [root@localhost?~]#?cd?/tmp [root@localhost?~]#?wget?--no-check-certificate?-O?nrpe.tar.gz?https://github.com/NagiosEnterprises/nrpe/archive/nrpe-3.2.1.tar.gz [root@localhost?~]#?tar?zxvf?nrpe.tar.gz [root@localhost?~]#?cd?/tmp/nrpe-nrpe-3.2.1/ [root@localhost?nrpe-nrpe-3.2.1]#?./configure?--enable-command-args [root@localhost?nrpe-nrpe-3.2.1]#?make?all [root@localhost?nrpe-nrpe-3.2.1]#?make?install-groups-users [root@localhost?nrpe-nrpe-3.2.1]#?make?install [root@localhost?nrpe-nrpe-3.2.1]#?make?install-config [root@localhost?nrpe-nrpe-3.2.1]#?echo?>>?/etc/services [root@localhost?nrpe-nrpe-3.2.1]#?echo?'#?Nagios?services'?>>?/etc/services [root@localhost?nrpe-nrpe-3.2.1]#?echo?'nrpe?5666/tcp'?>>?/etc/services [root@localhost?nrpe-nrpe-3.2.1]#?make?install-init [root@localhost?nrpe-nrpe-3.2.1]#?systemctl?enable?nrpe.service
#添加nagios服務器IP,運行服務器連接nrpe
[root@localhost?nrpe-nrpe-3.2.1]#?vi?/usr/local/nagios/etc/nrpe.cfg allowed_hosts=127.0.0.1,192.168.146.128 dont_blame_nrpe=1 [root@localhost?nrpe-nrpe-3.2.1]#?systemctl?start?nrpe.service [root@localhost?~]#?cat?/usr/lib/systemd/system/nrpe.service [root@localhost?nrpe-nrpe-3.2.1]#?/usr/local/nagios/libexec/check_nrpe?-H?127.0.0.1 NRPE?v3.2.1 [root@localhost?nrpe-nrpe-3.2.1]#?/usr/local/nagios/libexec/check_nrpe?-H?192.168.146.128 NRPE?v3.2.1
測試插件和NRPE
[root@localhost?nrpe-nrpe-3.2.1]#?vi?/usr/local/nagios/etc/nrpe.cfg command[check_load]=/usr/local/nagios/libexec/check_load?-w?15,10,5?-c?30,25,20 [root@localhost?nrpe-nrpe-3.2.1]#?/usr/local/nagios/libexec/check_nrpe?-H?127.0.0.1?-c?check_load WARNING?-?load?average:?0.06,?0.06,?0.09|load1=0.060;0.150;0.300;0;?load5=0.060;0.100;0.250;0;?load15=0.090;0.050;0.200;0; [root@localhost?~]#?netstat?-tnlp Active?Internet?connections?(only?servers) Proto?Recv-Q?Send-Q?Local?Address???????????Foreign?Address?????????State???????PID/Program?name???? tcp????????0??????0?0.0.0.0:22??????????????0.0.0.0:*???????????????LISTEN??????1062/sshd??????????? tcp????????0??????0?127.0.0.1:25????????????0.0.0.0:*???????????????LISTEN??????1372/master????????? tcp????????0??????0?0.0.0.0:5666????????????0.0.0.0:*???????????????LISTEN??????60275/nrpe?????????? tcp6???????0??????0?:::80???????????????????:::*????????????????????LISTEN??????57918/httpd????????? tcp6???????0??????0?:::22???????????????????:::*????????????????????LISTEN??????1062/sshd??????????? tcp6???????0??????0?::1:25??????????????????:::*????????????????????LISTEN??????1372/master????????? tcp6???????0??????0?:::5666?????????????????:::*????????????????????LISTEN??????60275/nrpe
5、安裝PNP插件(監控功能通過插件完成)
可參考:https://www.cnblogs.com/caoguo/p/5022230.html
[root@localhost?~]#?yum?-y?install?rrdtool?librrds-perl?perl-rrdtool?-y [root@localhost?~]#?tar?zxvf?pnp4nagios-0.6.26.tar.gz [root@localhost?~]#?cd?pnp4nagios-0.6.26 [root@localhost?pnp4nagios-0.6.26]#?./configure?--with-nagios-user=nagios?--with-nagios-group=nagios [root@localhost?pnp4nagios-0.6.26]#?make?all [root@localhost?pnp4nagios-0.6.26]#?make?install [root@localhost?pnp4nagios-0.6.26]#?make?install-webconf [root@localhost?pnp4nagios-0.6.26]#?make?install-config [root@localhost?pnp4nagios-0.6.26]#?make?install-init [root@localhost?pnp4nagios-0.6.26]#?cd?./sample-config [root@localhost?pnp4nagios-0.6.26]#?make?install-webconf
配置pnp4nagios
[root@localhost?pnp4nagios-0.6.26]#?cd?/usr/local/pnp4nagios/etc/ [root@localhost?etc]#?mv?misccommands.cfg-sample?misccommands.cfg [root@localhost?etc]#?mv?rra.cfg-sample?rra.cfg [root@localhost?etc]#?mv?nagios.cfg-sample?nagios.cfg [root@localhost?etc]#?cd?pages/ [root@localhost?pages]#?mv?web_traffic.cfg-sample?web_traffic.cfg [root@localhost?pages]#?cd?../check_commands/ [root@localhost?check_commands]#?mv?check_all_local_disks.cfg-sample?check_all_local_disks.cfg [root@localhost?check_commands]#?mv?check_nrpe.cfg-sample?check_nrpe.cfg [root@localhost?check_commands]#?mv?check_nwstat.cfg-sample?check_nwstat.cfg [root@localhost?check_commands]#?/etc/init.d/npcd?start [root@localhost?check_commands]#?chkconfig?npcd?on 配置Nagios數據輸出接口(以BULK模式運行)詳情參考官網https://docs.pnp4nagios.org/pnp-0.6/config#bulk_mode:
[root@localhost?~]#?vi?/usr/local/nagios/etc/nagios.cfg process_performance_data=1?#默認為0,修改為1 并在該文件中添加下面的內容 # #?service?performance?data # service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$ service_perfdata_file_mode=a service_perfdata_file_processing_interval=15 service_perfdata_file_processing_command=process-service-perfdata-file # #?host?performance?data?starting?with?Nagios?3.0 # host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$ host_perfdata_file_mode=a host_perfdata_file_processing_interval=15 host_perfdata_file_processing_command=process-host-perfdata-file
配置command.cfg:
[root@localhost?~]#?vi?/usr/local/nagios/etc/objects/commands.cfg 在該文件中添加下面的內容 define?command{ ???????command_name????process-service-perfdata-file ???????command_line????/usr/local/pnp4nagios/libexec/process_perfdata.pl?--bulk=/usr/local/pnp4nagios/var/service-perfdata } define?command{ ???????command_name????process-host-perfdata-file ???????command_line????/usr/local/pnp4nagios/libexec/process_perfdata.pl?--bulk=/usr/local/pnp4nagios/var/host-perfdata }
在模板配置文件中添加圖表圖標模板:
[root@localhost?~]#?vi?/usr/local/nagios/etc/objects/templates.cfg 在該文件中添加下面的內容 define?host?{ ???name???????host-pnp ???action_url?/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_ ???register???0 } define?service?{ ??name???????service-pnp ??action_url?/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$ ???register???0 }
在監控主機和服務中調用圖表模板(在主機和服務后面添加新的模板):
[root@localhost ~]# vi /usr/local/nagios/etc/objects/localhost.cfg
按下面的內容修改(不是添加)該文件
define?host{ ????????use?????????????????????linux-server,host-pnp?????????????????????????? ????????host_name???????????????localhost ????????alias???????????????????localhost ????????address?????????????????127.0.0.1 ????????} define?service{ ????????use????????????????????????????local-service,service-pnp ????????host_name???????????????????????localhost ????????service_description?????????????PING ????????check_command???????????check_ping!100.0,20%!500.0,60% ????????} define?service{ ????????use????????????????????????????local-service,service-pnp ????????host_name???????????????????????localhost ????????service_description?????????????Root?Partition ????????check_command???????????check_local_disk!20%!10%!/ ????????}
重啟nagios和apache:
[root@localhost?~]#?systemctl?restart?nagios.service [root@localhost?~]#?systemctl?restart?httpd.service
訪問nagios界面即可看到圖表小圖標:
要全綠色,不綠色就按照提示解決。
[root@localhost?check_commands]#?mv?/usr/local/pnp4nagios/share/install.php?/tmp/
全綠色后刷新,正常如下:
監控本機
==============================================================================
[root@localhost?~]#?cd?/usr/local/nagios/etc/objects [root@localhost?~]#?vim?localhost.cfg define?host{ ???????use?????????????????????linux-server?????????????????????????????????????? ???????host_name???????????????localhost ???????alias???????????????????localhost ???????address?????????????????127.0.0.1 ???????} #?Define?an?optional?hostgroup?for?Linux?machines define?hostgroup{ ???????hostgroup_name??linux-servers?;?The?name?of?the?hostgroup ???????alias???????????Linux?Servers?;?Long?name?of?the?group ???????members?????????localhost?????;?Comma?separated?list?of?hosts?that?belong?to?this?group ???????} #?Define?a?service?to?"ftp"?the?local?machine define?service{ ???????use?????????????????????????????local-service?????????;?Name?of?service?template?to?use ???????host_name???????????????????????localhost ???????service_description?????????????FTP ???????check_command???????????????????check_ftp ???????} #?Define?a?service?to?"nfs"?the?local?machine define?service{ ???????use?????????????????????????????local-service?????????;?Name?of?service?template?to?use ???????host_name???????????????????????localhost ???????service_description?????????????NFS ???????check_command???????????????????check_tcp!2049 ???????}
監控遠程主機
==============================================================================
[root@localhost?~]#?cd?/usr/local/nagios/etc/objects [root@localhost?~]#?cp?localhost.cfg?192.168.0.164.cfg [root@localhost?~]#?vim?192.168.0.164.cfg define?host{ ???????use?????????????????????linux-server???? ???????host_name???????????????testserver ???????alias???????????????????host196 ???????address?????????????????192.168.0.164 ???????} #define?hostgroup{ #????????hostgroup_name??testserver?;?The?name?of?the?hostgroup #????????alias???????????host;?Long?name?of?the?group #????????members?????????localhost???;?Comma?separated?list?of?hosts?that?belong?to?this?group #} define?service{ ???????use?????????????????????????????local-service ???????host_name???????????????????????testserver ???????service_description?????????????PING ???????check_command???????????????????check_ping!100.0,20%!500.0,60% ???????} define?service{ ???????use?????????????????????????????local-service?? host_name???????????????????????testserver ???????service_description?????????????HTTP ???????check_command???????????????????check_http #???????notifications_enabled???????????0 ???????} define?service{ ???????use?????????????????????????????local-service ???????host_name???????????????????????testserver ???????service_description?????????????NFS ???????check_command???????????????????check_tcp!2049 #???????notifications_enabled???????????0 ???????}
=============================================================================
更改主配置文件
[root@localhost?~]#?vim?/usr/local/nagios/etc/nagios.cfg 添加一行 cfg_file=/usr/local/nagios/etc/objects/192.168.122.100.cfg 檢測新的配置文件是否正確 [root@localhost?~]#?/usr/local/nagios/bin/nagios?-v?/usr/local/nagios/etc/nagios.cfg Total?Warnings:?0 Total?Errors:???0 Things?look?okay?-?No?serious?problems?were?detected?during?the?pre-flight?check
重啟nagios,web登錄確認是否新增了主機。
監控本機和遠程主機參考:
https://blog.51cto.com/1585654/1386857
nagios默認不用mysql存儲,可以使用NDOUtils插件實現mysql存儲:
https://support.nagios.com/kb/article/ndoutils-installing-ndoutils-406.html
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。