監控三劍客之Nagios監控服務器

博文目錄php

1、Nagioshtml

一、Nagios介紹mysql

二、Nagios主要功能ios

三、Nagios的做用web

四、Nagios常見的監控狀態sql

五、Nagios的原理shell

2、安裝LAMP環境vim

3、安裝Nagioscentos

一、安裝Nagios組件ruby

二、配置Apache支持Nagios

三、配置SendMail郵件

4、Nagios監控Linux客戶端

一、安裝依賴程序

二、安裝Nagios-plugins插件

三、安裝NRPE插件

1、Nagios

一、Nagios介紹

Nagios是一款開源的免費網絡監視工具,能有效監控Windows、Linux和Unix的主機狀態,交換機路由器等網絡設備,打印機等。在系統或服務狀態異常時發出郵件或短信報警第一時間通知網站運維人員,在狀態恢復後發出正常的郵件或短信通知。

二、Nagios主要功能

網絡服務監控(SMTP、POP三、HTTP、NNTP、ICMP、SNMP、FTP、SSH);

主機資源監控(CPU load、disk usage、system logs),也包括Windows主機(使用NSClient++ plugin);

能夠指定本身編寫的Plugin經過網絡收集數據來監控任何狀況(溫度、警告……);

能夠經過配置Nagios遠程執行插件遠程執行腳本;

遠程監控支持SSH或SSL加通道方式進行監控;

簡單的plugin設計容許用戶很容易的開發本身須要的檢查服務,支持不少開發語言(shell scripts、C++、Perl、ruby、Python、PHP、C#等);

包含不少圖形化數據Plugins(Nagiosgraph、Nagiosgrapher、PNP4Nagios等);

可並行服務檢查;

可以定義網絡主機的層次, 容許逐級檢查, 就是從父主機開始向下檢查;

當服務或主機出現問題時發出通告,可經過email, pager, sms 或任意用戶自定義的plugin>
進行通知;

可以自定義事件處理機制從新激活出問題的服務或主機;

自動日誌循環;

支持冗餘監控;

包括Web界面能夠查看當前網絡狀態,通知,問題歷史,日誌文件等。

三、Nagios的做用

監控計算機硬件;監控網絡;支持郵件或者短信發送警報。

四、Nagios常見的監控狀態

OK狀態:運行正常狀態顯示顏色爲綠色,監控級別0;

WARNING:警告狀態,監控狀態顏色爲黃色,監控級別1;

CRITICL:出現故障或者嚴重問題,監控狀態顏色爲紅色,監控級別2;

UNKNOWN:未知錯誤,監控狀態顏色爲深黃色,監控級別3;

五、Nagios的原理

1)Nagiosz依賴的組件

LAMP環境;
nrpe組件遠程管理使用;

2)Nagios原理

Nagios執行check_nrpe插件通知或者檢測計算機的服務或者進程;
將採集的進程狀態保存到消息隊列中;
經過Nagios圖形化管理界面展現給用戶;

2、安裝LAMP環境

此環境用到的軟件包及鏡像請訪問:https://pan.baidu.com/s/1Q0WoV7bBUYUB8F_JMtDaOw
提取碼:b0ah

[root@centos01 ~]# yum -y install httpd php mariadb mariadb-server php-mysql openssl-devel  <!--安裝LAMP依賴程序-->
[root@centos01 ~]# vim /var/www/html/index.php   <!--建立php測試頁-->
<?php
phpinfo();
?>
[root@centos01 ~]# systemctl start httpd    <!--啓動Apache-->
[root@centos01 ~]# systemctl enable httpd  <!--開機自動啓動-->
[root@centos01 ~]# systemctl start mariadb    <!--啓動Mariadb-->
[root@centos01 ~]# systemctl enable mariadb    <!--開機自動啓動-->
[root@centos01 ~]# useradd -M -s /sbin/nologin nagios   <!--建立管理Nagios用戶-->
<!--(切換Linux光盤)-->
[root@centos01 ~]# tar zxvf /mnt/nagios-4.0.1.tar.gz -C /usr/src/   <!--解壓縮Nagios壓縮包-->
[root@centos01 ~]# cd /usr/src/nagios-4.0.1/   <!--進入Nagios目錄-->
[root@centos01 nagios-4.0.1]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios  <!-配置Nagios--->
[root@centos01 nagios-4.0.1]# make all && make install && make install-init   
           <!--編譯安裝Nagios-->
[root@centos01 nagios-4.0.1]# make install-commandmode && make install-config  
             <!--編譯安裝Nagios-->
[root@centos01 ~]# chown -R nagios:nagios /usr/local/nagios   <!--設置目錄的全部者-->
[root@centos01 ~]# chkconfig --add nagios    <!--添加系統服務-->
[root@centos01 ~]# chkconfig --level 35 nagios on   <!--設置開機自動啓動-->

客戶端訪問php頁面
監控三劍客之Nagios監控服務器

3、安裝Nagios

一、安裝Nagios組件

[root@centos01 ~]# tar zxvf /mnt/nagios-plugins-1.5.tar.gz -C /usr/src/  
          <!--解壓縮nagios-plugins組件壓縮包-->
[root@centos01 ~]# cd /usr/src/nagios-plugins-1.5/   <!--進入nagios-plugins組件目錄-->
[root@centos01 nagios-plugins-1.5]# ./configure --prefix=/usr/local/nagios   
                <!--配置nagios-plugins組件-->
[root@centos01 nagios-plugins-1.5]# make && make install<!--編譯安裝nagios-plugins組件-->
[root@centos01 ~]# tar zxvf /mnt/nrpe-2.15.tar.gz -C /usr/src/   <!--解壓縮nrpe壓縮包-->
[root@centos01 ~]# cd /usr/src/nrpe-2.15/     <!--進入nrpe目錄-->
[root@centos01 nrpe-2.15]# ./configure && make all && make install-plugin  
         <!--配置編譯安裝nrpe組件-->

二、配置Apache支持Nagios

[root@centos01 ~]# vim /etc/httpd/conf/httpd.conf        <!--編輯Apache主配置文件-->
354 ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
355 
356 <Directory "/usr/local/nagios/sbin">
357     Options ExecCGI
358     AllowOverride None
359     Order allow,deny
360     Allow from all
361     AuthName "Nagios Access"
362     AuthType Basic
363     AuthUserFile "/usr/local/nagios/etc/htpasswd.users"
364     Require valid-user
365 </Directory>
366 
367 Alias /nagios "/usr/local/nagios/share"
368 
369 <Directory "/usr/local/nagios/share">
370     Options None
371     AllowOverride None
372     Order allow,deny
373     Allow from all
374     AuthName "Nagios Access"
375     AuthType Basic
376     AuthUserFile "/usr/local/nagios/etc/htpasswd.users"
377     Require valid-user
378 </Directory>
[root@centos01 ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin  
    <!--配置身份驗證,帳戶爲nagiosadmin,密碼爲pwd@123-->
[root@centos01 ~]# systemctl restart httpd    <!--從新啓動Apache服務-->

三、配置SendMail郵件

[root@centos01 ~]# tar zxvf /mnt/sendEmail-v1.55.tar.gz   <!--解壓SendMail包-->
[root@centos01 ~]# mv sendEmail-v1.55/sendEmail /usr/local/bin/   
      <!--剪切SendMail到/usr/local/bin/目錄-->
[root@centos01 ~]# vim /usr/local/nagios/etc/nagios.cfg   <!--添加存儲監控主機配置文件-->
  36 cfg_dir=/usr/local/nagios/etc/conf
[root@centos01 ~]# mkdir /usr/local/nagios/etc/conf/  <!--建立存儲監控主機目錄-->
[root@centos01 ~]# vim /usr/local/nagios/etc/objects/commands.cfg   <!--定義Nagios命令-->
239 define command{
240         command_name     notify-host-by-sendEmail
241         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 -o fqdn=FQND     -f 2807489749@qq.com -t $CONTACTEMAIL$ -s smtp.qq.com -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -xu 8214    09986 -xp hehe
242 
243 }
244 define command{
245         command_name    notify-service-by-sendEmail
246         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$SERVICEOU    TPUT$\n" | /usr/local/bin/sendEmail -o fqdn=FQDN -f 821409986@qq.com -t $CONTACTEMAIL$ -s smtp.qq.com -u "** $NOTIFICATIONTYPE$ Se    rvice Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu 2807489749 -xp hehe
247 }
248 define command{
249         command_name     check_nrpe
250         command_line    $USER1$/check_nrpe  -H  $HOSTADDRESS$  -c  $ARG1$
251 }
[root@centos01 ~]# vim /usr/local/nagios/etc/objects/contacts.cfg  <!--定義聯繫人-->
55 define contact{
 56         contact_name                            821409986
 57         alias                                   821409986
 58         service_notification_period             24x7
 59         host_notification_period                24x7
 60         service_notification_options            w,u,c,r
 61         host_notification_options               d,u,r
 62         service_notification_commands           notify-service-by-sendEmail
 63         host_notification_commands              notify-host-by-sendEmail
 64         email   821409986@qq.com
 65 }
 66 define contactgroup{
 67         contactgroup_name       821409986
 68         alias                   Nagios admin
 69         members                 821409986
 70 }
[root@centos01 ~]# vim /usr/local/nagios/etc/conf/hostgroups.cfg   <!--定義監控主機-->
define hostgroup{
        hostgroup_name                  web-server
        alias                           web-server
        members                         192.168.100.20    <!--被監控IP地址-->
}

[root@centos01 ~]# vim /usr/local/nagios/etc/conf/192.168.100.20.cfg   <!-編輯配置文件-->
define host{
        host_name                       192.168.100.20
        alias                           web-server
        address                         192.168.100.20
        check_command                   check-host-alive
        max_check_attempts              5
        check_period                            24x7
        notification_period                     24x7
        notification_options            d,u,r
        contact_groups                  821409986
}

define service{
        host_name                       192.168.100.20
        service_description             check-host-alive
        check_command                   check-host-alive
        max_check_attempts              3
        normal_check_interval           2
        retry_check_interval            2
        check_period                            24x7
#       notification                    web-server_interval 10
        notification_period                     24x7
        notification_options            w,u,c,r
        contact_groups                  821409986
}

define service{
        host_name                       192.168.100.20
        service_description             check-procs
        check_command                   check_nrpe!check_total_procs
        max_check_attempts              3
        normal_check_interval           2
        retry_check_interval            2
        check_period                            24x7
        notification_interval           10
        notification_period                     24x7
        notification_options            w,u,c,r
        contact_groups                  821409986
}

define service{
        host_name                       192.168.100.20
        service_description             check-load
        check_command                   check_nrpe!check_load
        max_check_attempts              3
        normal_check_interval           2
        retry_check_interval            2
        check_period                            24x7
        notification_interval           10
        notification_period                     24x7
        notification_options            w,u,c,r
        contact_groups                  821409986
}
[root@centos01 ~]# systemctl restart httpd   <!--從新啓動Apache服務-->
[root@centos01 ~]# systemctl restart nagios    <!--從新啓動nagios-->

客戶端訪問nagios的WEB界面
監控三劍客之Nagios監控服務器

4、Nagios監控Linux客戶端

一、安裝依賴程序

[root@centos02 ~]# yum -y install openssl-devel openssl    <!--安裝依賴程序-->
[root@centos02 ~]# useradd -M -s /sbin/nologin nagios    <!--建立管理nagios用戶-->

二、安裝Nagios-plugins插件

[root@centos02 ~]# scp root@192.168.100.10:/mnt/nagios-plugins-1.5.tar.gz /root/  
          <!--遠程複製plugins插件壓縮包-->
[root@centos02 ~]# tar zxvf nagios-plugins-1.5.tar.gz -C /usr/src/  <!--解壓縮plugins插件--> 
[root@centos02 ~]# cd /usr/src/nagios-plugins-1.5/    <!--進入plugins插件目錄-->
[root@centos02 nagios-plugins-1.5]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios   <!--編譯plugins插件--> 
[root@centos02 nagios-plugins-1.5]# make && make install   <!--編譯安裝nagios-plugins插件-->

三、安裝NRPE插件

[root@centos02 ~]# scp root@192.168.100.10:/mnt/nrpe-2.15.tar.gz /root   <!--遠程複製壓縮包-->
[root@centos02 ~]# tar zxvf nrpe-2.15.tar.gz -C /usr/src/   <!--解壓縮nrpe壓縮包-->
[root@centos02 ~]# cd /usr/src/nrpe-2.15/   <!--進入nrpe目錄-->
[root@centos02 nrpe-2.15]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios   <!--配置nrpe插件-->
[root@centos02 nrpe-2.15]# make all && make install-plugin && make install-daemon && make install-daemon-config   <!--編譯安裝nrpe插件-->
[root@centos02 ~]# vim /usr/local/nagios/etc/nrpe.cfg   <!--修改nrpe配置文件-->
81 allowed_hosts=127.0.0.1,192.168.100.10    <!--Nagios服務器IP地址-->

[root@centos02 ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

客戶端訪問nagios的WEB界面
監控三劍客之Nagios監控服務器

監控三劍客之Nagios監控服務器

監控三劍客之Nagios監控服務器

———————— 本文至此結束,感謝閱讀 ————————

相關文章
相關標籤/搜索