Nagios

一 對比php

Cacti:
  收集數據、圖形展現
  偏重網絡流量
  SNMP、OID、SNMP Agent

Nagios:
  偏重主機、服務的狀態
  Agent
  腳本

 

二 原理mysql

原理-1linux

監控對象
  主機、主機組
  服務/資源,服務組
  聯繫人,聯繫人組
  時段
  命令

 

原理-2
      ios

 

 原理-3web

     

 

 原理-4sql

    

 

三 操做apache

1. 安裝前的準備工做vim

1)解決安裝Nagios的依賴關係
 yum -y install httpd gcc glibc glibc-common *gd* php php-mysql mysql mysql-server mysql-devel  #gd先去除
 
 2)所須要安裝組件:
 服務端所用的安裝包爲 nagios nagios-plugins ndoutils(非必須)
linux客戶端 nrpe
windows客戶端 NSClient++
 
 3)
 進行selinux設置,或者關閉selinux
 
 
 4)開始搭建
 添加nagios運行所須要的用戶和組:

    # groupadd nagcmd
    # useradd -m nagios
    # usermod -a -G nagcmd nagios

    # usermod -a -G nagcmd apache

 

2. 編譯安裝nagioswindows

# tar zxf nagios-3.1.2.tar.gz 
# cd nagios-3.1.2
# ./configure --with-command-group=nagcmd --enable-event-broker 

# make all
# make install
# make install-init
# make install-config
# make install-commandmode

# vi /usr/local/nagios/etc/objects/contacts.cfg 
    email        nagios@localhost       #這個是默認設置

# make install-webconf

# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

# service httpd restart

 

3. 編譯、安裝nagios-plugins瀏覽器

yum -y install openssl openssl-devel
# tar -zxf nagios-plugins-1.4.15.tar.gz 
# cd nagios-plugins-1.4.15
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-mysql --enable-perl-modules

# make && make install

 

4. 配置並啓動Nagios

# chkconfig --add nagios
# chkconfig nagios on

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg    #檢測是否有錯誤
    Total Warnings: 0
    Total Errors:   0

# service nagios start

瀏覽器測試: 登陸時須要指定前面設定的web認證賬號和密碼
http://192.168.10.10/nagios/
user:nagiosadmin
pwd: 123

 

windos端

1.被監控端安裝NSClient++-0.3.8-Win32.msi    #netstat -an --> tcp 5666
2.安裝完成後修改配置文件NSC.ini把須要的庫都打開


3.在監控服務器上修改nagios配置文件nagios.cfg
去掉註釋cfg_file=/usr/local/nagios/etc/objects/windows.cfg
定義windows.cfg
define host{
        use             windows-server  ; Inherit default values from a template
        host_name       winserver       ; The name we're giving to this host
        alias           My Windows Server       ; A longer name associated with the host
        address         192.168.0.191   ; 你主機的IP
        }

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

 

 

linux端

被監控端
先添加nagios用戶
useradd nagios
爲了安裝nrpe,先安裝nagios-plugins-1.4.15.tar.gz 插件
yum -y install openssl openssl-devel  gcc*
# tar zxf nagios-plugins-1.4.15.tar.gz 
# cd nagios-plugins-1.4.15
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make all
# make install

tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12.tar.gz
./configure --enable-ssl --with-ssl-lib=/usr/lib64/
make all
make install-plugin
make install-daemon
make install-daemon-config

4.配置nrpe信息
vim /usr/local/nagios/etc/nrpe.cfg
    allowed_hosts=192.168.216.251,127.0.0.1  //容許監控的IP
    
[root@localhost nrpe-2.8.1]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

[root@localhost nrpe-2.8.1]# netstat -an | grep :5666
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN     

 

服務端

3.安裝NRPE
cd nagios-nrpe_2.8.1
./configure   #默認自動添加了openssl


#由於傳送過程要加密,若是後面make報錯,加以下參數
rpm -qa| grep ssl
openssl-devel-0.9.7a-43.17.el4_6.1
rpm -ql openssl-devel-0.9.7a-43.17.el4_6.1 | more


./configure --enable-ssl --with-ssl-lib=/usr/lib64/(固然前提要有openssl)
make all
make install-plugin


---安裝check_nrpe腳本

4.commands.cfg定義外部構件nrpe
vi /usr/local/nagios/etc/objects/commands.cfg
#添加
#check nrpe
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }


定義 mylinux.cfg
define host{
           use             linux-server   #到 vim templates.cfg 裏,肯定
          host_name     mylinux/IP
          alias            mylinux
          address        192.168.0.27(客戶端IP既被監控的IP)
               }
define service{
        use                      generic-service
        host_name             mylinux
        service_description     check-load
       check_command         check_nrpe!check_load
               }

define service{
        use                      generic-service
        host_name             mylinux
       service_description     check-users
       check_command        check_nrpe!check_users
               }
define service{
        use                    generic-service
        host_name           mylinux
        service_description  otal_procs
        check_command     check_nrpe!check_total_procs
} 


[root@localhost etc]# vim nagios.cfg      

  39 cfg_file=/usr/local/nagios/etc/objects/windows.cfg  #網頁纔會顯示
  40 cfg_file=/usr/local/nagios/etc/objects/linux.cfg
相關文章
相關標籤/搜索