2013年8月5日 星期一

[研究] Nagios 4.0.0 Beta1 安裝 (CentOS 6.4 x64)

[研究] Nagios 4.0.0 Beta1 安裝 (CentOS 6.4 x64)

官方網站
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

預設帳號是 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.0-beta1.tar.gz on CentOS 6.4 x64 ********** \033[0m"
echo -e "\033[31m 2013/08/05 ********** \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.0-beta1.tar.gz
then
    echo "nagios-4.0.0-beta1.tar.gz exist"
else
    wget  http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.0-beta1.tar.gz
fi

if test -f nagios-plugins-1.4.16.tar.gz
then
    echo "nagios-plugins-1.4.16.tar.gz exist"
else
    wget  http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
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

#3) Compile and Install Nagios

tar xzf nagios-4.0.0-beta1.tar.gz
cd nagios
./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.4.16.tar.gz
cd nagios-plugins-1.4.16
./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.4.16 on CentOS 5.4 x86 ********** \033[0m"

tar zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./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.12 on CentOS 5.4 x86 ********** \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 restart
#iptables  -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
#iptables  -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
# Fedora
#iptables  -A INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT
#iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT
#iptables -I RH-Firewall-1-INPUT -s 192.168.128.0/24 -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT
#iptables -I RH-Firewall-1-INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
# CentOS 5.4 x86
iptables -I RH-Firewall-1-INPUT -s 192.168.128.0/24 -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT
# Fedora 12 x86
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 5.4 x86 ********** \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 &




(完)

[研究] Nagios 4.0.0 Beta1 安裝 (CentOS 6.4 x64)
http://shaurong.blogspot.tw/2013/08/nagios-400-beta1-centos-64-x64.html
http://forum.icst.org.tw/phpbb/viewtopic.php?t=80069

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

CentOS 5.8 Nagios 3.3.1 Check_nt回報設定
http://forum.icst.org.tw/phpbb/viewtopic.php?t=26279

網路監控你選Cacti還是Nagios呢?
http://forum.icst.org.tw/phpbb/viewtopic.php?t=24328

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

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

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

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

有人成功在 Fedora 14 上安裝 nagios-3.2.3.tar.gz 嗎 ?
http://forum.icst.org.tw/phpbb/viewtopic.php?t=19184

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

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

[問題] 請問如何用 nagios 檢查 iptables 是否有執行 ?
http://forum.icst.org.tw/phpbb/viewtopic.php?t=17678

[問題] 請問 nagios 的歷史狀態資料如何清除 ?
http://forum.icst.org.tw/phpbb/viewtopic.php?t=17677

[研究] Nagios 2.12快速安裝程式(Fedora9,tgz版)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=16129

大家用過哪些管理工具?感覺如何? (Nagios, MRTG,...)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=16091

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

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

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

有人會用 nagios 的 check_oracle 嗎 ?
http://forum.icst.org.tw/phpbb/viewtopic.php?t=14382

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

nagios 2.9穩定嗎? 還是偵測方式問題? (FC5, 使用 tar.gz 安裝)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=12853

[問題] F7 (Fedora 7)上如何用yum安裝nagios ?
http://forum.icst.org.tw/phpbb/viewtopic.php?t=12743

【FreeBSD】Nagios-提供高效能和高準確性的網路監控軟體
http://forum.icst.org.tw/phpbb/viewtopic.php?t=12648

[問題] FC5(Fedora Core 5)上用tar.gz安裝nagios 2.9體無法使用?
http://forum.icst.org.tw/phpbb/viewtopic.php?t=12599

沒有留言:

張貼留言