系統要求
The only requirement of running Nagios is a machine running Linux (or UNIX variant) and a C compiler. You will probably also want to have TCP/IP configured, as most service checks will be performed over
The only requirement of running Nagios is a machine running Linux (or UNIX variant) and a C compiler. You will probably also want to have TCP/IP configured, as most service checks will be performed over
系統要求
The only requirement of running Nagios is a machine running Linux (or UNIX variant) and a C compiler. You will probably also want to have TCP/IP configured, as most service checks will be performed over
The only requirement of running Nagios is a machine running Linux (or UNIX variant) and a C compiler. You will probably also want to have TCP/IP configured, as most service checks will be performed over
the network.
You are not required to use the CGIs included with Nagios. However, if you do decide to use them, you will need to have the following software installed...
1。A web server (preferrably Apache)
2。Thomas Boutell's gd library version 1.6.3 or higher (required by the statusmap and trends CGIs)
1.下載源碼包
wget http://nchc.dl.sourceforge.net/sourceforge/nagios/nagios-2.0b3.tar.gz
2.解壓源碼包
tar xfvz nagios-2.0b3.tar.gz
3.配置編譯
cd nagios-2.0b3
adduser nagios
mkdir /usr/local/nagios
chown nagios.nagios /usr/local/nagios
grep "^User" /usr/local/apache2/conf/httpd.conf
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nobody
/usr/sbin/usermod -G nagcmd nagios
./configure --prefix=/usr/local/nagios --with-cgiurl=/nagios/cgi-bin --with-htmlurl=/nagios --with-nagios-usr=nagios --with-nagios-group=nagios --with-command-group=nagcmd --with-gd-lib -
wget http://nchc.dl.sourceforge.net/sourceforge/nagios/nagios-2.0b3.tar.gz
2.解壓源碼包
tar xfvz nagios-2.0b3.tar.gz
3.配置編譯
cd nagios-2.0b3
adduser nagios
mkdir /usr/local/nagios
chown nagios.nagios /usr/local/nagios
grep "^User" /usr/local/apache2/conf/httpd.conf
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nobody
/usr/sbin/usermod -G nagcmd nagios
./configure --prefix=/usr/local/nagios --with-cgiurl=/nagios/cgi-bin --with-htmlurl=/nagios --with-nagios-usr=nagios --with-nagios-group=nagios --with-command-group=nagcmd --with-gd-lib -
-enable-embedded-perl --with-perlcache
make all
make install
make install-init
make install-commandmode
make install-config
make install
make install-init
make install-commandmode
make install-config
安裝nagios-plugs
1.下載源碼包
wget http://nchc.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.tar.gz
2.解壓源碼包
tar xfvz nagios-plugins-1.4.tar.gz
3.配置編譯
./configure --prefix=/usr/local/nagios --with-mysql --with-cgiurl
make
make install
wget http://nchc.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.tar.gz
2.解壓源碼包
tar xfvz nagios-plugins-1.4.tar.gz
3.配置編譯
./configure --prefix=/usr/local/nagios --with-mysql --with-cgiurl
make
make install
配置apache
http.conf
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
AllowOverride AuthConfig
Options ExecCGI
Order allow,deny
Allow from all
AllowOverride AuthConfig
Options ExecCGI
Order allow,deny
Allow from all
Alias /nagios "/usr/local/nagios/share"
Options None
AllowOverride AuthConfig
Order allow,deny
Allow from all
Options None
AllowOverride AuthConfig
Order allow,deny
Allow from all
Authorization In The CGIs
The second step is to create a file named .htaccess in the root your CGI directory (and optionally also you HTML directory) for Nagios (usually /usr/local/nagios/sbin and /usr/local/nagios/share, respectively).
The second step is to create a file named .htaccess in the root your CGI directory (and optionally also you HTML directory) for Nagios (usually /usr/local/nagios/sbin and /usr/local/nagios/share, respectively).
The file(s) should have contents similiar to the following... :
cd /usr/local/nagios/sbin
vi .htaccess
vi .htaccess
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user
cd /usr/local/nagios/share
vi .htaccess
vi .htaccess
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user
Setting Up Authenticated Users:
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
格式:
htpasswd -c /usr/local/nagios/etc/htpasswd.users
Enabling Authentication/Authorization Functionality In The CGIs
The next thing you need to do is make sure that the CGIs are configured to use the authentication and authorization functionality in determining what information and/or commands users have access to. This is
done be setting the use_authentication variable in the CGI configuration file to a non-zero value. Example:
vi /usr/local/nagios/etc/cgi.cfg
use_authentication=1
use_authentication=1
/usr/local/apache2/bin/apachectl restart
配置文件
一. nagios.cfg
首先,剛裝好的nagios,在/usr/local/nagios/etc 下,文件都是以-sample結尾的,要把某些文件去掉-sample。
主配置文件 nagios.cfg
mv nagios.cfg--sample nagios.cfg
vi nagios.cfg
註釋這句話
#cfg_file=/usr/local/nagios/etc/minimal.cfg
在 # OBJECT CACHE FILE 這句話前面添加如下語句
cfg_dir=/usr/local/nagios/etc/hosts
cfg_dir=/usr/local/nagios/etc/contacts
cfg_dir=/usr/local/nagios/etc/services
cfg_dir=/usr/local/nagios/etc/commands
首先,剛裝好的nagios,在/usr/local/nagios/etc 下,文件都是以-sample結尾的,要把某些文件去掉-sample。
主配置文件 nagios.cfg
mv nagios.cfg--sample nagios.cfg
vi nagios.cfg
註釋這句話
#cfg_file=/usr/local/nagios/etc/minimal.cfg
在 # OBJECT CACHE FILE 這句話前面添加如下語句
cfg_dir=/usr/local/nagios/etc/hosts
cfg_dir=/usr/local/nagios/etc/contacts
cfg_dir=/usr/local/nagios/etc/services
cfg_dir=/usr/local/nagios/etc/commands
存盤退出
mkdir hosts
mkdir contacts
mkdir services
mkdir commands
mkdir contacts
mkdir services
mkdir commands
這樣做,主要是爲了分類,管理方便。
有些cfg文件可以參照 bigger.cfg-sample,minimal.cfg-sample 這兩個文件
有些cfg文件可以參照 bigger.cfg-sample,minimal.cfg-sample 這兩個文件
cd hosts
vi hosts.cfg
vi hosts.cfg
###############################################################################
###############################################################################
#
# HOSTS
#
###############################################################################
###############################################################################
###############################################################################
#
# HOSTS
#
###############################################################################
###############################################################################
# Generic host definition template - This is NOT a real host, just a template!
define host{
name generic-host ; The name of this host template
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}
name generic-host ; The name of this host template
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}
# Since this is a simple configuration file, we only monitor one host - the
# local host (this machine).
define host{
use generic-host ; Name of host template to use
host_name SH4
alias SH4
address 192.168.168.244
check_command check-host-alive
max_check_attempts 10
notification_interval 120
notification_period 24x7
notification_options d,r
contact_groups admins
}
define host{
use generic-host ; Name of host template to use
host_name SH3
alias SH3
address 192.168.168.243
check_command check-host-alive
max_check_attempts 10
notification_interval 120
notification_period 24x7
notification_options d,r
contact_groups admins
}
use generic-host ; Name of host template to use
host_name SH4
alias SH4
address 192.168.168.244
check_command check-host-alive
max_check_attempts 10
notification_interval 120
notification_period 24x7
notification_options d,r
contact_groups admins
}
define host{
use generic-host ; Name of host template to use
host_name SH3
alias SH3
address 192.168.168.243
check_command check-host-alive
max_check_attempts 10
notification_interval 120
notification_period 24x7
notification_options d,r
contact_groups admins
}
如果有很多服務器,可以把這些服務器分組
vi hostgroups.cfg
###############################################################################
###############################################################################
#
# HOST GROUPS
#
###############################################################################
###############################################################################
###############################################################################
#
# HOST GROUPS
#
###############################################################################
###############################################################################
# We only have one host in our simple config file, so there is no need to
# create more than one hostgroup.
# create more than one hostgroup.
define hostgroup{
hostgroup_name test
alias Test Servers
members SH4, SH3
}
hostgroup_name test
alias Test Servers
members SH4, SH3
}
cd /usr/local/nagios/etc/contacts
vi contacts.cfg
###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################
# In this simple config file, a single contact will receive all alerts.
# This assumes that you have an account (or email alias) called
# "nagios-admin" on the local host.
# This assumes that you have an account (or email alias) called
# "nagios-admin" on the local host.
define contact{
contact_name nagios-admin
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email [email protected]
}
contact_name nagios-admin
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email [email protected]
}
vi contactgroups.cfg
###############################################################################
###############################################################################
#
# CONTACT GROUPS
#
###############################################################################
###############################################################################
###############################################################################
#
# CONTACT GROUPS
#
###############################################################################
###############################################################################
# We only have one contact in this simple configuration file, so there is
# no need to create more than one contact group.
# no need to create more than one contact group.
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagios-admin
}
contactgroup_name admins
alias Nagios Administrators
members nagios-admin
}
cd /usr/local/nagios/etc/services
vi services.cfg
###############################################################################
###############################################################################
#
# SERVICES
#
###############################################################################
###############################################################################
# Generic service definition template - This is NOT a real service, just a template!
define service{
name generic-service ; The 'name' of this service template
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major per
formance problems)
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service 'freshness'
notifications_enabled 1 ; Service notifications are enabled
notification_options w,u,c,r,f
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
name generic-service ; The 'name' of this service template
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major per
formance problems)
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service 'freshness'
notifications_enabled 1 ; Service notifications are enabled
notification_options w,u,c,r,f
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
# Define a service to "ping" the machine
define service{
use generic-service ; Name of service template to use
host_name ns1
service_description PING
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_ping!100.0,20%!500.0,60%
}
use generic-service ; Name of service template to use
host_name ns1
service_description PING
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_ping!100.0,20%!500.0,60%
}
# Define a service to detect "http"
define service{
use generic-service ; Name of service template to use
host_name ns1
service_description HTTP
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_http
}
use generic-service ; Name of service template to use
host_name ns1
service_description HTTP
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_http
}
# Define a service to detect "ftp"
define service{
use generic-service ; Name of service template to use
host_name web01
service_description FTP
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_ftp
}
use generic-service ; Name of service template to use
host_name web01
service_description FTP
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_ftp
}
# Define a service to detect "DNS"
define service{
use generic-service ; Name of service template to use
host_name ns1
service_description DNS
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_dns
}
use generic-service ; Name of service template to use
host_name ns1
service_description DNS
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_dns
}
# Define a service to detect "SMTP"
define service{
use generic-service ; Name of service template to use
host_name web12
service_description SMTP
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_smtp
}
use generic-service ; Name of service template to use
host_name web12
service_description SMTP
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_smtp
}
# Define a service to detect "POP"
define service{
use generic-service ; Name of service template to use
host_name web12
service_description POP
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_pop
}
use generic-service ; Name of service template to use
host_name web12
service_description POP
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_pop
}
# Define a service to detect "IMAP"
define service{
use generic-service ; Name of service template to use
host_name web12
service_description IMAP
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_imap
}
use generic-service ; Name of service template to use
host_name web12
service_description IMAP
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 5
notification_period 24x7
check_command check_imap
}
# Define a service to detect "HTTPS"
define service{
use generic-service ; Name of service template to use
host_name web05
service_description HTTPS
is_volatile 0
use generic-service ; Name of service template to use
host_name web05
service_description HTTPS
is_volatile 0