Sie sind auf Seite 1von 7

Nagios User Manual

Nagios Prerequisites
Before installing Nagios, make sure you have the following installed: Apache, PHP, GCC compiler and GD development libraries.

Installing and Configuring Nagios


Note: This Nagios installation part only monitors the services running on the monitoring server or the localhost. Terms: Monitoring Server - the Virtual Server where Nagios, Nagios plug-ins and NRPE daemon are installed. Remote Server - the Virtual Servers being monitored by the Monitoring Server where Nagios plug-ins and NRPE daemon are installed. 1. Create the user account nagios: #/usr/sbin/useradd -m nagios #passwd nagios 2. Create the group nagcmd and then add both the nagios and apache users to this group: #/usr/sbin/groupadd nagcmd #/usr/sbin/usermod -a -G nagcmd nagios #/usr/sbin/usermod -a -G nagcmd apache Note: If you encounter an error stating user apache does not exist, just add apache to the user accounts. #/usr/sbin/useradd -m apache 3. Create a directory named downloads. Cd to that directory (cd downloads), then download Nagios and Nagios plug-ins from http://www.nagios.org/download/. 4. Extract the source code from the compressed tarball. Make sure you are in the directory where you downloaded the source code. Note: Check the latest version in Nagios main site. #tar xvzf nagios-3.2.0.tar.gz #cd nagios-3.2.0 5. Run the configure script. #./configure --with-command-group=nagcmd 6. Compile Nagio's source code.

#make all 7. Install the binaries, init script, sample configuration files, and configure permissions before starting Nagios: #make install #make install-init #make install-config #make install-commandmode 8. Edit the configuration file that will dictate which email address will receive alerts. Enter your email address. #nano /usr/local/nagios/etc/objects/contacts.cfg 9. Configure web interface. #make install-webconf 10. Create the user account nagiosadmin for logging into the web interface for Nagios. #htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin 11. Restart the web server (httpd) (apache) web service running on the virtual server: #service httpd restart or #service apache2 restart 12. Compile and install the Nagios plug-ins. Make sure you are in the directory where you downloaded the source code. Note: Check the latest version in Nagios main site. #tar xvzf nagios-plugins-1.4.11.tar.gz #cd nagios-plugins-1.4.11 13. Compile and install plug-ins. #./configure --with-nagios-user=nagios --with-nagios-group=nagios #make #make install 14. Verify if Nagios is installed correctly and will start without error: #/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 15. If no errors are reported, start Nagios: #service nagios start 16. Test Nagios by logging into the web interface. From a remote machine, using the browser, enter http://<ip_address_of_server>/nagios Enter screenshot of Nagios here:

Monitoring Remote Hosts using Nagios and NRPE


As we have stated before, the following installations and configurations given above is enough to monitory only one server. If we want to monitor multiple servers in a single web interface, we have to install the nagios plug-ins and NRPE daemon on the remote servers we want to monitor. Note: Make sure that necessary prerequisites stated above are installed. On the Remote Server (the other servers you want to monitor): 1. Create a nagios user account. #useradd nagios #passwd nagios 2. Create a directory named downloads. Cd to that directory (cd downloads), then download and install Nagios plug-ins. Download it from http://www.nagios.org/download/. 3. Extract the Nagios plugins. Note: Check the latest version in Nagios main site. #tar xvzf nagios-plugins-1.4.14.tar.gz #cd nagios-plugins-1.4.14 4.Configure and install the nagios-plugins. Make sure you are in the directory where you downloaded the source code. #./configure --with-nagios-user=nagios --with-nagios-group=nagios # make # make install 5. Change the permissions on the plugins directory: # chown nagios.nagios /usr/local/nagios # chown -R nagios.nagios /usr/local/nagios/libexec 6. Download and extract NRPE. Note: Make sure you are in the downloads directory. Download NRPE from http://www.nagios.org/download/. # tar -xvzf nrpe-2.12.tar.gz # cd nrpe-2.12 7. Install and configure NRPE: # ./configure # make all # make install-plugin

# make install-daemon # make install-daemon-config # make install-xinetd 8. Configure NRPE by editing the /etc/xinetd.d/nrpe file to allow our remote server to communicate with the monitoring server #nano vi /etc/xinetd.d/nrpe only_from = 127.0.0.1 <insert_monitoring_server_ip> <insert_remote_server_ip>

9. Add an entry in the /etc/services file for port TCP port 5666 for NRPE to communicate. #nano /etc/services Add the following entry. nrpe 5666/tcp # NRPE 10. Restart NRPE. # service xinetd restart 11. Test if NRPE is running and listening. Run the following. # netstat -at | grep nrpe This must output: tcp 0 0 *:nrpe *:*

LISTEN

12. Test if the NRPE daemon is accepting connections. Run the following command: # /usr/local/nagios/libexec/check_nrpe -H localhost This must output: NRPE v2.12 On the Monitoring Server: 14. Cd to the downloads directory. Download and extract NRPE. Download NRPE from http:// www.nagios.org/download/. Note: Check the latest version in Nagios main site. # tar -xzf nrpe-2.12.tar.gz # cd nrpe-2.12 15. Compile and configure NRPE: # ./configure # make all # make install-plugin 16. Make sure that the NRPE plugin running on the monitoring server that performs the monitoring can communicate with the remote host that we want to monitor: # /usr/local/nagios/libexec/check_nrpe -H <insert_ip_of_remote_server> This must output: NRPE v2.12

17. Configure Nagios to use the NRPE plug in by adding in the entry below. # nano /usr/local/nagios/etc/objects/commands.cfg ######################################################### NRPE CHECK COMMAND # Command to use NRPE to check remote host systems ######################################################## define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } 18. Configure Nagios, using the NRPE plugin, to communicate with the remote host. Create a template called linux-box-remote.cfg. Note: You can change the name of the template. # nano /usr/local/nagios/etc/objects/linux-box-remote.cfg define host{ name use check_period check_interval retry_interval max_check_attempts check_command notification_period notification_options contact_groups register } define host{ use host_name alias address } define service{ use host_name service_description

linux-box-remote generic-host 24x7 5 1 10 check-host-alive 24x7 d,r admins 0

linux-box-remote <any_name> <change_to_any_hostname> <insert_remote_server_ip>

generic-service <any_name> CPU Load

check_command check_nrpe!check_load } define service{ use generic-service host_name <any_name> service_description Current Users check_command check_nrpe!check_users } define service{ use generic-service host_name <any_name> service_description /dev/<paritition_name> Free Space check_command check_nrpe!check_<partition_name> } define service{ use generic-service host_name <any_name> service_description Total Processes check_command check_nrpe!check_total_procs } define service{ use generic-service host_name <any_name> service_description Zombie Processes check_command check_nrpe!check_zombie_procs } 19. Activate the new template. #nano /usr/local/nagios/etc/nagios.cfg Add the following entry. # Definitions for monitoring remote machines cfg_file=/usr/local/nagios/etc/objects/linux-box-remote.cfg 20. Restart Nagios. # service nagios restart 22. Verify if you can view the statistics of both servers (monitoring server and remote server). Log-in to the web interface of a remote machine. On the browser enter http:// <ip_address_of_server>/nagios <Enter Screenshot here>:

Monitoring Other Services

If you want to monitor other services running on the remote servers, you can do the following: 1. On the Remote Server that is being monitored, add the proper check command for the service. Note: You can refer the official Nagios documentation for this. #nano /usr/local/nagios/etc/nrpe.cfg Example: command[check_smbd]=/usr/local/nagios/libexec/check_procs -c 1:30 -C smbd 2. On the Monitoring Server, edit the template. In this example, that template is named linuxbox-remote.cfg. Add a service definition for each service that you added in the remote server's nrpe.cfg file. Note: You can refer the official Nagios documentation for this. #nano /usr/local/nagios/etc/objects/linux-box-remote.cfg Example service definition: define service{ use generic-service host_name <name_of_host> service_description CHECK_SMBD check_command check_nrpe!check_smbd } 3. Restart Nagios. #service nagios restart Reference: http://lancrossdata.com/index.php?option=com_content&view=article&id=91:monitoring-linuxwith-nagios&catid=52:monitoring-linux-&Itemid=69

Das könnte Ihnen auch gefallen