📜 ⬆️ ⬇️

Nagios - Assistant in monitoring services and hosts

There are various free systems for monitoring the status of systems and networks such as Munin , Zabbix , etc. I want to share with the IT community an example of how to configure the Nagios monitoring system for the Arch Linux operating system.

The following example of installing Nagios was made on the Arch linux x64 distribution, but this material can also be used for the Arch i686.


1. Make sure your system is updated!
')
pacman -Syu

2. Install LAMP.

To install LAMP, you can use the user manual in Russian .

3. Preliminary settings.

To successfully build packages, you need the following installed: freetype2, gd, glib2, libtool.

pacman -S freetype2 gd glib2 libtool

4. Installing Nagios.

On the computer with ArchLinux installed, create the ~ / build directory and go into it, here we will build our packages.

mkdir ~/build cd ~/build

Nagios can be found in the AUR repository. Therefore, we do the following:

- Go to the search page for the AUR repository http://aur.archlinux.org/

- In the search bar (Search Critetia), enter nagios and press [GO]
- Select the nagios package and load it into the ~ / build directory:

wget -c downloads.sourceforge.net/nagios/nagios-3.2.0.tar.gz

- unpack:

tar -xvzf nagios-3.2.0.tar.gz

- move to the unpacked directory and load the necessary files into it (which are on the nagios download page):

cd ~/build/nagios
wget -c aur.archlinux.org/packages/nagios/nagios/PKGBUILD
wget -c aur.archlinux.org/packages/nagios/nagios/nagios.install
wget -c aur.archlinux.org/packages/nagios/nagios/rc.nagios


-Now you need to generate a package, for this we execute the command:

makepkg

(it can be a mock if you make it from under the root, then if you are sure about the reliability of packages use makepkg - asroot - it is not safe!).
When the package is assembled execute the command:

pacman -U " "

This will install the package into the system.

Similar operations (starting from searching the AUR repository) will be performed with the nagios-plugin package:

cd ~ / build
wget -c downloads.sourceforge.net/nagiosplug/nagios-plugins-1.4.14.tar.gz
tar -xvzf nagios-plugins-1.4.14.tar.gz cd nagios-plugins
wget -c aur.archlinux.org/packages/nagios-plugins/nagios-plugins/PKGBUILD
makepkg
pacman -U nagios-plugins-1.4.14-1-x86_64.pkg.tar.gz

5. Configure Nagios

Copy the configuration files with examples to the place of "combat":
# cp /etc/nagios/cgi.cfg.sample /etc/nagios/cgi.cfg
# cp /etc/nagios/resource.cfg.sample /etc/nagios/resource.cfg
# cp /etc/nagios/nagios.cfg.sample /etc/nagios/nagios.cfg
# cp /etc/nagios/objects/commands.cfg.sample /etc/nagios/objects/commands.cfg
# cp /etc/nagios/objects/contacts.cfg.sample /etc/nagios/objects/contacts.cfg
# cp /etc/nagios/objects/localhost.cfg.sample /etc/nagios/objects/localhost.cfg

# cp /etc/nagios/objects/templates.cfg.sample /etc/nagios/objects/templates.cfg
# cp /etc/nagios/objects/timeperiods.cfg.sample /etc/nagios/objects/timeperiods.cfg


We set permissions to the / etc / nagios directory:

chown -R nagios:nagios /etc/nagios

Create a file that will be used for web authorization panel nagios:

# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin

(despite the correct path in the nagios.conf file of the httpd configuration, I did not have authorization when using the htpasswd.users file, so I did htpasswd -c / etc / nagios / users nagiosadmin and fixed the corresponding line in / etc / httpd / conf / extra /nagios.conf)

Let's set the rights to the directory with the nagios files:

# chown -R nagios:nagios /usr/share/nagios

This completes the Nagios configuration, now you need to configure Apache.

6. Configure Apache.

Edit the /etc/httpd/conf/httpd.conf file, add the line:

Include /etc/httpd/conf/extra/nagios.conf

and execute:

# usermod -G nagios -a http

7. PHP configuration.

We connect in the /etc/php/php.ini Nagios file, open_basedir, for this we add in the line open_basedir: / usr / share / nagios:

open_basedir = /srv/http/:/usr/share/nagios

All settings are finished, now you need to restart httpd and nagios:

/etc/rc.d/nagios restart
/etc/rc.d/httpd restart


Now follow the link localhost / nagios
(or Ip address of the server on which everything was configured instead of localhost) you will see an authorization window in which you need to enter the username nagiosadmin and the password you assigned to it.

Setting control over services and hosts.

Add UNIX hosts.

in the directory / etc / nagios / create the servers directory in which all configuration files will be stored:

mkdir /etc/nagios/servers

After that, be sure to uncomment the line cfg_dir = / etc / nagios / servers in the /etc/nagios/nagios.cfg file

Unix-servers.cfg file in the / etc / nagios / servers directory is responsible for the unix group of hosts with the following content:

define hostgroup{
hostgroup_name unix ;
alias UNIX Servers ;
members srv_www, srv_mail;
}


hostgroup_name - describe the host group

alias - display group in the dashboard
members - hosts in a group (comma separated)

Now create the host configuration files.
srv_www is the server on which the web site is running (including nagios) and the proxy server on port 3128:
# HOST
define host{
use linux-server
host_name srv_www ;

icon_image linux.png
statusmap_image linux.gd2
address 10.1.1.7 ; Ip
}
# SERVICE
#
define service{

use local-service
host_name srv_www
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
# ssh

define service{
use local-service
host_name srv_www
service_description SSH
check_command check_ssh
}

# tcp 3128
define service{
use local-service
host_name srv_www
service_description tcp
check_command check_tcp!3128
}

# http ( 80 )
define service{
use local-service
host_name srv_www ;
service_description HTTP
check_command check_http
}


Add Windows hosts.

To monitor windows hosts use the program NSClient . Install it with the default settings on the windows host and make the configuration for nagios.
The windows host group, /etc/nagios/servers/windows-servers.cfg: define hostgroup{
hostgroup_name windows ;
alias Windows Servers ;

members srv_host06;
}
define hostgroup{
hostgroup_name windows ;
alias Windows Servers ;

members srv_host06;
}


and /etc/nagios/servers/win-srv_host06.cfg:

# HOST
define host{
use win-servers

host_name srv_host06
icon_image windows_server.png
statusmap_image windows_server.gd2
address 10.1.1.212
}
######

# SERVICE
define service{
use local-service
host_name srv_host06 ;
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}

# ( 80% - warning, 90% critical)
define service{
use generic-service
host_name srv_host06 ;
service_description CPU Load
check_command check_nt!CPULOAD!-l 1,80,90
}

#
define service{
use generic-service
host_name srv_host06 ;
service_description DISK space
check_command check_nt!USEDDISKSPACE!-lc -w 80 -c 90
}


The icon_image and statusmap_image can be found at exchange.nagios.org/directory/Images-and-Logos/ at the / usr / share / nagios / share / images / logos / directory .

After writing the host configuration files, you need to restart nagios:

/etc/rc.d/nagios restart

Now we monitor the status of servers and services on these sites. It all looks like this:

http://xackep.livejournal.com http://xackep.livejournal.com
http://xackep.livejournal.com http://xackep.livejournal.com

I am not a master of writing such articles, but I will be sincerely glad if she helps someone or maybe someone wants to add it, because this is very brief and fluent in setting up a monster called Nagios.

Article written by my good friend! All the laurels actually him)
Unfortunately, I don’t have enough karma for an invite, so I ask you, dear habrazhiteli, to treat your friend with an inviteit - yarofrost@gmail.com

Source: https://habr.com/ru/post/83994/


All Articles