Nagios一般由一個主程序(Nagios)、一個插件程序(Nagios-plugins)和四個可選的ADDON(NRPE、NSCA、NSClient++和NDOUtils)組成。Ngios的監控工做都是經過插件實現的,所以,Nagios和Nagios-plugins是服務器端工做所必須的組件,而四個ADDON中php
一、NRPE:用來監控遠程linux/unix主機上執行腳本插件以實現對這些主機資源的監控mysql
二、NSCA:用來讓被監控的遠程linux/unix主機主動將監控信息發送給Nagios服務器(這在冗餘監控模式中特別要用到)linux
三、NSClient++:用來監控windows主機是安裝在windows主機上的組件ios
四、NDOUtils:是用來將Nagios的配置信息和個event產生的數據存入數據庫,以實現這些數據的快速檢索和處理c++
這四個ADDON(附件)中,NRPE和NSClient++工做與客戶端,NDOUtils工做於服務器端,而NSCA則於鏊同事安裝在服務器端和客戶端web
1、安裝nagios須要的rpm包:sql
# yum -y install httpd php mysql-devel php-mysql 數據庫
2、添加nagios運行所須要的用戶和組apache
# groupadd nagcmdvim
# useradd -G nagcmd nagios
# passwd nagios
把apache加入到nagcmd組,以便於在經過web interface操做nagios時可以具備足夠的權限
# usermod -a -G nagcmd apache
3、編譯nagios:
# tar -zxvf nagios-3.5.0.tar.gz
# ./configure --sysconfdir=/etc/nagios --with-command-group=nagcmd --enable-event-broker
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
在httpd的配置文件目錄(conf.d)中建立nagios的Web程序配置文件
# make install-webconf
--sysconfdir=/etc/nagios 配置文件的位置
--enable-event-broker 可使用你NDOUtils鏈接mysql數據庫的
4、爲email指定您想用來接收nagios警告信息的郵件地址,默認是本機的nagios用戶
# vim /etc/nagios/objects/contacts.cfg
5、建立一個登陸nagios web程序的用戶,這個帳號在之後經過web登錄nagios認證是所用:
# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
6、selinux會組織cgi腳本的運行,要麼關閉selinux
# setenforce 0
或者執行下面的兩個命令
# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin
# chcon -R -t httpd_sys_content_t /usr/local/nagios/share
啓動apache服務:
# /etc/init.d/httpd start
7、若是源碼安裝apache是遇到以下問題
./configure --prefix=/usr/local/apache 報錯
error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.
解決方法
cp -fr apr-1.4.8 ./httpd-2.4.6/srclib/apr
cp -fr apr-util-1.5.2 ./httpd-2.4.6/srclib/apr-util
./configure --prefix=/usr/local/apache 繼續報錯
解決辦法安裝pcre
安裝pcre報錯error: You need a C++ compiler for C++ support.
安裝c++編譯器
yum install -y gcc gcc-c++
8、編譯、安裝nagios-plugins
nagios的全部監控工做都是經過插件完成的,所以,在啓動nagios以前還須要爲其安裝官方提供的插件
# tar zxvf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install
9、將nagios添加到服務列表中並設置爲開機自啓動
# chkconfig --add nagios
# chkconfig nagios on 2345
10、啓動nagios
# /etc/init.d/nagios start
到此爲止nagios的頁面就能夠訪問了能夠登陸
1、安裝nagios-plugins
# tar -zxvf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# useradd -s /sbin/nologin -r nagios
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make all
# make install
2、安裝nrpe
# tar -zxvf nrpe-2.15.tar.gz
# cd nrpe-2.15
# ./configure --with-nrep-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
3、啓動nrpe進程
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
4、編寫nrped啓動腳本,設置開機自啓動
# vim /etc/init.d/nrped 加入以下內容
#!/bin/sh
nrpe_num=`ps aux | grep /bin/nrpe | grep -v grep | wc -l`
case $1 in
start)
if [ $nrpe_num -eq 1 ]
then
echo "Error:nrpe is running."
else
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo "nrpe started successfully."
fi
;;
stop)
if [ $nrpe_num -eq 1 ]
then
nrpe_pid=`ps aux | grep /bin/nrpe | grep -v grep | awk '{print $2}'`
kill -9 $nrpe_pid
echo "nrpe stoped successfully."
else
echo "Error:nrpe is stoping."
fi
;;
restart)
if [ $nrpe_num -eq 1 ]
then
nrpe_pid=`ps aux | grep /bin/nrpe | grep -v grep | awk '{print $2}'`
kill -9 $nrpe_pid
echo "nrpe stoped successfully."
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo "nrpe started successfully."
else
echo "Error:nrpe is stoping"
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo "nrpe started successfully."
fi
esac
賦予nrped執行權限:
# chmod 755 nrped
# chkconfig --add nrped
# chkconfig --list nrped
若是2345是關閉
# chkconfig --level 2345 nrped on
5、服務端也要安裝nrpe
# ./configure --sysconfdir=/etc/nagios --with-nrep-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
本人習慣:服務端的配置文件所有都在etc目錄下,client端的文件通常放在源碼文件中,因此在服務端編譯的時候都指定了配置文件的路徑,而在客戶端並未指定配置文件目錄
其他部分和client端同樣
須要準備的插件:
NSClient++-0.3.8-x64
Allowed hosts:容許誰檢測
NSClient password:fanjinbao;經過什麼密碼來監控
運行NSClient++後檢查是否開啓了12489的端口