Nagios安装文档
(Apache+Php+Nagios)
需求:监控多台服务器,及时报警
建议:nagios尽量单独安装到一台服务器上,避免与其他服务混合使用服务器
系统整体化境LANP(Debian6.0.5+Apache+Nagios+Php5.4)
Nagios安装文档(Apache+Php+Nagios) (1)
一、安装Linux(Debian)系统 (3)
1. 安装基本的debian环境 (3)
2. 优化debian系统 (3)
二、安装Apache服务器 (3)
1. 下载apache (3)
2. 编译安装 (3)
3. 启动apache (3)
三、安装PHP (4)
1. 安装php5.4 (4)
2. 优化php (4)
四、配置apahce & php (4)
1. 配置apache的httpd.conf文件 (4)
2. 优化Apache (5)
3. 重启Apache (5)
五、安装Nagios (5)
1. 安装libgd2 (5)
2. 创建nagios用户信息 (5)
3. 下载nagios (5)
4. 解压安装nagios (6)
5. 修改配置文件contacts.cfg (6)
6. 安装nagios插件 (6)
7. 添加至系统服务 (7)
8. 启动nagios (7)
六、配置Apache和Nagios结合点 (7)
1. 创建验证文件 (7)
2. 添加nagios配置文件 (7)
3. 修改apache配置文件 (8)
4. 重启apache (9)
一、安装Linux(Debian)系统
1.安装基本的debian环境
参考文档:https://www.sodocs.net/doc/7017714008.html,/install-and-setup-debian.html
2.优化debian系统
参考文档:https://www.sodocs.net/doc/7017714008.html,
二、安装Apache服务器
1.下载apache
下载地址:https://www.sodocs.net/doc/7017714008.html,/download.cgi
2.编译安装
编译安装参数:
./configure --prefix=/usr/local/apache --enable-so--enable-cgi--enable-info--enable-rewrite--enable-speling--enable-usertrack--enabl e-deflate
--enable-ssl--enable-mime-magic--enable-module=so--enable-module=rewrite--enable-share d=max
3.启动apache
#/usr/local/apache/bin/apachectl start
#/usr/local/apache/bin/apachectl stop
#/usr/local/apache/bin/apachectl restart
三、安装PHP
1.安装php5.4
参考文档:https://www.sodocs.net/doc/7017714008.html,/debian-php5-4.html
注意:和nginx编译参数不同,改为:
./configure --prefix=/usr/local/php --enable-fpm --with-curl --with-gd --enable-mbstring --with-mysql --with-mysqli --enable-gd-native-ttf --enable-sockets --with-jpeg-dir --with-png-dir --with-freetype-dir --with-zlib --enable-ftp --with-apxs2=/usr/local/apache/bin/apxs
2.优化php
参考文档:https://www.sodocs.net/doc/7017714008.html,
四、配置apahce & php
1.配置apache的httpd.conf文件
A、修改文件/usr/local/apache/conf/httpd.conf添加默认文件
DirectoryIndex index.html index.htm index.php
B、加载支持php的模块
LoadModule php5_module modules/libphp5.so
C、添加php识别
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
D、测试php
此时创建i.php文件,如何http://ip/i.php可以访问则说明php环境配置ok 2.优化Apache
参考文档:https://www.sodocs.net/doc/7017714008.html,
3.重启Apache
#/usr/local/apache/bin/apachectl restart
五、安装Nagios
1.安装libgd2
root@lanp:~# aptitude search libgd2
root@lanp:~# aptitude install libgd2-xpm
2.创建nagios用户信息
root@dnnp:~# useradd -s /sbin/nologin nagios
root@dnnp:~# mkdir /usr/local/nagios
root@dnnp:~# chown nagios.nagios /usr/local/nagios
3.下载nagios
下载nagios相关软件:nagios-3.4.1.tar.gz、nagios-plugins-1.4.16.tar.gz
nagios下载地址:
https://www.sodocs.net/doc/7017714008.html,/project/nagios/nagios-3.x/nagios-3.4.1/nagios-3.4.1.tar.gz
nagios-plugins下载地址
https://www.sodocs.net/doc/7017714008.html,/project/nagiosplug/nagiosplug/1.4.16/nagi os-plugins-1.4.16.tar.gz
4.解压安装nagios
root@lanp:~/software#tar -zxvf nagios-3.4.1.tar.gz
root@lanp:~/software# cd nagios/
root@lanp:~/software/nagios# ./configure --prefix=/usr/local/nagios
root@lanp:~/software/nagios# make all
root@lanp:~/software/nagios# make install
root@lanp:~/software/nagios# make install-init
root@lanp:~/software/nagios# make install-commandmode
root@lanp:~/software/nagios# make install-config
5.修改配置文件contacts.cfg
修改配置文件/usr/local/nagios/etc/objects/contacts.cfg,将define contact里面的email改成自己的email
6.安装nagios插件
Nagios编译参数为:
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
root@lanp:~/software# tar -zxvf nagios-plugins-1.4.16.tar.gz
root@lanp:~/software# cd nagios-plugins-1.4.16/
root@lanp:~/software/nagios-plugins-1.4.16# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
root@lanp:~/software/nagios-plugins-1.4.16# make
root@lanp:~/software/nagios-plugins-1.4.16# make install
7.添加至系统服务
把Nagios加入到服务列表中以使之在系统启动时自动启动
root@lanp:~# ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
8.启动nagios
A、验证nagios配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
B、启动、关闭nagios
root@lanp:~# /etc/init.d/nagios start/stop/restart
root@lanp:~# service nagios start/stop/restart
六、配置Apache和Nagios结合点
1.创建验证文件
文件为/usr/local/nagios/etc/https://www.sodocs.net/doc/7017714008.html,er 用户名为nagiosadmin
root@lanp:~#/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/https://www.sodocs.net/doc/7017714008.html,er nagiosadmin
2.添加nagios配置文件
添加nagios配置文件,文件路径:/usr/local/apache/conf/conf.d/nagios.conf配置文件内容为:
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
# Last Modified: 11-26-2005
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file. Customize the paths, etc. as
# needed to fit your system.
ScriptAlias /nagios/cgi-bin "/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/https://www.sodocs.net/doc/7017714008.html,er
Require valid-user
Alias /nagios "/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/https://www.sodocs.net/doc/7017714008.html,er
Require valid-user
3.修改apache配置文件
修改apache配置文件/usr/local/apache/conf/httpd.conf
A、在结尾添加Include /usr/local/apache/conf/conf.d/nagios.conf
B、LoadModule cgid_module modules/mod_cgid.so前面的注释去掉
C、AddHandler cgi-script .cgi .pl 前面注释去掉
4.重启apache
root@lanp:~# /usr/local/apache/bin/apachectl restart
完成验证
打开http://192.168.20.132/nagios/ 输入密码就可以看到nagios 的主页面
主要命令
Nagios文件验证:/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Nagios重启:/etc/init.d/nagios start/stop/restart
Apache重启:/usr/local/apache/bin/apachectl restart
注:nagios必须开启的服务
Php
Apache
Nagios
参考文档:
https://www.sodocs.net/doc/7017714008.html,
https://www.sodocs.net/doc/7017714008.html,
https://www.sodocs.net/doc/7017714008.html,/nagios-cn/