How to install Monit on your CentOS6 VPS

how-to-install-monit-on-your-centos6-vpsToday we’ll show you how to install Monit on your Centos VPS. Monit is a monitoring and managing as well as an automatic maintenance tool. The monitoring can be directly on the command line or on the web. You can assign Monit multiple tasks (not only monitoring), so if a certain service fails the check, Monit can alert or do something about it (try to restart the service for example).

First, we need to make sure our server is up-to-date. Run the following:

# yum update

Before installing Monit, we need to install some of the files required by it. To do this, type:

# yum install -y

Now we can download and install Monit on the server. This can also be achieved via the EPEL repository but you won’t get the latest version which will create additional configuation and usage difficulties for you. So, to download and install the latest Monit version on your server follow the next few simple steps:

# wget
# rpm -Uvh

After the installation is complete, edit the main config file to resemble the example below using your favorite text editor and set your own username and password:

# vim /etc/monit.conf

set httpd port 2812 and      # set the listening port to your desire. default is 2812 (if setting custom port, make sure it does not overlap with some other service’s listening port)
#     use address localhost  # only accept connection from localhost
#     allow localhost        # allow localhost to connect to the server and
allow user:’password’      # require user ‘user’ with password ‘password’
#    allow @monit           # allow users of group ‘monit’ to connect (rw)
#    allow @users readonly  # allow users of group ‘users’ to connect readonly

After the initial config is completed, we can configure some of the services we want to monitor. To do this, we will create separate files for every service located within the /etc/monit.d/ directory. Use your favorite text editor and create the files as shown for these couple of example service configurations:

# vim /etc/monit.d/http

check process webserver with pidfile /var/run/httpd/
group apache
start program = “/etc/init.d/httpd start”
stop  program = “/etc/init.d/httpd stop”
if failed host port 80 then restart

# vim /etc/monit.d/ntp

check process ntpd with pidfile /var/run/
start program = “/etc/init.d/ntpd start”
stop  program = “/etc/init.d/ntpd stop”
if failed host port 123 type udp then alert

# vim /etc/monit.d/ssh

start program  “/etc/init.d/sshd start”
stop program  “/etc/init.d/sshd stop”
if failed port 22 protocol ssh then restart

After creating the desired configuration files, test the control file for syntax errors:

# monit -t

And start monit by simply typing:

# monit

Open your browser to http://youripaddress:yourport and enter the credentials you created in /etc/monit.conf

That’s it. We have successfully installed and configured Monit on our CentOS VPS.

Of course, if you are one of our Linux VPS Hosting customers, you don’t have to do any of this, simply ask our admins, sit back and relax. Our admins will set this up for you immediately. You might also want to read our guide on How to install Monitorix system monitoring tool on CentOS 6 VPS.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Leave a Comment

To prove you are human please solve the following *