- 1.安装所需环境
- LAMP或者LNMP
- nagios-3.3.1.tar.gz-------------主程序
- nagios-plugins-1.4.15.tar.gz----插件
- 2.安装nagios-3.3.1.tar.gz
- 添加、修改用户以及组
- [root@localhost nagios]# useradd nagios
- [root@localhost nagios]# useradd apache
- [root@localhost nagios]# passwd nagios
- [root@localhost nagios]# groupadd nagcmd //创建用户组用于Web接口执行外部命令
- [root@localhost nagios]# usermod -g nagcmd nagios
- [root@localhost nagios]# usermod -g nagcmd apache
- [root@localhost monitor]# tar zxvf nagios-3.3.1.tar.gz -C /usr/local/src/
- [root@localhost monitor]# tar zxvf nagios-plugins-1.4.15.tar.gz -C /usr/local/src/
- [root@localhost monitor]# cd /usr/local/src/nagios
- [root@localhost nagios]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios
- --with-nagios-group=nagios --with-command-group=nagcmd --with-gd-lib=/usr/lib/ --with-gd-inc=/usr/include/
- 配置成功后会有如下提示:
- *** Configuration summary for nagios 3.3.1 07-25-2011 ***:
- General Options:
------------------------- Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /bin/traceroute- [root@localhost nagios]# make all
- [root@localhost nagios]# make install
- [root@localhost nagios]# make install-init
- [root@localhost nagios]# make install-config
- [root@localhost nagios]# make install-commandmode
- [root@localhost nagios]# vi /usr/local/nagios/etc/objects/contacts.cfg
修改email地址以接收报警内容- [root@localhost nagios]# make install-webconf
- /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
- /usr/bin/install: 无法创建普通文件"/etc/httpd/conf.d/nagios.conf": 没有那个文件或目录
- make: *** [install-webconf] 错误 1
- [root@localhost nagios]# mkdir -p /etc/httpd/conf.d/
- [root@localhost nagios]# /usr/local/webserver/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
- 3.安装nagios插件
- [root@localhost nagios]# cd ../nagios-plugins-1.4.15/
- [root@localhost nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
- 配置成功后有如下提示:
- --with-apt-get-command:
- --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
- --with-ping-command: /bin/ping -n -U -w %d -c %d %s
- --with-ipv6: yes
- --with-mysql: /usr/bin/mysql_config
- --with-openssl: yes
- --with-gnutls: no
- --enable-extra-opts: no
- --with-perl: /usr/bin/perl
- --enable-perl-modules: no
- --with-cgiurl: /nagios/cgi-bin
- --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
- --enable-libtap: no
- [root@bogon nagios-plugins-1.4.15]# make
[root@bogon nagios-plugins-1.4.15]# make install- 验证Nagios配置文件
- [root@bogon nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
启动Nagios服务
[root@bogon nagios]# service nagios start
4.编辑apache的httpd.conf- 在最后添加:
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"- <Directory "/usr/local/nagios/sbin">
- # SSLRequireSSL
- Options ExecCGI
- AllowOverride None
- Order allow,deny
- Allow from all
- # Order deny,allow
- # Deny from all
- # Allow from 127.0.0.1
- AuthName "Nagios Access"
- AuthType Basic
- AuthUserFile /usr/local/nagios/etc/htpasswd.users
- Require valid-user
- </Directory>
- Alias /nagios "/usr/local/nagios/share"
- <Directory "/usr/local/nagios/share">
- # SSLRequireSSL
- Options None
- AllowOverride None
- Order allow,deny
- Allow from all
- # Order deny,allow
- # Deny from all
- # Allow from 127.0.0.1
- AuthName "Nagios Access"
- AuthType Basic
- AuthUserFile /usr/local/nagios/etc/htpasswd.users
- Require valid-user
- </Directory>
- 5.再验证下
- [root@bogon nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
没有出错的话,重新启动nagios和apache- 6.登录web页面
- http://localehost/nagios
- 输入刚才设置的用户名密码。