由於需要用Nagios+Ganglia監控Hadoop集群,所以這裡開始了Nagios+Ganglia的旅程.Nagios官網上資料已經很詳盡,但在Ubuntu上安裝Nagios方面,只停留在Ubuntu 6.10和Ubuntu 7.10版本.而在Ubuntu11.10或Ubuntu10.04上安裝有些錯誤,所以這裡記錄下來.具體可以查看Nagios官網上Nagios在Ubuntu上安裝說明:http://nagios.sourceforge.net/docs/3_0/quickstart-ubuntu.html
1.所依賴包:
1)Apache #必須安裝
2)Php #必須安裝
3)Gcc #必須安裝
4)Gd #必須安裝
5) mailx #可選,讓Nagios支持郵件
6) postfix #可選,讓Nagios支持郵件
以上可以通過dpkp -L apache2等查看,如未安裝,請通過sudo apt-get install apache2等安裝,具體如下:
sudo apt-get install apache2 # 安裝Apache
sudo apt-get install php5 # 安裝Php
sudo apt-get install libapache2-mod-php5 # 整合Apache+Php
sudo apt-get install build-essential # 安裝Ubuntu編譯內核
sudo apt-get install libgd2-xpm-dev # 安裝Gd
sudo apt-get install mailx
sudo apt-get install postfix
2.開始安裝
sudo -s # 切換到root
1) 設置好用戶和用戶組
/usr/sbin/useradd -m -s /bin/bash nagios # 添加用戶nagios
passwd nagios # 給新用戶nagios設置密碼
/usr/sbin/groupadd nagios # 添加用戶組nagios
/usr/sbin/usermod -G nagios nagios # 將新用戶nagios添加到用戶組nagios
/usr/sbin/groupadd nagcmd # 添加新的用戶組nagcmd,用於接受外部命令,如通過web
/usr/sbin/usermod -a -G nagcmd nagios # 添加用戶nagios到用戶組nagcmd
/usr/sbin/usermod -a -G nagcmd www-data # 添加apache用戶到用戶組nagcmd
2)下載nagios和nagios-plugin
mkdir ~/downloads
cd ~/downloads
wget http://nchc.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz # 下載插件
wget http://nchc.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.3.1/nagios-3.3.1.tar.gz #下載nagios
3)安裝Nagios
cd ~/downloads
tar xzf nagios-3.3.1.tar.gz
cd nagios
./configure --with-command-group=nagcmd
make all
#make install #使用該命令會報錯,替換成以下命令
./configure --with-command-group=nagcmd
sed -i 's:for file in includes/rss/\*;:for file in includes/rss/\*.\*;:g' ./html/Makefile
sed -i 's:for file in includes/rss/extlib/\*;:for file in includes/rss/extlib/\*.\*;:g' ./html/Makefile
make fullinstall
#以上避免了使用make install報錯,報錯內容查看博客結尾.具體原因不清楚,有知道的麻煩回帖告知.
make install-init #安裝初始化,貌似make fullinstall有了安裝,但無所謂
make install-config #安裝配置
make install-commandmode #安裝命令模式
4)自定義配置
vi /usr/local/nagios/etc/objects/contacts.cfg #在裡面修改,如email
5)安裝web接口,以便通過浏覽器可以訪問到nagios
make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin #給nagios設置用戶和密碼
/etc/init.d/apache2 reload #重載,讓新設置的用戶和密碼生效
6)編譯nagios插件
cd ~/downloads
tar xzf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
7)啟動nagios
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios #讓nagios隨機啟動
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #驗證naios配置文件是否正確
/etc/init.d/nagios start #啟動nagios
8)通過浏覽器進入nagios控制台
http://localhost/nagios/ #再輸入剛配置的用戶nagiosadmin和你設置的密碼
最後附上用make install安裝nagios時所報錯誤
- root@www.linuxidc.com:/media/europa/callisto/nagios___/nagios-3.3.1/nagios# make install
- cd ./base && make install
- make[1]: Entering directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/base'
- make install-basic
- make[2]: Entering directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/base'
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin
- /usr/bin/install -c -m 774 -o nagios -g nagios nagios /usr/local/nagios/bin
- /usr/bin/install -c -m 774 -o nagios -g nagios nagiostats /usr/local/nagios/bin
- make[2]: Leaving directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/base'
- make strip-post-install
- make[2]: Entering directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/base'
- /usr/bin/strip /usr/local/nagios/bin/nagios
- /usr/bin/strip /usr/local/nagios/bin/nagiostats
- make[2]: Leaving directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/base'
- make[1]: Leaving directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/base'
- cd ./cgi && make install
- make[1]: Entering directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/cgi'
- make install-basic
- make[2]: Entering directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/cgi'
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/sbin
- for file in *.cgi; do \
- /usr/bin/install -c -m 775 -o nagios -g nagios $file /usr/local/nagios/sbin; \
- done
- make[2]: Leaving directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/cgi'
- make strip-post-install
- make[2]: Entering directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/cgi'
- for file in *.cgi; do \
- /usr/bin/strip /usr/local/nagios/sbin/$file; \
- done
- make[2]: Leaving directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/cgi'
- make[1]: Leaving directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/cgi'
- cd ./html && make install
- make[1]: Entering directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/html'
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/media
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/stylesheets
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/contexthelp
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/docs
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/docs/images
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/images
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/images/logos
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/includes
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/includes/rss
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/includes/rss/extlib
- /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/ssi
- /usr/bin/install -c -m 664 -o nagios -g nagios robots.txt /usr/local/nagios/share
- rm -f /usr/local/nagios/share/index.html
- rm -f /usr/local/nagios/share/main.html
- rm -f /usr/local/nagios/share/side.html
- for file in *.php; \
- do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share; done
- for file in stylesheets/*.css; \
- do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/stylesheets; done
- for file in contexthelp/*.html; \
- do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/contexthelp; done
- for file in images/*.gif; \
- do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/images; done
- for file in images/*.jpg; \
- do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/images; done
- for file in images/*.png; \
- do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/images; done
- for file in images/*.ico; \
- do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/images; done
- for file in images/logos/*.*; \
- do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/images/logos; done
- for file in includes/*.*; \
- do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/includes; done
- for file in includes/rss/*; \
- do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/includes/rss; done
- /usr/bin/install: omitting directory `includes/rss/extlib'
- /usr/bin/install: omitting directory `includes/rss/htdocs'
- /usr/bin/install: omitting directory `includes/rss/scripts'
- make[1]: *** [install] Error 1
- make[1]: Leaving directory `/media/europa/callisto/nagios___/nagios-3.3.1/nagios/html'
- make: *** [install] Error 2
- root@www.linuxidc.com:/media/europa/callisto/nagios___/nagios-3.3.1/nagios#