./configure --prefix=/usr/local/nagios-1.6.3
make all
make install
make install-init
make install-config
make install-commandmode
(make install-webconf #可以自动配置httpd.conf)
cp sample-config/httpd.conf /usr/local/apache/conf/extra/nagios.conf
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
(nagiosadmin 要与 /usr/local/nagios/etc/objects/contacts.cfg 里的 contact_name 相同)
chkconfig --add nagios
chkconfig --levels 345 nagios on
chown -R nagios.nagios nagios-1.6.3
ln -s nagios-1.6.3 nagios
1.2 安装nagios-plugins
cd nagios-plugins-1.4.12
./configure --prefix=/usr/local/nagios-1.6.3 --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
make
make install
1.3 安装NRPE
cd nagios-nrpe_2.12
./configure #默认自动添加了openssl
./configure --prefix=/usr/local/nagios-1.6.3 --enable-ssl --with-ssl-lib=/lib/
make all
make install-plugin
make install-daemon
make install-daemon-config
1.4 commands.cfg定义外部构件nrpe
vi /usr/local/nagios/etc/objects/commands.cfg
#添加
#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
1.5.配置要监控的linux主机
vi /usr/local/nagios/etc/nagios.cfg
#中间添加
cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg
vi /usr/local/nagios/etc/objects/mylinux.cfg
define host{
use linux-server
host_name mylinux
alias mylinux
# 客户端IP
address 192.168.1.212
}
define service{
use generic-service
host_name mylinux
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name mylinux
service_description check-load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name mylinux
service_description check-disk
check_command check_nrpe!check_hda1 }
define service{
use generic-service
host_name mylinux
service_description check-users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name mylinux
service_description otal_procs
check_command check_nrpe!check_total_procs
}
1.6.其它设置
chkconfig --add nagios #配置机器启动时自动启动Nagios
chkconfig nagios on
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #检查Nagios配置文件
vi /etc/selinux/config #关闭SELinux
SELINUX=disabled
service iptables stop #关闭SELinux,或打开80,5666端口
service nagios start
二. 配置WEB服务:
2.1 安装httpd和php
yum install httpd php -y
2.2配置nagios的web服务:
在/etc/httpd/http.d中建立nagios.conf文件:
[iyunv@yucheng22 tmp]# cat nagios.conf
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
#
# 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.
<Directory "/usr/local/nagios-1.6.3/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-1.6.3/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios-1.6.3/share"
<Directory "/usr/local/nagios-1.6.3/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-1.6.3/etc/htpasswd.users
Require valid-user
</Directory>