Server monitoring using Munin and Monit on CentOS 7.2
In this article, I will describe how to use Munin and Monit to monitor a CentOS 7 server. Munin can generate pretty small graphics for almost all aspects of the server (load average, memory usage, CPU usage, MySQL throughput, eth0 traffic, etc.) without too much configuration, and Monit checks services such as Apache, MySQL, Postfix Availability and take appropriate action, such as restarting (if the service is found to be abnormal). The combination of the two provides you with comprehensive monitoring: a graph that enables you to identify current or upcoming problems (for example, “We will soon need a larger server, and our average load is increasing rapidly.”), And A watchdog ensures the availability of monitored services.
Although Munin allows you to monitor multiple servers, here we only discuss monitoring the system where the system is installed.
This tutorial was written for CentOS 7.2, but the configuration should also be applicable to other distributions, such as RHEL and Scientific Linux.
1 Preliminary note
The host name of our system is server1.example.com, there is a website www.example.com, and the document root directory is / var / www / html.
2 enable EPEL repository
On CentOS 7, Munin and Monit are not provided in the default CentOS repository. Fortunately, we can install them from the EPEL repository. To enable the EPEL repository, we run:
yum -y install epel-release
Import EPEL GPG key:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
yum -y update
To ensure that the system is up-to-date and that EPEL’s package list has been loaded before starting to install munin.
2 install Apache web server
Munin needs a web server to provide and display its statistical files. I will install the apache httpd server here:
yum install httpd
Start apache and make it start automatically at startup.
systemctl enable httpdsystemctl start httpd
4 install and configure Munin
To install Munin on CentOS, do the following:
yum -y install munin munin-node
Then, we create a system startup link for Munin and start it:
systemctl enable munin-nodesystemctl start munin-node
Next, we must edit the Munin configuration file /etc/munin/munin.conf.
We want munin to use the name server1.example.com instead of localhost in the HTML output, so we replace localhost with server1.example.com. Without comments, the changed file looks like this:
[...] # a simple host tree [server1.example.com] address 127.0.0.1 use_node_name yes [...]
Muning statistics are protected by username and password (Apache Basic Authentication). In the next step, we add the new user and password to the / etc / munin / munin-htpasswd file.
htpasswd /etc/munin/munin-htpasswd admin
This command will add a new user named “admin” and prompt for the new password twice.
Now wait a few minutes so that munin can generate the first statistic output, then go to http://server1.example.com/munin/ in your browser, and you will see the first statistic.
(This is just a small excerpt of the many graphics produced by munin …)