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


2、編譯安裝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


3、編譯、安裝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

4、配置並啓動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認證帳號和密碼。


#################################################################
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
}


#################################################################


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


#################################################################





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章