Contents
1. Install nagios server... 2
1. Install nagios... 2
2. Install the nagios plug-in... 3
3. Install the nrpe plug-in... 3
2. Run nagios. 3
3. Add a monitoring host... 4
1. windows host... 4
2. linux host... 6
4. Use plug-ins... 10
5. Custom notification alert... 10
1. nagios Server Installation 1. nagios Installation
1. Create a user nagios
/Usr/sbin/useradd nagios
2. Download nagios4.0.4
Http://jaist.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.4/nagios-4.0.4.tar.gz
3. Extract
Tar -zxfnagios-4.0.4.tar.gz
4. Enter the nagios-4.0.4 directory for sequential execution.
./Configure
Make all # compile the main program and CGIs
Make install # this INSTALLThe main program CGIs, and HTML files
Make install-init # this INSTALLThe initscript in/etc/rc. d/init. d
Make install-commandmode # this installand configures permissions onthe directory for holding the external command file
Make install-config # this installsample config files in/usr/local/nagios/etc/
You'll have to modify these sample files before you can usenagios,
The configuration file is installed in/usr/local/nagios/etc by default.
To configure Nagios for normal operation, you only need to make a simple modification...
Use the editor software you are good at to edit this
/Usr/local/nagios/etc/objects/contacts. cfg configuration file, change the email address
The e-mail information in the contact definition information of nagiosadmin is your EMail information to receive the alarm
.
Vi/usr/local/nagios/etc/objects/contacts. cfg
# Configure web interfaces
Make install-webconf # this INSTALLThe Apache configfile for the Nagios web interface
Create the following command to create a nagiosadmin user for logging on to Nagios web interface.
Htpasswd-c/usr/local/nagios/etc/htpasswd. usersnagiosadmin
Restart apache to make the service take effect.
Service httpd restart
Make install-exfoliation # this INSTALLThe exfoliation theme for the Nagios webinterface
Make install-classicui # this INSTALLThe classictheme for the Nagios web interface
2. Install the nagios plugin
Compile and install the plug-in
./Configure -- with-nagios-user = nagios -- with-nagios-group = nagios
Make
Makeinstall
3. Install the nrpe plug-in
The following is a detailed description of linux host monitoring.
After nrpe is installed, You need to configure
Add the NRPE command to the objects/command. cfg command definition file.
[Root @ KCentOS5C ~] # Vi/usr/local/nagios/etc/commands. cfg
-------------------------------------------------------
# NRPE Command
Add the nrpe function command.
Define command (
Command_name nrpe
Command_line $ USER1 $/check_nrpe-H $ HOSTADDRESS $-c $ ARG1 $
}
2. Run nagios
Add Nagios to the service list to enable it automatically when the system starts.
Chkconfig -- add nagios
Chkconfig nagios on
Verify the configuration file of Nagios. If no error is reported, you can start Nagios
/Usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios. cfg
1. Initialization Script: the simplest way to start the nagios daemon is to use the initialization script,
/Etc/rc. d/init. d/nagios start
2. manually, you can receive and start the Nagios daemon, and use the command parameter-d
/Usr/local/nagios/bin/nagios-d/usr/local/nagios/etc/nagios. cfg
3. Use service
Service nagios start
3. Add monitoring HOST 1. windows Host
Install NSClient ++
During installation, you only need to modify the address of the nagios server. Do not enter the password.
Other steps,
2. Open the windows. cfg file in editing mode.
Vi/usr/local/nagios/etc/objects/windows. cfg (this is configured on the nagios server host)
You can modify the object definition in the windows. cfg file. Modify host_name,
The alias and address domains match the added Windows machine.
Define host
Define host {
Use windows-server; Inherit default valuesfrom
Windows server template (make sure you keep this line !)
Host_name winserver
Alias My Windows Server
Address 192.168.1.2 # windows Host address.
}
Define Service
Define service {
Use generic-service
Host_name 192.168.120.152
Service_description NSClient ++ Version
Check_command check_nt! CLIENTVERSION
}
# Create a service for monitoring theuptime of the server
# Change the host_name to match the name ofthe host you defined abve
Define service {
Use generic-service
Host_name 192.168.120.152
Service_description Uptime
Check_command check_nt! UPTIME
}
# Create a service for monitoring CPU load
# Change the host_name to match the name ofthe host you defined abve
Define service {
Use generic-service
Host_name 192.168.120.152
Service_description CPU Load
Check_command check_nt! CPULOAD! -L 5, 80, 90
}
# Create a service for monitoring memoryusage
# Change the host_name to match the name ofthe host you defined abve
Define service {
Use generic-service
Host_name 192.168.120.152
Service_description MemoryUsage
Check_command check_nt! MEMUSE! -W 80-c 90
}
# Create a service for monitoring C: \ diskusage
# Change the host_name to match the name ofthe host you defined abve
Define service {
Use generic-service
Host_name 192.168.120.152
Service_description C: \ DriveSpace
Check_command check_nt! USEDDISKSPACE! -L c-w 80-c 90
}
# Create a service for monitoring the W3SVCservice
# Change the host_name to match the name ofthe host you defined abve
Define service {
Use generic-service
Host_name 192.168.120.152
Service_description W3SVC
Check_command check_nt! SERVICESTATE! -DSHOWALL-l W3SVC
}
# Create a service for monitoring thepolicer.exe process
# Change the host_name to match the name ofthe host you defined abve
Define service {
Use generic-service
Host_name 192.168.120.152
Service_description Explorer
Check_command check_nt! PROCSTATE! -D SHOWALL-l assumer.exe
}
After modification, add windows. cfg to nagios. cfg.
Export _file =/usr/local/nagios/etc/objects/windows. cfg
2. linux host
Install the nagios plug-in and nrpe on the monitored host
1. Add a Nagio user
[Root @ KCentOS5A ~] # Useradd nagios
2. decompress the Nagios-plugins package
[Root @ KCentOS5A ~] # Tar-zxvf nagios-plugins-1.4.10.tar.gz 4. Go to the Nagios-plugins plug-in package directory
[Root @ KCentOS5A ~] # Cd nagios-plugins-1.4.10
5. Pre-configure the Nagios-plugins installation path
[Root@KCentOS5Anagios-plugins-1.4.10] #./configure -- prefix =/usr/local/nagios
6. After the pre-configuration is complete, information is fed back and Makefile is generated.
-------------------------------------------------------
Config. status: creating po/Makefile
-- With-apt-get-command:
-- With-ping6-command:/bin/ping6-n-U-w % d-c % d % s
-- With-ping-command:/bin/ping-n-U-w % d-c % d % s
With-ipv6: yes
-- With-mysql: no
-- With-openssl: yes
-- With-gnutls: no
-- With-perl:/usr/bin/perl
-- Enable-perl-modules: no
-- With-cgiurl:/nagios/cgi-bin
-- With-trusted-path:/bin:/sbin:/usr/bin:/usr/sbin
-------------------------------------------------------
7. Compile the Nagios-plugins plug-in program
# Make
8. Install the Nagios-plugins plug-in program
[Root@KCentOS5Anagios-plugins-1.4.10] # make install
9. Check the Nagios-plugins plug-in installation.
[Root@KCentOS5Anagios-plugins-1.4.10] # ll/usr/local/nagios/
Total 8
Drwxr-xr-x2 root 4096 Oct 7 0libexec
Drwxr-xr-x3 root 4096 Oct 7 share
10. recursively change the owner of the Nagios main path
[Root @ KCentOS5A ~] # Chown-R nagios. nagios/usr/local/nagios/
11. Check attributes of the main path of Nagios
[Root @ KCentOS5A ~] # Ll/usr/local/| grep nagios
Drwxr-xr-x4 nagios 4096 Oct 7 nagios
[Root @ KCentOS5A ~] # Ll/usr/local/nagios/
Total 8
Drwxr-xr-x2 nagios 4096 Oct 7 libexec
Drwxr-xr-x3 nagios 4096 Oct 7 share
4. Install the NRPE extension program on the monitored Host:
1. decompress the NRPE compressed package
[Root @ KCentOS5A ~] # Tar-zxvf nrpe-2.9.tar.gz
2. Go to the NRPE package directory
[Root @ KCentOS5A ~] # Cd nrpe-2.9
3. Pre-configure the NRPE Installer
[Root@KCentOS5Anrpe-2.9] #./configure
4. After the pre-configuration is complete, a prompt message and a Makefile are displayed.
-------------------------------------------------------
Configure: creating./config. status
Config. status: creating Makefile
Config. status: creating src/Makefile
Config. status: creating subst
Config. status: creating include/config. h
* ** Configuration summary for nrpe 2.9 08-13-2007 ***:
GeneralOptions:
-------------------------
NRPEport: 5666
NRPEuser: nagios
NRPEgroup: nagios
Nagiosuser: nagios
Nagiosgroup: nagios
Reviewthe options abve for accuracy. If they look okay,
Type 'make all' to compile the NRPE daemon and client.
Finally, the system prompts you to continue using the "make all" command to compile the NRPE daemon and client programs.
-------------------------------------------------------
5. Compile the NRPE Program
[Root@KCentOS5Anrpe-2.9] # make all
6. After compilation is successful, a prompt will be reported.
-------------------------------------------------------
* ** Compile finished ***
If thenali daemon and client compiled without any errors, you
Cancontinue with the installation or upgrade process.
Read thePDF documentation (nrpeation) for information on the next
Steps youshocould take to complete the installation or upgrade.
There is a nrpe.pdf manual in the nrpe package. Next, you can refer to the Manual for subsequent operations.
-------------------------------------------------------
Install the NRPE plug-in, daemon, and template daemon configuration files.
Installthe NRPE plugin (for testing), daemon, and sample daemon config file.
7. Install the NRPE plug-in program
[Root@KCentOS5Anrpe-2.9] # make install-plugin
8. Install the NRPE daemon
[Root@KCentOS5Anrpe-2.9] # make install-daemon
9. Install the NRPE Daemon Configuration File
[Root@KCentOS5Anrpe-2.9] # make install-daemon-config
10. Check the installation of the NRPE Program
[Root@KCentOS5Anrpe-2.9] # ll/usr/local/nagios/
-------------------------------------------------------
Total 16
Drwxrwxr-x2 nagios 4096 Oct 7 bin
Drwxrwxr-x2 nagios 4096 Oct 7 etc
Drwxr-xr-x2 nagios 4096 Oct 7 libexec
Drwxr-xr-x 3 nagios 4096 Oct 7 share
Configure and run NRPE on the monitored Host:
1. Configure the main configuration file for NRPE
[Root @ KCentOS5A ~] # Vi/usr/local/nagios/etc/nrpe. cfg
Here are some key settings.
-------------------------------------------------------
Pid_file =/var/run/nrpe. pid
Set the PID file that NRPE runs, which is set by default and does not need to be changed.
Server_port = 5666
This is the system Port occupied by the NRPE daemon.
# Server_address = 0.0.0.0
Server_address = 192.168.1.9 # This is the IP address of the controlled end.
Sets the network interface for the system to listen to NRPE. Generally, a specific IP address is set. If you want multiple NICs, use commas (,) to separate multiple IP addresses. To listen to all network interfaces of the system, you can use "0.0.0.0" to indicate the special addresses of all network interfaces, but you cannot use the wildcard "*".
Nrpe_user = nagios
Nrpe_group = nagios
Set the host user of the NRPE.
Allowed_hosts = 192.168.1.12 # This is the IP address of the monitoring server.
Here is the IP address of the host that allows NRPE interaction with the local machine, that is, the address of the Nagios monitoring server. If you want to specify multiple Nagios servers, use a comma ", to separate multiple IP addresses.
Add the command to be monitored in nrpe. cfg:
Command [check_users] =/usr/local/nagios/libexec/check_users-w 5-c 10
Command [check_load] =/usr/local/nagios/libexec/check_load-w 15, 10, 5-c 30, 25, 20
Command [check_hda1] =/usr/local/nagios/libexec/check_disk-w 20%-c 10%-p/dev/hda1
Command [check_zombie_procs] =/usr/local/nagios/libexec/check_procs-w 5-c 10-s Z
Command [check_total_procs] =/usr/local/nagios/libexec/check_procs-w 150-c 200
Start the daemon nrpe Process
/Usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe. cfg-d
Add NRPE run to system startup script
[Root @ KCentOS5A ~] # Echo "/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe. cfg-d ">/etc/rc. d/rc. local
Add host information on the nagios server. Add the host to nagios. cfg.
Export _file =/usr/local/nagios/etc/objects/host160.cfg
Iv. Use plug-ins
Write the plug-in the directory/usr/local/nagios/libexec,
For example:
1. Put the check_cpu.sh file in the libexec directory.
Modify the execution permission.
2. Add the following command to the monitored Host:
Define service {
Host_name 153
Use generic-service
Check_command check_nrpe! Check_cpu_233
Service_description check_cpu_233
Notifications_enabled 1
Event_handler_enabled 1
Max_check_attempts 3
Check_interval 5
Retry_check_interval 2
Notification_options w, u, c
}
Add the following in nrpe. cfg:
Command [check_cpu_233] =/usr/local/nagios/libexec/check_cpu.sh-w 60-c 80
The check_cpu.sh file must be placed in each directory for inspection.
5. Custom notification alert
Specify the service, contacts, and notification methods.
To implement notification methods for specified contacts for a specified service,
Add the notification sending time to timeperiods. cfg.
Define timeperiod {
Timeperiod_name notify_at_8
Alias once_a_day
Sunday-
Monday-
Tuesday-
Wednesday-
Thursday-
Friday-
Saturday-
}
Define the contacts to be notified:
Define contact {
Contact_name policyadmin
Alias wu
Use generic-contact
Service_icationication_commands notify-service-by-qqemail # notification command
Email XXXX@163.com
}
We add services to the specified host.
Define service {
Host_name localhost
Use local-service
Service_descriptionpolicy_at_800
Contacts policyadmin # specify a contact
Check_command yy_at_800 # defines a service check command to trigger notification sending.
Check_period yy_at_8 # defines the detection time.
Icationication_period yy_at_8 # detection Interval
}
Restart the service to send messages within a specified period of time.