2014年1月3日 星期五

[研究] Nagios 4.0.2 快速安裝程式(tar.gz) (CentOS 6.5 x64)

[研究] Nagios 4.0.2 快速安裝程式(tar.gz) (CentOS 6.5 x64)

2014-01-03

官方網站
http://www.nagios.com/

Nagios + plugins 快速安裝參考
http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html
http://nagios.sourceforge.net/docs/3_0/quickstart.html

NRPE 安裝
http://nagios.sourceforge.net/docs/nrpe/NRPE.pdf
http://support.nagios.com/knowledgebase/officialdocs

 架構
http://nagios.sourceforge.net/docs/nrpe/NRPE.pdf

nagios-4.0.2.tar.gz 是最主要的部分
nagios-plugins-1.5.tar.gz 提供 check_disk、check_load、、、等檢查程式,你也可以自己撰寫 (任何語言甚至 shell script 都可)
nrpe-2.14.tar.gz 提供受監控主機和監看畫面主機間溝通


預設帳號是 nagiosadmin
預設密碼是 password
如果想改密碼, 請找到

htpasswd  -cb  /usr/local/nagios/etc/htpasswd.users   nagiosadmin   password

把 password 換成你要的密碼

安裝參考
http://assets.nagios.com/downloads/nagioscore/docs/Installing_Nagios_Core_From_Source.pdf

快速安裝程式

echo -e "\033[31;42m ********** Install nagios-4.0.2.tar.gz on CentOS 6.5 x64 ********** \033[0m"
echo -e "\033[31m 2014/01/03 ********** \033[0m"
echo -e "Ref : http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html"

# Check SELinux status
if  [ "`grep SELINUX=disabled /etc/selinux/config`" == "" ]; then

# disable SELinux now
/usr/sbin/setenforce 0

# disable SELinux after every reboot
# echo "/usr/sbin/setenforce 0" >> /etc/rc.local  

#or
# disable SELinux always
sed -i -e "s@SELINUX=enforcing@#SELINUX=enforcing@"   /etc/selinux/config
sed -i -e "s@SELINUX=permissive@#SELINUX=permissive@"   /etc/selinux/config
sed -i -e "/SELINUX=/aSELINUX=disabled"   /etc/selinux/config
fi

# Kill nptd on running...
ProcessID="`ps aux | grep ntpd | awk '{print $2}' `"
for i in $ProcessID
do
  echo $i
  kill -9 $i
done
ntpdate tick.stdtime.gov.tw

# Kill yum on running...
ProcessID="`ps aux | grep yum | awk '{print $2}' `"
for i in $ProcessID
do
  echo $i
  kill -9 $i
done

#Prerequisites

yum -y install httpd php gcc glibc glibc-common gd gd-devel xinetd openssl-devel

#1) Create Account Information

#su -l
/usr/sbin/useradd nagios
#passwd nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nagios
/usr/sbin/usermod -G nagcmd apache

#2) Download Nagios and the Plugins

cd ~
if test -f nagios-4.0.2.tar.gz
then
    echo "nagios-4.0.2.tar.gz exist"
else
    wget  http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.2.tar.gz
fi

if test -f nagios-4.0.2.tar.gz
then
  echo "nagios-4.0.2.tar.gz does not exist !"
  exit
fi

if test -f nagios-plugins-1.5.tar.gz
then
    echo "nagios-plugins-1.5.tar.gz exist"
else
    wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
fi

if test -f nagios-plugins-1.5.tar.gz
then
    echo "nagios-plugins-1.5.tar.gz does not exist"
    exit
fi

if test -f nrpe-2.14.tar.gz
then
    echo "nrpe-2.14.tar.gz exist"
else
    wget  http://downloads.sourceforge.net/nagios/nrpe-2.14.tar.gz
fi

if test -f nrpe-2.14.tar.gz
then
    echo "nrpe-2.14.tar.gz does not exist"
    exit
fi

#3) Compile and Install Nagios

tar xzf nagios-4.0.2.tar.gz
cd nagios-4.0.2
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode

# 4) Customize Configuration

# vi /usr/local/nagios/etc/objects/contacts.cfg

#5) Configure the Web Interface

make install-webconf
#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# Set ID : nagiosadmin, Password : password
htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin password
service httpd restart
cd ..

# [root@localhost ~]# ls -al /usr/local/nagios/etc
# total 84
# drwxrwxr-x. 3 nagios nagios  4096 Aug  5 16:18 .
# drwxr-xr-x. 9 nagios nagios  4096 Aug  5 16:13 ..
# # -rw-rw-r--. 1 nagios nagios 11647 Aug  5 16:16 cgi.cfg
# -rw-r--r--. 1 nagios nagios    26 Aug  5 16:05 htpasswd.users
# -rw-rw-r--. 1 nagios nagios 42807 Aug  5 16:05 nagios.cfg
# -rw-r--r--. 1 nagios nagios  7988 Aug  5 16:18 nrpe.cfg
# drwxrwxr-x. 2 nagios nagios  4096 Aug  5 16:05 objects
# -rw-rw----. 1 nagios nagios  1318 Aug  5 16:05 resource.cfg
# [root@localhost ~]#

# [root@localhost ~]# ls -al /usr/local/nagios/etc/objects/
# total 56
# drwxrwxr-x. 2 nagios nagios  4096 Aug  5 16:05 .
# drwxrwxr-x. 3 nagios nagios  4096 Aug  5 16:18 ..
# -rw-rw-r--. 1 nagios nagios  7694 Aug  5 16:05 commands.cfg
# -rw-rw-r--. 1 nagios nagios  2138 Aug  5 16:05 contacts.cfg
# -rw-rw-r--. 1 nagios nagios  5375 Aug  5 16:05 localhost.cfg
# -rw-rw-r--. 1 nagios nagios  3096 Aug  5 16:05 printer.cfg
# -rw-rw-r--. 1 nagios nagios  3265 Aug  5 16:05 switch.cfg
# -rw-rw-r--. 1 nagios nagios 10621 Aug  5 16:05 templates.cfg
# -rw-rw-r--. 1 nagios nagios  3180 Aug  5 16:05 timeperiods.cfg
# -rw-rw-r--. 1 nagios nagios  3991 Aug  5 16:05 windows.cfg
# [root@localhost ~]#




#6) Compile and Install the Nagios Plugins

tar xzf nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
cd ..

# 7) Start Nagios

chkconfig --add nagios
chkconfig nagios on
# check  /usr/local/nagios/etc/nagios.cfg
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# reload nagios.cfg
service nagios start

#8) Modify SELinux Settings
# Fedora ships with SELinux (Security Enhanced Linux) installed and in Enforcing mode by default. This can result in "Internal Server Error" messages when you attempt to access the Nagios CGIs.
# See if SELinux is in Enforcing mode.
# getenforce
# Put SELinux into Permissive mode.
# setenforce 0
# To make this change permanent, you'll have to modify the settings in /etc/selinux/config and reboot.
# Instead of disabling SELinux or setting it to permissive mode, you can use the following command to run the CGIs under SELinux enforcing/targeted mode:
# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
# chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
# For information on running the Nagios CGIs under Enforcing mode with a targeted policy, visit the NagiosCommunity.org wiki at http://www.nagioscommunity.org/wiki.

# 9) Login to the Web Interface

# You should now be able to access the Nagios web interface at the URL below. You'll be prompted for the username (nagiosadmin) and password you specified earlier.

#firefox http://localhost/nagios/ &

#如果你有自己做的設定檔案, 記得改變擁有者, 讓 nagios 可以讀取
#chown -R nagios:nagios /usr/local/nagios/etc
#sed -i -e "s@use_authentication=1@use_authentication=0@"  /usr/local/nagios/etc/cgi.cfg

chkconfig httpd on
service httpd restart

#echo -e "\033[31m Please wait for FireFox, Account: nagiosadmin ********** \033[0m"
#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin password
#firefox http://localhost/nagios &

echo -e "\033[31;42m ********** Install Nagios Plugins 1.5 on CentOS 6.5 x64 ********** \033[0m"

tar zxvf nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure
make
make install
cd ..
#/bin/cp -f /usr/local/nagios/etc/objects/*.cfg  /usr/local/nagios/etc/.
sed -i -e "s@use_authentication=1@use_authentication=0@"  /usr/local/nagios/etc/cgi.cfg

chown -R nagios.nagios /usr/local/nagios
#yum -y install xinetd
#firefox http://localhost/nagios &

echo -e "\033[31;42m ********** Install Nagios NRPE 2.14 on CentOS 6.5 x64 ********** \033[0m"


if  [ "chkconfig --list | grep nrpe" != "" ]; then
  echo "Turn Off nrpe by yum install, if exist"
  chkconfig nrpe off
  service nrpe stop
fi

# nrpe is ok on "service nrpe restart", but failed on "/usr/lib/nagios/plugins/check_nrpe -H localhost"
# so we will start NRPE by xinetd
#./configure need gcc

tar zxvf nrpe-2.14.tar.gz
cd nrpe-2.14
#yum -y install gcc xinetd nagios-devel openssl-devel
#yum -y install openssl-devel

./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
cd ..

chown nagios.nagios /usr/local/nagios

chown -R nagios.nagios /usr/local/nagios/libexec

echo "nrpe 5666/tcp # NRPE"  >> /etc/services

chkconfig xinetd on
service xinetd restart
service xinetd status
netstat -at | grep nrpe
/usr/local/nagios/libexec/check_nrpe -H localhost

service iptables start
iptables -I INPUT -s 192.168.128.0/24 -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT
service iptables save
service iptables restart

echo -e "\033[31;42m ********** TEST on CentOS 6.5 x64 ********** \033[0m"

#let other nagios machine can browse this machine
#sed -i -e "s@127.0.0.1@127.0.0.1  192.168.128.128  10.3.0.208@"  /etc/xinetd.d/nrpe

chown -R nagios.nagios /usr/local/nagios

#service nagios restart
service xinetd restart
service httpd restart

# Kill nagios daemon on running...
ProcessID="`ps aux | grep nagios | awk '{print $2}' `"
for i in $ProcessID
do
  echo $i
  kill -9 $i
done
ps aux | grep nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

echo -e "\033[31m *.cfg : /usr/local/nagios/etc/*.cfg \033[0m"
echo " "
echo -e "\033[31m Please wait for FireFox ...\033[0m"
echo -e "\033[31m Account: nagiosadmin \033[0m"
echo -e "\033[31m Password : password \033[0m"

firefox http://localhost/nagios &






(完)

Setting Up Email Alerts for Network Monitoring with Nagios

[研究] Nagios 4.0.2 安裝 (CentOS 6.5 x64)
http://shaurong.blogspot.tw/2014/01/nagios-402-centos-65-x64.html

[研究] Nagios XI 2012 R2.7 安裝
http://shaurong.blogspot.tw/2014/01/nagios-xi-2012-r27.html

[研究] Nagios 4.0.0 Beta1 安裝 (CentOS 6.4 x64)
http://shaurong.blogspot.tw/2013/08/nagios-400-beta1-centos-64-x64.html

[研究] Nagios XI 2012 R1.5 安裝
http://shaurong.blogspot.tw/2013/02/nagios-xi-2012-r15.html

[研究] Nagios XI 安裝
http://forum.icst.org.tw/phpbb/viewtopic.php?t=18007

[研究] Nagios 3.2.3 安裝(tar.gz)(CentOS 6.0 x86)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=20254

[研究] Nagios 3.2.0 快速安裝程式(tar.gz)(CentOS 5.4 x86)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=17761

[研究] Nagios 3.2.3 快速安裝程式(yum)(Fedora 15 x86)(失敗)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=20253

[研究] Nagios 3.2.3 安裝(tar.gz)(Fedora 15 x86)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=20255

[研究] Nagios 3.2.3 快速安裝程式(yum)(Fedora 14 x86)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=19201

[研究] Nagios 3.0.6 快速安裝程式(tar.gz)(Fedora 9)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=16071

[研究] Nagios 2.12 快速安裝程式(tar.gz)(Fedora 9)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=16129

[研究] Nagios 2.11 快速安裝程式(yum)(Fedora 9)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=16073

[研究] Nagios 2.7 安裝(yum)(Fedora Core 5)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=12854

3 則留言:

  1. 冒昧請問 怎麼實現Windows mount point volume 的空間監控?

    ./check_nrpe -u -H 192.168.102.71 -p 5666 -c CheckDriveSize -a ShowAll MaxWarnUsed=90% MaxCritUsed=95% Drive=C:/Volume/abc
    OK: C:/Volume/abc: Total: 16.568GB - Used: 120.719MB - Free: 16.45GB|'C:/Volume/abc used'=0GB;14;15;0;16 'C:/Volume/abc used %'=0%;89;94;0;100

    直接於command line執行沒問題,可是在Nagios內的的log則出現Could not get free space reason 3

    再麻煩指教一下,感恩

    回覆刪除
    回覆
    1. 不知道您發生甚麼問題,您是用 CentOS ? 用 root ?

      刪除
    2. 我是用Nagios去監控Windows,Windows內安裝NSclient++ 4.2.88
      實體硬碟C:、D:我知道可以利用check_nt的指令去檢查剩餘空間
      不過掛載的磁碟(C:\abc\Volume_1,C:\abc\Volume_2這類)就不知道怎麼處理了

      有查到可利用check_nrpe CheckDriveSize的方式
      不過我測試Nagios主機的終端機上透過指令執行都沒問題也可以正常回報
      但是上到Nagios上就會出現錯誤了

      刪除