{"id":11824,"date":"2019-03-17T13:12:03","date_gmt":"2019-03-17T13:12:03","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11824"},"modified":"2019-03-17T13:12:03","modified_gmt":"2019-03-17T13:12:03","slug":"how-to-install-and-setup-monit-linux-process-and-services-monitoring-program","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/17\/how-to-install-and-setup-monit-linux-process-and-services-monitoring-program\/","title":{"rendered":"How to Install and Setup Monit (Linux Process and Services Monitoring) Program"},"content":{"rendered":"<p><strong>Monit<\/strong>\u00a0is a free open source and very useful tool that automatically monitors and manages\u00a0<strong>server process<\/strong>,\u00a0<strong>files<\/strong>,\u00a0<strong>directories<\/strong>,\u00a0<strong>checksums<\/strong>,\u00a0<strong>permissions<\/strong>,\u00a0<strong>filesystems<\/strong>\u00a0and services like\u00a0<strong>Apache<\/strong>,\u00a0<strong>Nginx<\/strong>,\u00a0<strong>MySQL<\/strong>,\u00a0<strong>FTP<\/strong>,\u00a0<strong>SSH<\/strong>,\u00a0<strong>Sendmail<\/strong>and so on in a\u00a0<strong>UNIX\/Linux<\/strong>\u00a0based systems and provides an excellent and helpful monitoring functionality to system administrators.<\/p>\n<p>The monit has user friendly web interface where you can directly view the system status and setup up processes using native HTTP(S) web server or via the command line interface. This means you must have web server like\u00a0<strong>Apache<\/strong>\u00a0or\u00a0<strong>Nginx<\/strong>\u00a0installed on your system to access and view monit web interface.<\/p>\n<p><strong>Read Also<\/strong>\u00a0:\u00a0<a href=\"https:\/\/www.tecmint.com\/command-line-tools-to-monitor-linux-performance\/\" target=\"_blank\" rel=\"noopener\">10 Linux Performance Monitoring Tools<\/a><\/p>\n<h5>What Monit can do<\/h5>\n<p>Monit has a ability to start a process if it is not running, restart a process if not responding and stop a process if uses high resources. Additionally you can also use Monit to Monitor\u00a0<strong>files<\/strong>,\u00a0<strong>directories<\/strong>\u00a0and\u00a0<strong>filesystems for changes<\/strong>,\u00a0<strong>checksum changes<\/strong>,\u00a0<strong>file size changes<\/strong>\u00a0or\u00a0<strong>timestamp changes<\/strong>. With Monit you can able to monitor remote hosts\u00a0<strong>TCP\/IP<\/strong>\u00a0port,\u00a0<strong>server protocols<\/strong>\u00a0and\u00a0<strong>ping<\/strong>. Monit keeps its own log file and alerts about any critical error conditions and recovery status.<\/p>\n<p><center>This article is written to describe a simple guide on\u00a0<strong>Monit<\/strong>\u00a0installation and configuration on a\u00a0<strong>RHEL<\/strong>,\u00a0<strong>CentOS<\/strong>,\u00a0<strong>Fedora<\/strong>,\u00a0<strong>Ubuntu<\/strong>,\u00a0<strong>Linux Mint<\/strong>\u00a0and\u00a0<strong>Debian<\/strong>\u00a0Linux Operating Systems, but it should be easily compatible to\u00a0<strong>Scientific Linux<\/strong>\u00a0as well.<\/center><\/p>\n<h3>Step 1: Installing Monit<\/h3>\n<p>By default,\u00a0<strong>Monit<\/strong>\u00a0tool is not available from the system base repositories, you need to add and enable third party\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-enable-epel-repository-for-rhel-centos-6-5\/\" target=\"_blank\" rel=\"noopener\">epel repository<\/a>\u00a0to install\u00a0<strong>monit<\/strong>\u00a0package under your\u00a0<strong>RHEL\/CentOS<\/strong>\u00a0systems. Once you\u2019ve added epel repository, install package by running the following\u00a0<strong>yum command<\/strong>. For\u00a0<strong>Ubuntu\/Debian\/Linux Mint<\/strong>\u00a0user\u2019s can easily install using\u00a0<strong>apt-get command<\/strong>\u00a0as shown.<\/p>\n<h5>On RedHat\/CentOS\/Fedora\/<\/h5>\n<pre># yum install monit<\/pre>\n<h5>On Ubuntu\/Debian\/Linux Mint<\/h5>\n<pre>$ sudo apt-get install monit<\/pre>\n<h3>Step 2: Configuring Monit<\/h3>\n<p><strong>Monit<\/strong>\u00a0is very easy to configure, in fact the configuration files are created to be very easily readable and making them easier for users to understand. It is designed to monitor the running services in every 2 minutes and keeps the logs in \u201c<strong>\/var\/log\/monit<\/strong>\u201c.<\/p>\n<p><strong>Monit<\/strong>\u00a0has it\u2019s web interface that runs on port\u00a0<strong>2812<\/strong>\u00a0using web server. To enable web interface you need to make changes in monit configuration file. The main configuration file of monit located at\u00a0<strong>\/etc\/monit.conf<\/strong>\u00a0under (<strong>RedHat\/CentOS\/Fedora<\/strong>) and\u00a0<strong>\/etc\/monit\/monitrc<\/strong>\u00a0file for (<strong>Ubuntu\/Debian\/Linux Mint<\/strong>). Open this file using your choice of editor.<\/p>\n<pre># vi \/etc\/monit.conf<\/pre>\n<pre>$ sudo vi \/etc\/monit\/monitrc<\/pre>\n<p>Next, uncomment the following section and add the IP address or domain name of your server, allow anyone to connect and change monit user and password or you can use default ones.<\/p>\n<pre> set httpd port 2812 and\r\n     use address localhost  # only accept connection from localhost\r\n     allow localhost        # allow localhost to connect to the server and\r\n     allow admin:monit      # require user 'admin' with password 'monit'\r\n     allow @monit           # allow users of group 'monit' to connect (rw)\r\n     allow @users readonly  # allow users of group 'users' to connect readonly<\/pre>\n<p>Once you\u2019ve configured it, you need to start the monit service to reload the new configuration settings.<\/p>\n<pre># \/etc\/init.d\/monit start<\/pre>\n<pre>$ sudo \/etc\/init.d\/monit start<\/pre>\n<p>Now, you will able to access the monit web interface by navigating to the \u201c<strong>http:\/\/localhost:2812<\/strong>\u201d or \u201c<strong>http:\/\/example.com:2812<\/strong>\u201c. Then enter user name as \u201c<strong>admin<\/strong>\u201d and password as \u201c<strong>monit<\/strong>\u201c. You should get screen similar to below.<\/p>\n<div id=\"attachment_2583\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/04\/Monit-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2583\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/04\/Monit-1.jpg\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/04\/Monit-1.jpg 600w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/04\/Monit-1-300x225.jpg 300w\" alt=\"Install Monit in Fedora\" width=\"600\" height=\"450\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Monit Web Interface<\/p>\n<\/div>\n<h3>Step 3: Adding Monitoring Services<\/h3>\n<p>Once monit web interface correctly setup, start adding the programs that you want to monitor into the\u00a0<strong>\/etc\/monit.conf<\/strong>\u00a0under (<strong>RedHat\/CentOS\/Fedora<\/strong>) and\u00a0<strong>\/etc\/monit\/monitrc<\/strong>\u00a0file for (<strong>Ubuntu\/Debian\/Linux Mint<\/strong>) at the bottom.<\/p>\n<p>Following are some useful configuration examples for monit, that can be very helpful to see how a service is running, where it keeps its pidfile and how to start and stop a service etc.<\/p>\n<h5>Apache<\/h5>\n<pre>check process httpd with pidfile \/var\/run\/httpd.pid\r\ngroup apache\r\nstart program = \"\/etc\/init.d\/httpd start\"\r\nstop program = \"\/etc\/init.d\/httpd stop\"\r\nif failed host 127.0.0.1 port 80\r\nprotocol http then restart\r\nif 5 restarts within 5 cycles then timeout<\/pre>\n<h5>Apache2<\/h5>\n<pre>check process apache with pidfile \/run\/apache2.pid\r\nstart program = \"\/etc\/init.d\/apache2 start\" with timeout 60 seconds\r\nstop program  = \"\/etc\/init.d\/apache2 stop\"<\/pre>\n<h5>Nginx<\/h5>\n<pre>check process nginx with pidfile \/var\/run\/nginx.pid\r\nstart program = \"\/etc\/init.d\/nginx start\"\r\nstop program = \"\/etc\/init.d\/nginx stop\"<\/pre>\n<h5>MySQL<\/h5>\n<pre>check process mysqld with pidfile \/var\/run\/mysqld\/mysqld.pid\r\ngroup mysql\r\nstart program = \"\/etc\/init.d\/mysqld start\"\r\nstop program = \"\/etc\/init.d\/mysqld stop\"\r\nif failed host 127.0.0.1 port 3306 then restart\r\nif 5 restarts within 5 cycles then timeout<\/pre>\n<h5>SSHD<\/h5>\n<pre>check process sshd with pidfile \/var\/run\/sshd.pid\r\nstart program \"\/etc\/init.d\/sshd start\"\r\nstop program \"\/etc\/init.d\/sshd stop\"\r\nif failed host 127.0.0.1 port 22 protocol ssh then restart\r\nif 5 restarts within 5 cycles then timeout<\/pre>\n<p>Once you\u2019ve configured all programs for monitoring, check monit syntax for errors. If found any errors fix them, it\u2019s not so tough to figure out what\u2019s went wrong. When you get message like \u201c<strong>Control file syntax OK<\/strong>\u201c, or if you see no errors, you can proceed ahead.<\/p>\n<pre># monit -t<\/pre>\n<pre>$ sudo monit -t<\/pre>\n<p>After fixing all possible errors, you can type the following command to start the monit service.<\/p>\n<pre># \/etc\/init.d\/monit restart<\/pre>\n<pre>$ sudo \/etc\/init.d\/monit restart<\/pre>\n<p>You can verify that monit service is started by checking log file.<\/p>\n<pre># tail -f \/var\/log\/monit<\/pre>\n<pre>$ sudo tail -f \/var\/log\/monit.log<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[BDT Apr  3 03:06:04] info     : Starting monit HTTP server at [localhost:2812]\r\n[BDT Apr  3 03:06:04] info     : monit HTTP server started\r\n[BDT Apr  3 03:06:04] info     : 'tecmint.com' Monit started\r\n[BDT Apr  3 03:06:04] error    : 'nginx' process is not running\r\n[BDT Apr  3 03:06:04] info     : 'nginx' trying to restart\r\n[BDT Apr  3 03:06:04] info     : 'nginx' start: \/etc\/init.d\/nginx<\/pre>\n<h5>Monit Screenshot<\/h5>\n<p>This is how looks monit after adding all process for monitoring.<\/p>\n<div id=\"attachment_2584\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/04\/Monit-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2584\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/04\/Monit-2.jpg\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/04\/Monit-2.jpg 600w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/04\/Monit-2-300x225.jpg 300w\" alt=\"Monit Monitoring Process\" width=\"600\" height=\"450\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Monit Monitoring All Process<\/p>\n<\/div>\n<h3>Reference Links<\/h3>\n<ol>\n<li><a href=\"https:\/\/mmonit.com\/\" target=\"_blank\" rel=\"nofollow noopener\">Monit Home Page<\/a><\/li>\n<li><a href=\"https:\/\/mmonit.com\/wiki\/\" target=\"_blank\" rel=\"nofollow noopener\">Monit Documentation<\/a><\/li>\n<li><a href=\"https:\/\/mmonit.com\/wiki\/Monit\/ConfigurationExamples\" target=\"_blank\" rel=\"nofollow noopener\">Monit Configuration Examples<\/a><\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.tecmint.com\/how-to-install-and-setup-monit-linux-process-and-services-monitoring-program\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Monit\u00a0is a free open source and very useful tool that automatically monitors and manages\u00a0server process,\u00a0files,\u00a0directories,\u00a0checksums,\u00a0permissions,\u00a0filesystems\u00a0and services like\u00a0Apache,\u00a0Nginx,\u00a0MySQL,\u00a0FTP,\u00a0SSH,\u00a0Sendmailand so on in a\u00a0UNIX\/Linux\u00a0based systems and provides an excellent and helpful monitoring functionality to system administrators. The monit has user friendly web interface where you can directly view the system status and setup up processes using native HTTP(S) &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/17\/how-to-install-and-setup-monit-linux-process-and-services-monitoring-program\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Install and Setup Monit (Linux Process and Services Monitoring) Program&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11824","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11824"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11824\/revisions"}],"predecessor-version":[{"id":11825,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11824\/revisions\/11825"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}