搭建nagios監控步驟

來源:互聯網
上載者:User

標籤:nagios監控

1、實驗環境:

主機名稱:            ip              需要的軟體環境

nagios-server     192.168.124.143    Apache、Php、Nagios、nagios-plugins、nrpe

nagios-linux      192.168.124.203    nagios-plugins、nrpe

監控機 nagios-server上需要 安裝nagios軟體,對監控的資料做處理,並且提供 web介面查看和管理。當然也對本機自身的資訊進行監控;

被監控機 nagios-linux需安裝NRPE及nagios plugins,根據監控機的請求執行監 控,然後將結果回傳給監控機;

一、Nagios監控機(192.168.124.143)上的環境準備

      1、 安裝編譯環境

      使用yum安裝

      [[email protected] ~]# yum install -y gcc glibc glibc-common gd xinetd openssl-devel mysql-devel

      2、 建立nagios使用者和使用者組

     [[email protected] ~]#useradd -s /sbin/nologin nagios

     [[email protected] ~]#mkdir /usr/local/nagios

     [[email protected] ~]#chown -R nagios:nagios /usr/local/nagios 

      3、 yum安裝httpd和php,並配置httpd支援php     

           只要能實現瀏覽器能正常訪問 http://本機IP/index.php 既可

      4、 編譯安裝nagios    

      上傳nagios源碼包至/root目錄下 

      [[email protected] ~]#tar zxvf nagios-4.0.3.tar.gz   

      [[email protected] ~]#cd nagios-4.0.3   

      [[email protected] ~]#./configure --prefix=/usr/local/nagios --with-nagiosuser=nagios --with-nagios-group=nagios  

      [[email protected] ~]#make all   

      [[email protected] ~]#make install   

      [[email protected] ~]#make install-init

      [[email protected] ~]#make install-commandmode

      [[email protected] ~]#make install-config

      [[email protected] ~]#make install-webconf

      [[email protected] ~]#chkconfig --add nagios                           #       將nagios加入系統 服務

      [[email protected] ~]#chkconfig nagios on

      5、 驗證nagios是否被正確安裝

         切換目錄到安裝路徑(這裡是/usr/local/nagios),看是否存在etc、bin、 libexec、sbin、share、var  這些目錄,如果存在則可以表明程式被正確的安裝到 系統了。

         Nagios 各個目錄用途說明如下:     

        

     目錄名             用途

    bin Nagios       可執行程式所在目錄 

    etc Nagios       設定檔所在目錄 

    sbin           Nagios CGI檔案所在目錄,也就是執行外部命令所需檔案所在的目錄       share          Nagios網頁檔案所在的目錄 

    libexec         Nagios 外部外掛程式所在目錄 

    var Nagios     記錄檔、lock 等檔案所在的目錄 

    var/archives    Nagios 日誌自動歸檔目錄 

    var/rw        用來存放外部命令檔案的目錄

      6、 安裝nagios外掛程式

         上傳nagios-plugins-1.5.tar.gz至/root目錄下

     [[email protected] ~]#tar zxvf nagios-plugins-1.5.tar.gz

     [[email protected] ~]#cd nagios-plugins-1.5

      [[email protected] ~]#./configure --prefix=/usr/local/nagios --with-mysql --with-nagios-user=nagios --with-nagiosgroup=nagios

     [[email protected] ~]#make && make install

     備忘:

      --with-mysql 使nagios外掛程式支援監控mysql(系統要先yum安裝好 mysql-devel軟體包),在libexec目錄下會有 check_mysql和check_mysql_query命令

      7、 安裝check_nrpe外掛程式

        上傳nrpe-2.12.tar.gz至/root目錄下  

      [[email protected] ~]#tar zxvf nrpe-2.12.tar.gz   

     [[email protected] ~]#cd nrpe-2.12

     [[email protected] ~]#./configure --with-nrpe-user=nagios      --with-nrpe-group=nagios      --with-nagiosuser=nagios      --with-nagios-group=nagios      --enable-command-args      --enable-ssl      

     [[email protected] ~]#make all

     [[email protected] ~]#make  install-plugin

      監控機上只運行到這一步就行,因為只需要nrpe中的check_nrpe外掛程式             

      8、 修改apache的設定檔/etc/httpd/conf/httpd.conf

       [[email protected] ~]#vim /etc/httpd/conf/httpd.conf

         User apache修改為User nagios

        Group apache修改為Group nagios

         DirectoryIndex index.html修改為DirectoryIndex index.php

         儲存

      9、 為了安全起見,一般情況下要讓nagios 的web 監控頁面必須經過授權才能訪問              編譯安裝nagios 4.0.3版本完成後,已自動設定httpd並設定了預設的htpasswd驗證檔案                  /usr/local/nagios/etc/ htpasswd.users     

      [[email protected] ~]#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin                       #指定使用者 nagiosadmin可以訪問  

      10、 啟動httpd服務

      [[email protected] ~]#service httpd restart  

      [[email protected] ~]#service nagios start   

      11、 瀏覽器訪問nagios網站

      http://192.168.124.143/nagios  

    二、被監控機(192.168.124.203)安裝nrpe及nagios-plugins  

      1、 安裝編譯環境

        使用yum安裝 

      [[email protected] ~]# yum install -y gcc glibc glibc-common gd xinetd openssl-devel mysql-devel

      2、 編譯安裝nagios外掛程式

    上傳nagios-plugins-1.5.tar.gz至/root目錄下  

      [[email protected] ~]#tar -zxvf nagios-plugins-1.5.tar.gz 

      [[email protected] ~]#cd nagios-plugins-1.5

      [[email protected] ~]#./configure  --with-mysql --with-nagios-user=nagios --with-nagios-group=nagios    

      [[email protected] ~]#make && make install       

     這一步完成後會在/usr/local/nagios/下產生兩個目錄libexec和share,修改目錄許可權            [[email protected] ~]#useradd -s /sbin/nologin nagios

       [[email protected] ~]#chown  -R nagios:nagios /usr/local/nagios       

     3、 編譯安裝nrpe 

    上傳nrpe-2.12.tar.gz至/root目錄下 

      [[email protected] ~]#tar -zxvf nrpe-2.12.tar.gz   

      [[email protected] ~]#cd nrpe-2.12   

      [[email protected] ~]#./configure --with-nrpe-user=nagios      --with-nrpe-group=nagios      --with-nagiosuser=nagios      --with-nagios-group=nagios      --enable-command-args      --enable-ssl    

       [[email protected] ~]#make all    

       [[email protected] ~]#make install-plugin 

       [[email protected] ~]#make install-daemon  

       [[email protected] ~]#make install-daemon-config 

     #現在再查看/usr/local/nagios 目錄就會發現有4個子目錄

      [[email protected] ~]#make install-xinetd   

      [[email protected] ~]#vim /etc/xinetd.d/nrpe  

        修改在末尾項 only_from    = 192.168.124.0/24

        這裡設定允許監控機所在的網段訪問   

       [[email protected] ~]#vim /etc/services  

     #編輯/etc/services 檔案,末尾增加NRPE服務內容   

         在最後添加   nrpe    5666/tcp   #nrpe

       [[email protected] ~]#service xinetd restart 

      [[email protected] ~]#netstat -ntulp|grep 5666  

    #查看nrpe是否已啟動並監聽5666連接埠    

      4、 測試nrpe是否正常工作 

    在監控機(192.168.124.143)執行check_nrpe這個外掛程式來測試與被監控機(192.168.124.203)的通訊    

      [[email protected] ~]#/usr/local/nagios/libexec/check_nrpe -H 192.168.124.203              如顯示     NRPE V2.12   ,則nrpe通訊正常    

           

    三、監控機(192.168.124.143)上的配置

     1、 在commands.cfg檔案末尾增加check_nrpe的定義

       [[email protected] ~]#vim /usr/local/nagios/etc/objects/commands.cfg  

       #添加如下 代碼

      define command{         

          command_name    check_nrpe           

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

    2、 定義對Nagios-Linux 主機的監控,建立nagios_linux.cfg檔案並加入以下 代碼內容


      [[email protected] ~]#vim /usr/local/nagios/etc/objects/nagios_linux.cfg 

      define host{       

         use             linux-server

         host_name         nagios-linux

         alias           nagios-linux    

         address          192.168.124.67                 #此處設定被監控機的IP地址            }

      define service{          #添加監控CPU負載的服務 

         use            local-service   

         host_name        nagios-linux    

         service_description   CPU Load

       check_command        check_nrpe!check_load

                 }

      define service{            #添加監控總進程數的服務

          use             local-service    

          host_name         nagios-linux  

          service_description  Total Processes 

          check_command      check_nrpe!check_total_procs   

                 }   

      上述代碼分別定義了CPU Load(cpu負載)以及Total Processes(總進程數)的監 控服務,還可以在此檔案中增加其他的監控服務

      3、 在nagios的主設定檔nagios.cfg末尾增加如下代碼內容  

       [[email protected] ~]#vim /usr/local/nagios/etc/nagios.cfg  

      cfg_file=/usr/local/nagios/etc/objects/nagios_linux.cfg   

      #在nagios的主設定檔中增 加被監控機的設定檔 

      4、 重啟各項服務

       [[email protected] ~]#service httpd restart

       [[email protected] ~]#service nagios restart

      5、 驗證nagios是否能監控到本機(localhost)以及被監控機nagios-linux         

         http://ip/nagios    

      6、[[email protected] ~]#service httpd restart

        [[email protected] ~]#service nagios restart

       #重啟驗證新增的監控資訊  

            

ok!到此結束!希望對你有所協助


本文出自 “12178027” 部落格,請務必保留此出處http://12188027.blog.51cto.com/12178027/1863548

搭建nagios監控步驟

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.