一聚教程网:一个值得你收藏的教程网站

热门教程

Ubuntu 12.04中安装配置Nagios 4.0.5步骤详解

时间:2022-06-30 19:22:49 编辑:袖梨 来源:一聚教程网

以下是2014-4-17安装记录:
== 服务端 ==
安装依赖包:(其实不装也能安装成功,就是部分功能会disabled)

sudo apt-get install build-essential libssl-dev \
libgd2-xpm-dev libpng12-dev php5-gd libgd2-xpm
用户组:
sudo adduser --system --no-create-home --disabled-login --group nagios
sudo groupadd nagcmd
sudo usermod -G nagcmd nagios
sudo usermod -a -G nagcmd www-data
从 http://www.nagios.org/download/ 下载解压:

cd /tmp
mkdir nagios
cd nagios
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.5.tar.gz
wget http://www.nagios-plugins.org/download/nagios-plugins-2.0.1.tar.gz
tar zxf nagios-4.0.5.tar.gz
tar zxf nagios-plugins-2.0.1.tar.gz
编译安装:

cd /tmp/nagios/nagios-4.0.5
./configure --prefix=/opt/nagios --sysconfdir=/etc/nagios \
--with-nagios-user=nagios --with-nagios-group=nagios \
--with-command-user=nagios --with-command-group=nagcmd
make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode
建立htpasswd.users,这个如果装了apache2有htpasswd这个命令,不然可以用某个python脚本:
(如果服务器不想装python,可以找台有python的服务器;或者找台装了apache的机器运行htpasswd;或者装个httpd不启动也没关系)
(生成的htpasswd.users是个文本文件,复制到服务器的 /etc/nagios/htpasswd.users)
wget http://trac.edgewall.org/export/10791/trunk/contrib/htpasswd.py
chmod +x htpasswd.py
./htpasswd.py -c -b /etc/nagios/htpasswd.users nagiosadmin "password"
修改联系人email,在contacts.cfg的email那里(34行)
sudo vi /etc/nagios/objects/contacts.cfg
安装mail报警通知所需包(安装时选择”Internet Site”;输入域名)
(注意:不装这个mail包编译nagios-plugins-2.0.1会error,但是编译nagios-plugins-2.0没问题。。。)
sudo apt-get install mailutils postfix
sudo ln -s /usr/bin/mail /bin/mail
安装插件:
cd /tmp/nagios/nagios-plugins-2.0.1
./configure --prefix=/opt/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make install
sudo chown -R nagios:nagios /opt/nagios
启动nagios
sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
sudo service nagios start
安装fcgi
sudo apt-get install spawn-fcgi fcgiwrap
编辑nginx.conf

sudo vi /etc/nginx/sites-enabled/nagios
其中对/nagios/开头的地址进行了rewrite,(nagios内部很多页面是写死/nagios/开头的,导致images、css等出不来)

server {
  server_name nagios.bianbian.org;
  access_log  /var/log/nginx/nagios.access.log;
  error_log   /var/log/nginx/nagios.error.log;
  auth_basic            "Restricted Nagios Area!";
  auth_basic_user_file  /etc/nagios/htpasswd.users;
  root    /opt/nagios/share/;
  location ~ ^/nagios/ {
    rewrite ^/nagios/(.*) /$1 permanent;
  }
  location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.socket;
  }
  location ~ \.cgi$ {
    root /opt/nagios/sbin/;
    rewrite ^/cgi-bin/(.*)\.cgi /$1.cgi break;
    fastcgi_param AUTH_USER $remote_user;
    fastcgi_param REMOTE_USER $remote_user;
    include fastcgi_params;
    fastcgi_pass unix:/var/run/fcgiwrap.socket;
  }
}
启动服务
sudo service nagios start

登录后就看到nagios的监控界面了

热门栏目