/ 中存储网

Ubuntu 11.10/Ubuntu 10.4上安装Nagios的方法及命令

2015-07-22 16:11:48 来源:中存储网

由于需要用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:/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:/media/europa/callisto/nagios___/nagios-3.3.1/nagios#