nagios 的安装

来源:互联网 发布:directx编程入门 编辑:程序博客网 时间:2024/05/16 06:28

来源:

http://webcache.googleusercontent.com/search?q=cache:KYssdPHmkHoJ:www.techmajha.com/2010/04/15/rpmforge-yum-repository/+nagios+Configuration+validation+failed&cd=10&hl=zh-CN&ct=clnk

http://heipark.iteye.com/blog/1190929


service nagios start  

出错:

nagios is stopped

Configuration validation failed        


解决办法:

# vi /etc/selinux/config
SELINUX=disabled

然后重启计算机,就OK了.


#安装nagios
yum -y install nagios nagios-nrpe nagios-plugins nagios-plugins-nrpe check_logfiles

#添加nagios到系统自动运行
chkconfig --add nagios
chkconfig nagios on

 

    nagios相关路径:

/etc/nagios  #配置文件目录:
/etc/nagios/objects  #模板相关配置
/usr/bin/nagios # nagios程序
 

配置Apache密码访问

 

# nagiosadmin为用户名,配置这个用户名为省很多事
htpasswd -c /etc/nagios/htpasswd.users nagiosadmin

启动并测试

 

service nagios start
service httpd start
#打开浏览器,输入密码,在host里面应该有“localhost”这台机器
http://{your_ip_address}/nagios

nagios is stopped
Configuration validation failed        
解决办法:

How to Access NTFS partition from linux (Centos / RHEL) ?
How to install media player like VLC on Centos / RHEL ?

How to install network monitoring tool like nagios on Centos / RHEL ?

You may have reached here while googling solution for above question’s ?

Centos / RHEL are the enterprise level server operating system and is not packaged with entertainment pack.

Whereas distributions like fedora, ubuntu Desktop are meant for clients or desktop computers. Where you will not come across above issues, the entertainment packages is the part of fedora and ubuntu distribution.

Here, RPMforge RPM repositories come into picture.
RPMforge is a collaboration of Dag, Dries, and other packagers. They provide over 4000 packages for CentOS, including mplayer, VLC, xmms-mp3, and other popular media tools. It is not part of RedHat or CentOS but is designed to work with these major distributions.

To install RPMforge YUM repository use following 5 steps.

Note: Internet required

1. Use following 3 sub steps to Install DAG GPG key

# wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
# rpm –import RPM-GPG-KEY.dag.txt
# rm RPM-GPG-KEY.dag.txt

2. Install yum-priorities.
Note :The yum-priorities is used to enforce ordered protection of repositories, by giving priorities to repositories. Packages from repositories with a lower priority will be given lowest priority. This plugin is particularly useful for anyone who uses one or more third-party repositories, as these repositories may update system files, which can potentially compromise the stability of your CentOS installation.

# yum install yum-priorities

3. Download and install package (i386 – 32bit) Use following 3 sub steps

# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
# rpm -Uhv rpmforge-release-0.3.6-1.el5.rf.i386.rpm
# rm rpmforge-release-0.3.6-1.el5.rf.i386.rpm

3. Download and install package (x86_64 – 64bit) Use following 3 sub steps

# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
# rpm -Uhv rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
# rm rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

4. Files created in /etc/yum.repos.d/ folder

# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Media.repo mirrors-rpmforge rpmforge.repo

5. Properly configure priorities of yum repositories as follows :

# vim /etc/yum.repos.d/CentOS-Base.repo
[base] or [updates] or [addons] or [extras]
priority=1
[centosplus]
priority=2

# vim /etc/yum.repos.d/rpmforge.repo
[rpmforge]
priority=10

Note: The Repository with higher priority will be given higher priority for installing any package. e.g. if you want rpmforge repository should have highest priority than you can set highest priority for the same as above. The priorities are also in effect when a new package is installed – if a package is in more than one repository, it will be installed from the repository with the highest priority.

——————————————————————————————————————————————————


Examples:
Gstreamer Movie Player is multimedia player for *NIX systems

# yum clean all

# yum install gstreamer*

# yum whatprovides gstreamer-plugins-ugly

# yum install gstreamer-plugins-ugly

# yum install gstreamer-plugins-bad

VLC Player is commonly used multimedia player

To install VLC Player just type

# yum install vlc

————————————————————————————–

Following is the result of successful installation of ntfs module.

# yum install -y fuse fuse-ntfs-3g

———————————————————————————

To install nagios

# yum install nagios nagios-plugins nagios-plugins-nrpe nagios-devel

# chkconfig nagios on

nagios -v /etc/nagios/nagios.cfg

Things look okay – No serious problems were detected during the pre-flight check

Configure Apache for Nagios : Add User :

# htpasswd -c /etc/nagios/htpasswd.users nagios
New password:
Re-type new password:
Adding password for user nagios

Restart Apache to make new settings effective.

# /etc/init.d/httpd restart

Restart nagios service

# service nagios restart
Configuration validation failed                            [FAILED]

As shown above If nagios service failed to start. you should disable selinux and restart machine to activate changes :

# vi /etc/selinux/config
SELINUX=disabled

On restart nagios should start successfully.

Open the browser like Mozilla and type :

http://localhost/nagios/
username : nagios
password :

you will have following error :

To overcome above error Configure Apache for Nagios : Add User :nagiosadmin

# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

This will add user nagiosadmin

# vim /etc/nagios/cgi.cfg

# AUTHENTICATION USAGE
use_authentication=1
# SYSTEM/PROCESS INFORMATION ACCESS
authorized_for_system_information=nagiosadmin
CONFIGURATION INFORMATION ACCESS
authorized_for_configuration_information=nagiosadmin
# SYSTEM/PROCESS COMMAND ACCESS
authorized_for_system_commands=nagiosadmin
# GLOBAL HOST/SERVICE VIEW ACCESS
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
# GLOBAL HOST/SERVICE COMMAND ACCESS
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin

Once again open the browser like Mozilla and type :

http://localhost/nagios/

username : nagiosadmin
password :

Nagios Configuration files/directories :

# ls /etc/nagios/
cgi.cfg              htpasswd.users       objects/
command-plugins.cfg  nagios.cfg           resource.cfg

# ls /etc/nagios/objects/
commands.cfg     localhost.cfg    switch.cfg       timeperiods.cfg
contacts.cfg     printer.cfg      templates.cfg    windows.cfg

————————————————————————–

Client Configuration

    Linux client configuraiton

# /usr/sbin/useradd nagios
# passwd nagios
# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.14.tar.gz
# tar -xzf nagios-plugins-1.4.14.tar.gz
# cd nagios-plugins-1.4.14
# ./configure –with-nagios-user=nagios –with-nagios-group=nagios
# make
# make install

# chown nagios.nagios /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios/libexec

# yum install xinetd
# yum install libssl-dev

# wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz/download

# tar xvzf nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure

# make all
# make install-plugin
# make install-daemon

# vi /etc/xinetd.d/nrpe
Should Look Like:
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg –inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 [NAGIOS SERVER ADDRESS]
}

# vi /etc/services
add:
nrpe 5666/tcp # NRPE

# service xinetd restart
# netstat -at | grep nrpe
tcp 0 0 *:nrpe *:* LISTEN

# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12

# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
USERS WARNING – 6 users currently logged in |users=6;5;10;0

# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs
PROCS WARNING: 178 processes

# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
OK – load average: 0.15, 0.24, 0.25|load1=0.150;15.000;30.000;0; load5=0.240;10.
000;25.000;0; load15=0.250;5.000;20.000;0;

# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_hda1
DISK OK – free space: /boot 81 MB (87% inode=99%);| /boot=11MB;78;88;0;98

If this worked correctly its time to setup your Nagios server to monitor your remote host, so ssh once againg into your Nagios server.
Now we are going to add separate host file i.e linux.cfg for the new host so we need to edit the nano “nagios.cfg” file:

# vi /etc/nagios/nagios.cfg
And Add following line

cfg_file=/etc/nagios/objects/linux.cfg

# vi /etc/nagios/objects/linux.cfg

##################################################
##################################################
# HOST DEFINITIONS
##################################################
##################################################

# Define a host for the Windows machine we’ll be monitoring
# Change the host_name, alias, and address to fit your situation

define host{
use linux-server ; Inherit default values from a template
host_name remotelinux ; The name we’re giving to this host
alias My Linux Server ; A longer name associated with the host
address 192.168.19.146 ; IP address of the host
}

##################################################
# HOST GROUP DEFINITIONS
##################################################

# Define a hostgroup for Windows machines
# All hosts that use the windows-server template will automatically be a member of this group

define hostgroup{
hostgroup_name linux clients ; The name of the hostgroup
alias linux ; Long name of the group
members remotelinux
}

##################################################
# SERVICE DEFINITIONS
##################################################

# Create a service for monitoring the version of NSCLient++ that is installed
# Change the host_name to match the name of the host you defined above

define service{
use generic-service
host_name remotelinux
service_description Ping
check_command check_ping!100.0,20%!500.0,60%
}

# Create a service for monitoring the uptime of the server
# Change the host_name to match the name of the host you defined above

define service{
use generic-service
host_name remotelinux
service_description Users
check_command check_nrpe!check_users
}

# Create a service for monitoring CPU load
# Change the host_name to match the name of the host you defined above

define service{
use generic-service
host_name remotelinux
service_description CPU Load
check_command check_nrpe!check_load
}

# Create a service for monitoring memory usage
# Change the host_name to match the name of the host you defined above

define service{
use generic-service
host_name remotelinux
service_description HDD Status
check_command check_nrpe!check_total_procs
}

define service{
use generic-service
host_name remotelinux
service_description CPU Load
check_command check_nrpe!check_hda1
}

# service nagios restart
Stopping nagios: [ OK ]
Starting nagios: [ OK ]
# /usr/bin/nagios -v /etc/nagios/nagios.cfg

———————————————————————————

    Windows client configuration

Download 64bit NSClient from :

http://sourceforge.net/projects/nscplus/files/nscplus/NSClient%2B%2B%200.3.8/NSClient%2B%2B-0.3.8-x64.msi/download

Download 32bit NSClient from :

http://sourceforge.net/projects/nscplus/files/nscplus/NSClient%2B%2B%200.3.8/NSClient%2B%2B-0.3.8-Win32.zip/download

Edit file C:\Program Files\NSClient++\nsc.ini
This file is divided in sections placed in brackets.

1. First go to [modules] section and uncheck the modules you want to monitor.
The FileLogger.dll logs the activities of the NSClient++.
CheckDisk.dll checks the file size and hard disk use.
The CheckSystem.dll will check for memory, uptime, service stats and processes.
You will also need to uncomment the NSClientListener.dll and the NRPEListener.dll in order to communicate with Nagios.

2. Then go to [Settings] section. Under the ALLOWED HOSTS ADDRESSES section enter the local host and the machine you want to monitor.
These addresses should be separated by a comma.

[Settings]
;# ALLOWED HOST ADDRESSES
; This is a comma-delimited list of IP address of hosts that are allowed to talk to the all daemons.
; If leave this blank anyone can access the deamon remotly (NSClient still requires a valid password).
; The syntax is host or ip/mask so 192.168.0.0/24 will allow anyone on that subnet access
allowed_hosts=127.0.0.1/32,192.168.19.0/24

3. Now go to [NSClient] section. Under the ALLOWED HOSTS ADDRESSES section enter the IP Address of machine you want to monitor.

[NSClient]
;# ALLOWED HOST ADDRESSES
; This is a comma-delimited list of IP address of hosts that are allowed to talk to NSClient deamon.
; If you leave this blank the global version will be used instead.
; Enter the IP Address of Nagios Server
allowed_hosts=192.168.19.187/255.255.255.0

4. Finally, under [NRPE] set your port that NRPE will listen to.
[NRPE]
;# NRPE PORT NUMBER
; This is the port the NRPEListener.dll will listen to.
port=5666

Since, NSClient++ is configured according to our requirement.
Go to Start -> run -> services.msc -> look for NSClient++ and restart it.

Once all is set up and running ssh into nagios server and check your connection.
# /usr/lib/nagios/plugins/check_nrpe -H 192.168.19.52
I (0.3.8.75 2010-05-27) seem to be doing fine…

If you get any errors you will need to correct them, use the log for locating the errors.

Enable WARNING / CRITICAL status email notification

# vi /etc/nagios/objects/contacts.cfg
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user

email techmajha@gmail.com ; ***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

——————————————————–

Graphing in Nagios based on Historical Data

We will use PNP4Nagios for Graphs. PNP is an addon for the Nagios Network Monitoring System. PNP provides easy to use, easy to configure RRDTools based performance charts feeded by the performance data output of the Nagios Plugins.

Download PNP4Nagios software

# wget http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.7.tar.gz/download
# tar xvzf pnp4nagios-0.6.7.tar.gz
# cd pnp4nagios-0.6.7
# ./configure

*** Configuration summary for pnp4nagios-0.6.7 09-27-2010 ***

General Options:
————————- ——————-
Nagios user/group: nagios nagios
Install directory: /usr/local/pnp4nagios
HTML Dir: /usr/local/pnp4nagios/share
Config Dir: /usr/local/pnp4nagios/etc
Location of rrdtool binary: /usr/bin/rrdtool Version 1.4.4
RRDs Perl Modules: FOUND (Version 1.4004)
RRD Files stored in: /usr/local/pnp4nagios/var/perfdata
process_perfdata.pl Logfile: /usr/local/pnp4nagios/var/perfdata.log
Perfdata files (NPCD) stored in: /usr/local/pnp4nagios/var/spool

Web Interface Options: ————————- ——————-
HTML URL: http://localhost/pnp4nagios
Apache Config File: /etc/httpd/conf.d/pnp4nagios.conf

Review the options above for accuracy. If they look okay,
type ‘make all’ to compile.

# make all

*** Compile finished ***

make install
– This installs the main program and HTML files

Enjoy.

# make install

*** Main program, Scripts and HTML files installed ***

Please run ‘make install-webconf’ to install the
web configuration file

Please run ‘make install-config’ to install sample
configuration files

Please run ‘make install-init’ if you want to use
BULK Mode with NPCD

# make install-config

# make install-webconf

/usr/bin/install -c -m 644 httpd.conf /etc/httpd/conf.d/pnp4nagios.conf

*** Apache config file installed ***

Now open /etc/nagios/nagios.cfg and uncomment lines as listed below

# vi /etc/nagios/nagios.cfg

# PROCESS PERFORMANCE DATA OPTION
# This determines whether or not Nagios will process performance
# data returned from service and host checks. If this option is
# enabled, host performance data will be processed using the
# host_perfdata_command (defined below) and service performance
# data will be processed using the service_perfdata_command (also
# defined below). Read the HTML docs for more information on
# performance data.
# Values: 1 = process performance data, 0 = do not process performance data

process_performance_data=1

# HOST AND SERVICE PERFORMANCE DATA PROCESSING COMMANDS
# These commands are run after every host and service check is
# performed. These commands are executed only if the
# enable_performance_data option (above) is set to 1. The command
# argument is the short name of a command definition that you
# define in your host configuration file. Read the HTML docs for
# more information on performance data.

#host_perfdata_command=process-host-perfdata
#service_perfdata_command=process-service-perfdata

# HOST AND SERVICE PERFORMANCE DATA FILES
# These files are used to store host and service performance data.
# Performance data is only written to these files if the
# enable_performance_data option (above) is set to 1.

host_perfdata_file=/tmp/host-perfdata
service_perfdata_file=/tmp/service-perfdata

# HOST AND SERVICE PERFORMANCE DATA FILE TEMPLATES
# These options determine what data is written (and how) to the
# performance data files. The templates may contain macros, special
# characters (\t for tab, \r for carriage return, \n for newline)
# and plain text. A newline is automatically added after each write
# to the performance data file. Some examples of what you can do are
# shown below.

host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$

# HOST AND SERVICE PERFORMANCE DATA FILE MODES
# This option determines whether or not the host and service
# performance data files are opened in write (“w”) or append (“a”)
# mode. If you want to use named pipes, you should use the special
# pipe (“p”) mode which avoid blocking at startup, otherwise you will
# likely want the defult append (“a”) mode.

host_perfdata_file_mode=a
service_perfdata_file_mode=a

# HOST AND SERVICE PERFORMANCE DATA FILE PROCESSING INTERVAL
# These options determine how often (in seconds) the host and service
# performance data files are processed using the commands defined
# below. A value of 0 indicates the files should not be periodically
# processed.

host_perfdata_file_processing_interval=15
service_perfdata_file_processing_interval=15

# HOST AND SERVICE PERFORMANCE DATA FILE PROCESSING COMMANDS
# These commands are used to periodically process the host and
# service performance data files. The interval at which the
# processing occurs is determined by the options above.

host_perfdata_file_processing_command=process-host-perfdata-file
service_perfdata_file_processing_command=process-service-perfdata-file

At the end of /etc/nagios/objects/commands.cfg, add the command definitions 
define command{
command_name process-service-perfdata-file
command_line $USER1$/process_perfdata.pl –bulk=/usr/local/nagios/var/service-perfdata

}
define command{
command_name process-host-perfdata-file
command_line $USER1$/process_perfdata.pl –bulk=/usr/local/nagios/var/host-perfdata
}

Append following 2 entries to /etc/nagios/objects/templates.cfg :
define host {
name host-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$
}
define service {
name srv-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
}

These are templates that you add to each host and service definition for graphs in /etc/nagios/objects/windows.cfg and /etc/nagios/objects/linux.cfg files and any other client config file.:

# vi /etc/nagios/objects/windows.cfg
define host{
use windows-server,host-pnp ; Inherit default values from a template
host_name winserver ; The name we’re giving to this host
alias My Windows Server ; A longer name associated with the host
address 192.168.19.52 ; IP address of the host
}

# Create a service for monitoring the uptime of the server
# Change the host_name to match the name of the host you defined above

define service{
use generic-service,srv-pnp
host_name winserver
service_description Uptime
check_command check_nt!UPTIME
}

# Create a service for monitoring CPU load
# Change the host_name to match the name of the host you defined above

define service{
use generic-service,srv-pnp
host_name winserver
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}

Restart Nagios

# service nagios restart

Possibly Related Posts:

  • Printer Drivers for linux
  • OCS Inventory NG and GLPI
  • Wifi: Wireless card drivers of Dell vostro laptops for Centos
  • google chrome on centos
  • How to setup pptpconfig (VPN client tunnel)