Nagios monitoring Setup and configuration detailed steps
Reference text: http://blog.chinaunix.net/uid-26999549-id-4031729.html
Reference text: https://www.centos.bz/2012/02/centos-install-nagios/
(i) Install Nagios (Nagios server is: 192.168.6.6 nagios client is: 192.168.2.33)
1. Basic Support Kit: GCC glibc glibc-common gd gd-devel xinetd openssl-devel httpd php
Note: Both PHP and httpd are installed using the source package, installation configuration method is not detailed here
Yum install-y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
2. Create Nagios accounts and groups
Useradd-m Nagios
Groupadd Nagios
Usermod-a-G Nagios Nagios
3. Compile and install
Tar xvf nagios-4.0.7.tar.gz
CD nagios-4.0.7
./configure Prefix=/usr/local/nagios--with-nagios-user=nagios--with-nagios-group=nagios
Make all
Make install
Make Install-init (Generate init startup script)
Make install-config (Generate some template profiles)
Make Install-commandmode (set appropriate permissions)
Make install-webconf (if the httpd is installed through Yum, the Apache configuration file conf.d/nagios.conf) is automatically generated
4. Set the Web authentication password for Nagios
/usr/local/apache/bin/htpasswd-c/usr/local/nagios/etc/htpasswd.user Nagiosadmin
It is best to use nagiosadmin, and if defined as another user, there is a problem modifying the service alert option through the Web interface
5. Set up the Nagios boot
Chkconfig--add Nagios
Chkconfig Nagios on
6. Install the Nagios plugin Nagios-plugin
Tar zxvf nagios-plugins-2.0.tar.gz
CD nagios-plugins-2.0.tar.gz
./configure--prefix=/usr/local/nagios--with-nagios-user=nagios--with-nagios-group=nagios
--with-apt-get-command--with-ping6-command--with-ping-command--with-mysql
--with-gnutls--enable-extra-opts
Make&&make Install
7. Complete the initial installation at this time, you can monitor and view some of the services of the machine, detect the configuration file and start Nagios
/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg
Nagios Core 4.0.7
Copyright (c) 2009-2011 Nagios Core Development team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last modified:08-30-2013
License:gpl
website:http://www.nagios.org
Reading Configuration data ...
Read main config file okay ...
Processing object config file '/usr/local/nagios/etc/objects/commands.cfg ' ...
Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg ' ...
Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg ' ...
Processing object config file '/usr/local/nagios/etc/objects/templates.cfg ' ...
Processing Object Config directory '/usr/local/nagios/etc/servers ' ...
Processing object config file '/usr/local/nagios/etc/servers/localhost.cfg ' ...
Read object config files okay ...
Running pre-flight check on configuration data ...
Checking Services ...
Checked 6 Services.
Checking hosts ...
Checked 1 hosts.
Checking host groups ...
Checked 0 host groups.
Checking Service groups ...
Checked 0 service groups.
Checking contacts ...
Checked 1 Contacts.
Checking Contact Groups ...
Checked 1 Contact groups.
Checking Service escalations ...
Checked 0 Service Escalations.
Checking Service Dependencies ...
Checked 0 service dependencies.
Checking Host escalations ...
Checked 0 Host Escalations.
Checking Host Dependencies ...
Checked 0 host dependencies.
Checking commands ...
Checked commands.
Checking time Periods ...
Checked 5 time periods.
Checking for circular paths between hosts ...
Checking for circular host and service dependencies ...
Checking Global Event Handlers ...
Checking Obsessive Compulsive Processor commands ...
Checking Misc Settings ...
Total warnings:0
Total errors:0
Things look okay-no serious problems were detected during the pre-flight check
Appears here, indicating that there are no errors in the configuration file, you can start Nagios and Apache
Service Nagios Start
/usr/local/apache/sbin/apchectl
Visit Nagios
http://192.168.6.6/nagios/
The prompt page is inaccessible because Apache is a source pack installation, and the default path and RPM package are different, and you need to add the specified access path to the Apache httpd.conf configuration file
8. Configure Apache and load the Nagios login page
Find Apache configuration file/usr/local/apache/conf/httpd.conf
Found it:
User Daemon
Group Daemon Revision changed to
User Nagios
Group Nagios
or Usermod-a-G Nagios Apache
For security reasons, it is generally necessary to have the Nagios Web monitoring page authorized for access, which requires an increase in the authentication configuration, where the following information is added at the end of the httpd.conf file:
The following information is generated when compiling Nagios (make install-webconf), and the configuration information is in:/etc/httpd/confd.d/nagios.conf file
setting for 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.user
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.user
Require Valid-user
</Directory>
9. Restart Nagios, Apache and visit Nagios
Service Nagios Restart
/usr/local/apache/bin/apachectl restart
Http://192.168.6.6/nagions
Prompt to enter username password, access successful
But after landing in, Nagios page to the right of all garbled
Workaround:
The main reason is that Apache didn't open the CGI script.
Go to Apache's main configuration file httpd.conf
Vim/usr/local/apache/conf/httpd.conf
LoadModule Cgid_module modules/mod_cgid.so
LoadModule Actions_module modules/mod_actions.so
Remove the top 2 lines, restart Apache, OK
Visit again, garbled disappear OK.
(ii) configuration Nagios
1.nagios Configuration directory information
cd/usr/local/nagios/etc/
Ls
Cgi.cfg Htpasswd.user nagios.cfg Objects Resource.cfg
[Root@localhost etc] ll
Total 68
-rw-rw-r--1 nagios nagios 11669 Nov 14:18 (CGI configuration file)
-rw-r--r--1 root Nov 14:20 htpasswd.user (Apache authentication password file)
-rw-rw-r--1 nagios nagios 44710 Nov 14:18 (main configuration file)
Drwxrwxr-x 2 Nagios nagios 4096 Nov 14:18 (object definition file directory)
-RW-RW----1 Nagios nagios 1340 Nov 14:18 (Resource configuration file)
2. Modify the nagios.cfg main configuration file
Vim Nagios.cfg
Comment out: cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
Cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
Remove the Cfg_dir=/usr/local/nagios/etc/servers (note)-----cfg_dir=/usr/local/nagios/etc/servers
Create a new servers subdirectory in the/usr/local/nagios/etc/directory, where you can add a host configuration file directly
mkdir servers
3. Configure the configuration file in the object directory
CD objects/
ll
Total 48
-rw-rw-r--1 nagios nagios 7716 Nov 14:18 (command definition file)
-rw-rw-r--1 nagios nagios 2166 Nov 14:18 (Contact information definition file)
-rw-rw-r--1 nagios nagios 5403 Nov 14:18
-rw-rw-r--1 nagios nagios 3124 Nov 14:18
-rw-rw-r--1 nagios nagios 3293 Nov 14:18
-rw-rw-r--1 nagios nagios 10812 Nov 14:18
-rw-rw-r--1 nagios nagios 3208 Nov 14:18 (time cycle definition file)
-rw-rw-r--1 nagios nagios 4019 Nov 14:18
Configure contact information (Mail Recipient email address)
Contact Definition:
Vim Contacts.cfg
The email field behind the Nagios@localhost into their own mailbox, the alarm message sent this mailbox, such as 15566058@139.com
If you are setting up a reminder multiple mailboxes can be separated by commas, such as: 15566058@139.com,abc@163.com, followed by other email addresses.
Save, exit.
(iii) Nrpe installation configuration
1. Install Nrpe
Tar zxvf nrpe-2.15.tar.gz
CD nrpe-2.15
./configure && Make all
Make Install-plugin
Make Install-daemon
Make Install-daemon-config
Then run into xinetd a child service
Make install-xinetd
If you cannot install XINETD, you can start Nrpe into 1 daemon servers
/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg-d
In this case to Vim/usr/local/nagios/etc/nrpe.cfg
Add allow_host = 127.0.0.1,10.144.180.32,223.27.162.39,223.27.162.27
2. Configure Nrpe
Vim/etc/xinetd.d/nrpe
Add 192.168.6.6 after only_from=127.0.0.1 to separate spaces
3. Add Port
Vim/etc/services at the end of the add
Nrpe 5666/tcp Nrpe
Modify the configuration file/usr/local/nagios/etc/objects/commands.cfg add support for Nrpe
Vim/usr/local/nagios/etc/objects/commands.cfg Add the following at the end
Define Command{
Command_name Check_nrpe
Command_line/usr/local/nagios/libexec/check_nrpe-h $HOSTADDRESS $-C $ARG 1$
}
4. Configure/USR/LOCAL/NAGIOS/ETC/NRPE.CFG Files
Cd/usr/local/nagios/etc/nrpe.cfg
Vim Nrpe.cfg
Replace hda1 in Command[check_hda1]=/usr/local/nagios/libexec/check_disk-w 20%-C 10%-p/dev/hda1 with the following: SDA:
Command[check_sda]=/usr/local/nagios/libexec/check_disk-w 20%-C 10%-P/DEV/SDA
Replace Command[check_total_procs]=/usr/local/nagios/libexec/check_procs-w 150-c 200 with the following:
Command[check_total_procs]=/usr/local/nagios/libexec/check_procs-w 400-c 450
Add Command[check_swap]=/usr/local/nagios/libexec/check_swap-w 90%-C 80%
Save, exit.
Restart the XINETD service
Ok,nagios Service-side installation successful ...
(iv) Nagios client (monitored segment) installation configuration
Yum Install-y OpenSSL Openssl-devel
Useradd-s/sbin/nlogin Nagios
2. Install Nagios-plugin
Cd/opt/software/
Tar zxvf nagios-plugins-2.0.tar.gz
CD nagios-plugin-2.0
./configure--prefix=/usr/local/nagios--with-nagios-user=nagios--with-nagios-group=nagios--enable-libtap
--enable-redhat-pthread-workaround--with-apt-get-command--with-ping6-command--with-ping-command
--with-mysql--with-gnutls--enable-extra-opts--with-openssl--with-trusted-path
Make&&make Install
3. Installation Configuration Nrpe
Yum Install Xinetd-y
Tar zxvf nrpe-2.15.tar.gz
CD nrpe-2.15
./configure && Make all
Make Install-plugin
Make Install-daemon
Make Install-daemon-config
Make install-xinetd
Vim/etc/xinetd.d/nrpe
Add the Nagios server-side IP address after only_from = 127.0.0.1 192.168.6.6 as follows:
Only_from = 127.0.0.1 192.168.6.6
Vim/etc/services
Add Nrpe 5666/tcp to the end of the file Nrpe
Modify/usr/local/nagios/etc/nrpe.cfg
Cp-p/usr/local/nagios/etc/nrpe.cfg/usr/local/nagios/etc/nrpe.cfg.default-Back up the profile before you modify it
Vim/usr/local/nagios/etc/nrpe.cfg
Modify all hda1 characters in the Nrpe.cfg file to SDA
or use the SED command to bulk modify, as follows:
Sed-i ' s/hda1/sda/g '/usr/local/nagios/etc/nrpe.cfg
Add SWEP partition Monitor: Command[check_swap]=/usr/local/nagios/libexec/check_swap-w 90%-C 80%
Save, exit.
Restart the XINETD service:
Service xinetd Restart
(v) add edit monitored host configuration file in Server/usr/local/nagios/etc/nggios
Vi/usr/local/nagios/nagios.cfg
Add Reference host.cfg File
You can define a host in/usr/local/nagios/etc/objects/host.cfg
Define Host{
Use Linux-server
HOST_NAME Nagios-linux
Alias Nagios-linux
Address 10.144.176.64
}
You can add a service definition to a specific machine in/usr/local/nagios/etc/objects/services.cfg
Define Service{
Use Generic-service
HOST_NAME Server1
Service_description Check Main Disk Partition/home
Check_command Check_nrpe!check_disk_home
Normal_check_interval 1
Notification_interval 1
}
Define Service{
Use Generic-service
HOST_NAME Server1
Service_description Check HTTP Service Status
Check_command check_nrpe!check_http
Normal_check_interval 1
Notification_interval 1
}
3. Monitor the server to monitor the running port
(1) Nagios Client Configuration
Vim/usr/local/nagios/etc/nrpe.cfg the end of the file to add the definition port information as follows:
Command[check_templateupload:8080]=/usr/local/nagios/libexec/check_tcp-h localhost-p 8080-w 120-c 180
Save, exit
Restart the XINETD service
Service xinetd Restart
(2) Nagios service-side configuration
Add the following at the end of the Vim/usr/local/nagios/etc/services/192.168.2.33.cfg file
Define Service {
HOST_NAME 192.168.2.33-test
Service_description check_templateupload:8080
Check_period 24x7
Max_check_attempts 4
Normal_check_interval 1
Retry_check_interval 1
Contact_groups Admins
Notification_interval 10
Notification_period 24x7
Notification_options W,u,c,r
Check_command check_nrpe!check_templateupload:8080
}
Save, exit
Restart the Nagios service
Service Nagios Restart
Access to Nagios Services
Http://192.168.6.6/nagios
Done.....