nagios 部署安裝


安裝前的準備工做

(1)解決安裝Nagios的依賴關係:
Nagios基本組件的運行依賴於httpd、gcc和gd。能夠經過如下命令來檢查nagios所依賴的rpm包是否已經徹底安裝:
# yum -y install httpd gcc glibc glibc-common *gd* php php-mysql mysql mysql-server mysql-devel


(2)所須要安裝組件:
服務端所用的安裝包爲 nagios nagios-plugins ndoutils(非必須)
linux客戶端 nrpe
windows客戶端 NSClient++

(3)
進行selinux設置,或者關閉selinux
開始搭建:
(1)添加nagios運行所須要的用戶和組:
# groupadd nagcmd
# useradd -m nagios
# usermod -a -G nagcmd nagios

把apache加入到nagcmd組,以便於在經過web Interface操做nagios時可以具備足夠的權限:
# usermod -a -G nagcmd apache


二、編譯安裝nagios:
# tar zxf nagios-3.3.1.tar.gz
# cd nagios-3.3.1
# ./configure --with-command-group=nagcmd --enable-event-broker

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

爲email指定您想用來接收nagios警告信息的郵件地址,默認是本機的nagios用戶:
# vi /usr/local/nagios/etc/objects/contacts.cfg
email        nagios@localhost       #這個是默認設置

執行以下命令,實如今httpd的配置文件目錄(conf.d)中建立Nagios的Web程序配置文件:
# make install-webconf

建立一個登陸nagios web程序的用戶,這個用戶賬號在之後經過web登陸nagios認證時所用:
# htpasswd -c /var/www/nagios/etc/htpasswd.users nagiosadmin

以上過程配置結束之後須要從新啓動httpd:
# service httpd restart


三、編譯、安裝nagios-plugins
Nagios的全部監控工做都是經過插件完成的,所以,在啓動nagios以前還須要爲其安裝官方提供的插件。
# 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

四、配置並啓動Nagios
(1)把nagios添加爲系統服務並將之加入到自動啓動服務隊列:
# chkconfig --add nagios
# chkconfig nagios on

(2)檢查其主配置文件的語法是否正確:
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

(3)若是上面的語法檢查沒有問題,接下來就能夠正式啓動nagios服務了:
# service nagios start

(4)配置selinux
若是您的系統開啓了selinux服務,則默認爲拒絕nagios web cgi程序的運行。您能夠經過下面的命令來檢查您的系統是否開啓了selinux:
#getenforce

若是上面命令的結果顯示開啓了selinux服務,您能夠經過下面的命令暫時性的將其關閉:
#setenforce 0

若是您想在之後徹底關閉selinux,能夠經過編輯/etc/sysconfig/selinux文件,將其中的selinux後面的值「force」修改成「disable」便可。

固然,您也能夠經過如下方式將nagios的CGI程序運行於SELinux/targeted模式而不用關閉selinux:
# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin
# chcon -R -t httpd_sys_content_t /usr/local/nagios/share

(5)經過web界面查看nagios:
http://your_nagios_IP/nagios
登陸時須要指定前面設定的web認證賬號和密碼。
php


#################################################################
linux端

被監控端
先添加nagios用戶
useradd nagios
爲了安裝nrpe,先安裝nagios-plugins-1.4.15.tar.gz 插件
# 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  (會自動加載SSL)
#若是後面make報錯,加以下參數
./configure --enable-ssl --with-ssl-lib=/usr/lib/(固然前提要有openssl)
若是仍然沒法正常進行,需安裝openssl-devel包
make all
make install-plugin
make install-daemon
make install-daemon-config

4.配置nrpe信息
vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1  //容許監控的IP
server_address=192.168.0.186 //修改成外部網卡監聽的IP
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d



服務端
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=/lib/(固然前提要有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
          host_name     mylinux
          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
}


mysql

#################################################################linux


define service{
        use                    generic-service
        host_name           mylinux
        service_description  httpd
        check_command     check_http! -H 192.168.0.27
}
ios


#################################################################web

相關文章
相關標籤/搜索