Example of installing nagios monitoring software in CentOS 6.5

Source: Internet
Author: User
Tags centos
The latest stable version is installed here:
Nagios-4.0.8
Nagios-plugins-2.0.3
 
The installation is as follows:
Preparations before installation
To use the root user to operate the server, the following software environments are required:
Apache
PHP
DCC compiler
GD development Library
You can use yum for installation:
Yum install httpd php
Yum install gcc glibc-common
Yum install gd-devel
 
  1. Create users and user groups
Useradd-m nagios
Passwd nagios
 
 
Create a new NagcmdGroup for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.
/Usr/sbin/groupadd nagcmd/usr/sbin/usermod-a-G nagcmd nagios/usr/sbin/usermod-a-G nagcmd apache
 
2. Download the Nagios and Nagios plug-ins
Create a folder/software and put the downloaded file under the/software Directory
Download: http://www.nagios.org/download

 

 

3. Compile and install nagios
# Cd/software
# Tar-zxvf nagios-4.0.8.tar.gz
# Cd nagios-4.0.8
Run the Nagios configure script, passing the name of the group you created earlier like so:
./Configure -- with-command-group = nagcmd
Compile the Nagios source code.
Make all
Install binaries, init script, sample config files and set permissions on the external command directory.
Make installmake install-initmake install-configmake install-commandmode
Don't start Nagios yet-there's still more that needs to be done...
 
4. Customize Configuration
Sample configuration files have now been installed in /Usr/local/nagios/etcDirectory. These sample files shocould work fine for getting started with Nagios. You'll need to make just one change before you proceed...
Edit /Usr/local/nagios/etc/objects/contacts. cfgConfig file with your favorite editor and change the email address associated with NagiosadminContact definition to the address you 'd like to use for processing alerts.
Vi/usr/local/nagios/etc/objects/contacts. cfg
 
5. Configure the Web Interface
 
Install the Nagios web config file in the Apache conf. d directory.
Make install-webconf
Create NagiosadminAccount for logging into the Nagios web interface. Remember the password you assign to this account-you'll need it later.
Htpasswd-c/usr/local/nagios/etc/htpasswd. users nagiosadmin // Here I set the password to 123456
Restart Apache to make the new settings take effect.
Service httpd restart
Note: Consider implementing the ehanced CGI security measures described here to ensure that your web authentication credentials are not compromised.

6. Install the nagios plugin
Cd/software
Tar-zxvf nagios-plugins-2.0.3.tar.gz
Cd nagios-plugins-2.0.3
./Configure -- with-nagios-user = nagios -- with-nagios-group = nagios
Make
Make install
 
7. Start nagios
Add nagios to startup
Chkconfig -- add nagios
Chkconfig nagios on
 
Verify whether the nagios configuration file is correct:
/Usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios. cfg
 
If no error occurs, enable nagios:
Service nagios start
 
8. Disable selinux
Vim/etc/selinux/config
Change SELINUX = enforcing to SELINUX = disabled
After modification, the system must be restarted to take effect.
Temporary effect:
# Setenforce 0
 
9. Log on to the browser
The username is nagiosadmin and the password is 123456
Http: // localhost/nagios/
 
Here, port 80 is changed to port 800 by default, as shown in the figure below:
 
Projects of the current local machine monitored by default:
 
10. nagios configuration file description
After nagios is installed, the main directory is/usr/local/nagios. All configuration files are in the/usr/local/nagios/etc directory:
Cgi. cfg
Htpasswd. users // used for web login verification.
Nagios. cfg // Main configuration file of nagios. If you are monitoring other hosts, you need to add configuration files for other hosts.
Resource. cfg // defines the location of the nagios plug-in
 
The objects directory is also a very important Directory. Most operations are performed here. Its default files include:
Commands. cfg // command definition file, where commands can be referenced by other configuration files
Contacts. cfg // file that defines contacts and contact groups
Localhost. cfg // monitor local files
Printer. cfg // template file for printer monitoring, disabled by default
Switch. cfg // template file for monitoring vro, which is not enabled by default
Templates. cfg // defines the template configuration file for the host and service, which can be referenced in other configuration files
Timeperiods. cfg // defines the configuration file of the nagios monitoring period
Windows. cfg // the configuration file for monitoring windows hosts. It is not enabled by default.
 
Monitor local machine:
Add local monitoring to/usr/local/nagios/etc/nagios. cfg, which has been added by default:
Export _file =/usr/local/nagios/etc/objects/localhost. cfg
 
By default, the local configuration file monitors eight services: Current load, Current Users, HTTP, PING, Root Partition, SSH, Swap Usage, and Total Processes.
Add a monitoring rule for local/data partitions:
Vim localhost. cfg
Add
Define service {
Use local-service
Host_name localhost
Service_description Data Partition
Check_command check_local_disk! 20%! 10%! /Data
Notifications_enabled 1
        }
 
Save and restart the nagios service. Log on to the web.
 
 
Settings for sending emails to Nagios:
Download sendmail http://caspian.dotconf.net/menu/Software/SendEmail/

 

Cd/usr/local/
Tar-zxvf sendEmail-v1.56.tar.gz
Copy the executable cp sendEmail-v1.56/sendEmail/usr/local/bin/
Sending test:
# SendEmail-f nagios@domain.com-t 7344506@qq.com-s mail.domain.com-u "This is subject"-xu nagios-xp passpwd-m This is content.
Explanation:
-F indicates the sender's email address.
-T indicates the recipient's email address.
-S indicates the domain name or ip address of the SMTP server
-U indicates the subject of the email.
-Xu indicates the SMTP authentication User name
-Xp indicates the password for SMTP verification. (Note that this password seems to be restricted. For example, I use d! 5neyland cannot be correctly identified)
-M indicates the Mail content

Modify commands. cfg
Vim/usr/local/nagios/etc/objects/commands. cfg
# 'Policy-host-by-email 'command definition
Define command {
Command_name sort Y-host-by-email
Command_line/usr/bin/printf "% B" "****** Nagios ***** \ n \ nNotification Type: $ icationicationtype $ \ nHost: $ HOSTNAME $ \ nState: $ HOSTSTATE $ \ nAddress: $ HOSTADDRESS $
\ NInfo: $ HOSTOUTPUT $ \ n \ nDate/Time: $ LONGDATETIME $ \ n "| sendEmail-f nagios@domain.com-t $ CONTACTEMAIL $-s mail.domain.com-u" ** $ icationicationtype $ Host Alert: $ HOSTNAM
E $ is $ HOSTSTATE $ ** "$ CONTACTEMAIL $-xu nagios-xp password
        }

# 'Your Y-service-by-email 'command definition
Define command {
Command_name sort Y-service-by-email
Command_line/usr/bin/printf "% B" "****** Nagios ***** \ n \ nNotification Type: $ icationicationtype $ \ n \ nService: $ SERVICEDESC $ \ nHost: $ HOSTALIAS $ \ nAddress: $ HOSTA
DDRESS $ \ nState: $ SERVICESTATE $ \ n \ nDate/Time: $ LONGDATETIME $ \ n \ nAdditional Info: \ n $ SERVICEOUTPUT $ \ n "| sendEmail-f nagios@domain.com-t $ CONTACTEMAIL $-s mail.domain.com-u" ** $ Reply IC
ATIONTYPE $ Service Alert: $ HOSTALIAS $/$ SERVICEDESC $ is $ SERVICESTATE $ ** "$ CONTACTEMAIL $-xu nagios-xp password
        }

Save and restart the nagios service.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.