📜 ⬆️ ⬇️

Own monitoring server with nagios and cacti

Under the cat tips on the rapid deployment of "monitoring systems" through nagios and cacti.

Suppose there is a pristine clean server with debian lenny preinstalled. And we have to make from this shapeless mass an amusement park with blackjack and girls. Hmm, although no, probably all the same you need to do a monitoring server with nagios and cacti.

First of all, you need to install the ssh server and mc (midnight commander), I think to comment on why and why we do it unnecessarily
debian:~# apt-get update
debian:~# apt-get install openssh-server
debian:~# apt-get install mc


Next, we put nagios. We will put in a "kosher" way, using apt. This will save us from the problem of dependencies, many hours of climbing in the wilds of configuration files and shorten the deployment time of the system.
And so, we recruit a magic team

debian:~# apt-get install nagios3

and, voila, we have already installed the Nagios in the minimum configuration. What happened? The package manager looked at the dependencies for the nagios3 package. In addition to the basic package, plugins for nagios, apache and many, many necessary libraries were installed.
Minimal configs for nagios and apache were also created. In theory, everything should work out of the box, but as usual you have to use a file.
')
As we can see, in the /etc/nagios3/nagios.conf config it is indicated that ordinary http authorization is used to access nagios, but unfortunately there is no authorization file.
In order to fix this sad fact we will create it by the team.
debian:~# htpasswd -c /etc/nagios3/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

Please note that the user should be exactly nagiosadmin, and not Vasya, Lucy or Petruchio.
This is due to the fact that by default in nagios.cfg the user with access to all functions is nagiosadmin.

We include the processing of external commands, the necessary thing, for example, for “Re-schedule the next check of this host”.
debian:~# mcedit /etc/nagios3/nagios.cfg

check_external_commands=1

We change permishens and owners
chown -R nagios.www-data /var/lib/nagios3
chmod -R 770 /var/lib/nagios3/spool
chmod 644 /etc/nagios3/resource.cfg


The installation of nagios3 is complete. We can enter the interface nagios3 typing in your favorite browser
http: // youre_server_ip / nagios3
Now with a clear conscience, we proceed to its configuration. You can plunge into configuration files and watch them for hours, receiving indescribable satisfaction with multiple orgasms from this process. Or make the act of setting nagios through a web interface. For example, using NagiosQL.
In order to observe the “kosher” nature of the NagiosQL installation, we will add a repository with NagiosQL that was added to the list of repositories.
The list of repositories is in /etc/apt/sources.list:

deb http:// debian.swobspace.net lenny main
deb-src http:// debian.swobspace.net lenny main

Next, to get only NagiosQL from the debian.swobspace.net repository, create the file / etc / apt / preferences
debian:~# touch /etc/apt/preferences

and in it we indicate our preferences for installing packages

Package: *
Pin: origin debian.swobspace.net
Pin-Priority: 200

Package: nagiosql
Pin: origin debian.swobspace.net
Pin-Priority: 600


Get and import keys for the debian.swobspace.net repository
debian:~# wget http:// www.swobspace.net/wob@swobspace.net.pub.asc -O- | apt-key add -

Update the list of packages
debian:~# apt-get update

Install NagiosQL
debian:~# apt-get install nagiosql

It is here that we fully see the advantage of the “kosher” approach to installing packages, the dependencies were php, mysql, the necessary modules and libraries. No need to puzzle why some function does not work, or why the graph is not generated.
During the installation, you will be asked for the root password to access the mysql database, be sure to write it on a piece of paper.

Customization
1.Activate the NagiosQL installer
debian:~# touch /usr/share/nagiosql/htdocs/install/ENABLE_INSTALLER

2. Go http: // youre_server_ip / nagiosql and perform the installation in an intuitive web interface, it is here that you will need that piece of parchment on which we recorded the root password from mysql with obscure scribbles.

3. After successful installation, deactivate the NagiosQL installer
debian:~# rm -f /usr/share/nagiosql/htdocs/install/ENABLE_INSTALLER
for reliability, you can delete the entire folder with the installer
debian:~# rm -rf /usr/share/nagiosql/htdocs/install

4. Add the line to /etc/nagios3/nagios.cfg.
cfg_dir=/etc/nagiosql/domains/localhost

5. Create the / etc / nagios / import folder and copy all configs from /etc/nagios3/conf.d and / etc / nagios-plugins / into it. And import them into NagiosQL.
Data import is carried out in the Tools => Data import menu.

6. We throw out the leaflet with the password recorded by root for mysql in the trash

Next you will have to deal with NagiosQL yourself, google translate to help you.

The installation of cacti itself as well as nagios is very simple.

debian:~# apt-get install cacti

Before you again will appear a rather large list of dependencies, without hesitation, type Yes. During the installation process, we will again need an unfortunate leaflet with a password from mysql, in vain we must have thrown it into the trash.

It remains to configure cacti, everything is simple, as with NagiosQL. Intuitive interface.
http: // youre_server_ip / cacti
Standard login and password for access to cacti: admin / admin.

Now, suppose we have a server from which we will take data and draw graphics on it.
We will shoot the data through snmpd
Install snmpd on the server from which we will take the data (again, I mean that the server is debian lenny).
shaper:~# apt-get install snmpd

in the / etc / default / snmpd config we change the un IP address on which the snmpd daemon will accept requests

shaper:~# mcedit /etc/default/snmpd

instead
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1'
changeable
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid you_server2_ip'

Add a line to the /etc/snmp/snmpd.conf file

rocommunity my_snmp_community youre_server_ip

rocommunity - rocommunity -only access allowed
my_snmp_community - snmp community for data access
youre_server_ip - un from which access to the daemon is allowed

Reboot snmp
shaper:~# /etc/init.d/snmpd restart

Further operations are done in the interface Cacti
Console => Management => Devices => Add (upper right corner)
Descpription - machine description
Hostname - IP
Host Template - udc / net SNMPD Host

SNMP Version - Version 2

SNMP Community - snmp community specified on the server

Click Create
If after that we see

Ping Results
Host is alive

Click Create Graphs for this Host
Put down the "checkboxes" on those graphs that you want to draw and click Create (for gigabit interfaces, select the Select a graph type - In / Out Bits (64-bit Counters) selector)

If everything went well again, we can add “our server” to the tree of graphs
Console => Management => Graph Trees => Default Tree => Add (upper right corner)

Tree Item Type - choose Host
Host - our server

Click Create.
And after 5-10 minutes, enjoy the charts.

Ruthlessly destroying the leaflet with the password recorded for root mysql

It took us no more than half an hour to get the basic setup of the monitoring server. Again, please note the base.
The rest is in your hands, no one limits the flow of fantasy, the main thing is not to abuse hallucinogens.

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


All Articles