Nagios监控服务器IP:192.168.11.5
VPN 监控服务器IP:192.168.11.6
Nagios 配置如下:
一 、安装Apache+php
2 编译安装php
yum install libxml2-devel
Cd /usr/local/php-5.4.3
./configure--prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs
make && make install
3 修改apache的配置文件
vi /usr/local/apache2/conf/httpd.conf
<IfModule dir_module>
DirectoryIndex index.html index.php # 添加 index.php
</IfModule>
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module modules/libphp5.so #添加
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php # 添加
4 测试php是否安装成功
cd /usr/local/apache2/htdocs/
vi test.php
<?php
phpinfo();
?>
5 使用游览器访问
php到此安装成功
二 、安装Nagios监控服务器
安装nagios
1 安装nagios
useradd -s /sbin/nologin nagios # 建立nagios用户
cd /usr/local/nagios-3.2.3/
./configure --prefix=/usr/local/nagios
make all
make install
make install-init #在/etc/rc.d/init.d/目录下创建启动脚本
make install-commandmode #配置目录权限
make install-config #安装nagios示例配置文件,这里安装路径为/usr/local/nagios/etc
2 安装nagios 插件
cd /usr/local/nagios-plugins-1.4.15/
./configure --prefix=/usr/local/nagios #这里插件安装的位置与nagios相同
make && make install
3 配置apache ,使用apache支持nagios
vi /usr/local/apache2/conf/httpd.conf
修改为
User nagios
Group nagios
最后添加
#nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
4 创建nagios访问的用户 用户名称为nagios
/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd naigos
New password:
Re-type new password:
Adding password for user naigos
5 启动apache
/usr/local/apache2/bin/apachectl restart
6 修改naigos的权限
chown nagios.nagios /usr/local/nagios
chown nagios.nagios -R /usr/local/nagios/libexec/
7 使用游览器访问nagios服务器
显示乱码,解决方法:
主要是apache没有开启cgi脚本的缘故
进入apache的主配置文件httpd.conf
vi /usr/local/apache2/conf/httpd.conf
#LoadModule cgid_module modules/mod_cgid.so
#LoadModule actions_module modules/mod_actions.so
将上面2行的#去掉,重启apache就OK了
8 配置nagios服务器
[root@localhost local]# cd /usr/local/nagios-3.2.3/
[root@localhost nagios-3.2.3]# cd /usr/local/nagios
[root@localhost nagios]# ls
bin etc include libexec sbin share var
[root@ac96548d etc]# vi /usr/local/nagios/etc/cgi.cfg
main_config_file=/usr/local/nagios/etc/nagios.cfg
physical_html_path=/usr/local/nagios/share
url_html_path=/nagios show_context_help=0
use_pending_states=1
use_authentication=1
use_ssl_authentication=0
default_user_name=nagios
authorized_for_system_information=nagiosadmin,nagios
#添加刚才使用htpasswd建立的用户naigos (使用nagios于nagiosadmin用户才能看到监控的主机)
authorized_for_configuration_information=nagiosadmin,nagios
authorized_for_system_commands=nagios
authorized_for_all_services=nagiosadmin,nagios
authorized_for_all_hosts=nagiosadmin,nagios
authorized_for_all_service_commands=nagiosadmin,nagios
authorized_for_all_host_commands=nagiosadmin,nagios
default_statusmap_layout=5 default_statuswrl_layout=4
ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$
refresh_rate=90 escape_html_tags=1
action_url_target=_blank notes_url_target=_blank lock_author_names=1
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 检测nagios的配置文件是否有语法错误
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg 启动nagios监控服务器
9 通过游览器可以看到nagios监控服务器本机的状态
至此 nagios监控服务器安装成功