{"id":1683,"date":"2017-08-22T16:47:57","date_gmt":"2017-08-22T20:47:57","guid":{"rendered":"https:\/\/easy-admin.ca\/?p=1683"},"modified":"2024-03-26T14:43:26","modified_gmt":"2024-03-26T18:43:26","slug":"monitoring-linux-systems-and-services-using-monit","status":"publish","type":"post","link":"https:\/\/easy-admin.ca\/index.php\/2017\/08\/22\/monitoring-linux-systems-and-services-using-monit\/","title":{"rendered":"Monitoring Linux Systems and Services using Monit"},"content":{"rendered":"<div><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1700\" src=\"https:\/\/easy-admin.ca\/wp-content\/uploads\/2017\/08\/monit.jpg\" alt=\"\" width=\"603\" height=\"313\" srcset=\"https:\/\/easy-admin.ca\/wp-content\/uploads\/2017\/08\/monit.jpg 603w, https:\/\/easy-admin.ca\/wp-content\/uploads\/2017\/08\/monit-300x156.jpg 300w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/div>\n<div><\/div>\n<div><\/div>\n<div><em><strong>Monit<\/strong><\/em> is a opensource process tool for Linux operating system which helps you to monitor system process using web browser and also when ever requires it automatically do the maintenance or repair of particular process in such a way that it can be brought back online. It can also used for managing and monitoring of programs, files, directories, and devices for timestamps changes, checksum changes, or size changes; not limited to perform various TCP\/IP network checks, protocol checks, and can utilize SSL for such checks.<\/div>\n<div><\/div>\n<p>onfigure EPEL repo to download the latest Monit package.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# rpm -ivh https:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Install the Monit.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# yum -y install monit<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Start monit by using the following command.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# monit<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Check the monit status.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# monit status\nThe Monit daemon 5.6 uptime: 0m\n\u00a0\nSystem 'server.itzgeek.com'\n\u00a0 status\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Running\n\u00a0 monitoring status\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Monitored\n\u00a0 load average\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [0.14] [0.55] [0.49]\n\u00a0 cpu\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0.0%us 0.0%sy 0.0%wa\n\u00a0 memory usage\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 390704 kB [20.8%]\n\u00a0 swap usage\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0 kB [0.0%]\n\u00a0 data collected\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Wed, 23 Jul 2014 16:06:28<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h3><strong>Configure Monit:<\/strong><\/h3>\n<p>Monit config file is \/etc\/monit.conf, by default monit is set to check the services at interval of 1 min, this setting can be altered by changing.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# vi \/etc\/monitrc\nset daemon  60<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Alert cans be configured by.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">set mailserver<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Alert templates can be found in the configuration file itself.<br \/>\nLogs setting can be changed by using the following file.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# vi \/etc\/monit.d\/logging\n\u00a0\nset logfile<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h3><strong>Web Interface:<\/strong><\/h3>\n<p>Monit also provides a web interface to monitor and manage the configured services, by default monit listens on 2812 port but it needs to be setup. Open monit configuration file \/etc\/monit.conf.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# vi \/etc\/monit.conf<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<p>Look for httpd port 2812, modify the following entries<\/p>\n<\/div>\n<p>FROM<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">set httpd port 2812 and\nuse address localhost\u00a0 # only accept connection from localhost\nallow localhost\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # allow localhost to connect to the server and\nallow admin:monit\u00a0\u00a0\u00a0\u00a0\u00a0 # require user 'admin' with password 'monit'\nallow @monit\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # allow users of group 'monit' to connect (rw)\nallow @users readonly\u00a0 # allow users of group 'users' to connect readonly<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>TO<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">set httpd port 2812\nallow 0.0.0.0\/0.0.0.0\nallow admin:monit<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>From the above settings, monit will listen on 2812; admin user will able to access the web interface from any network.<\/p>\n<p>Reload monit.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# systemctl restart\u00a0 monit.service<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Auto start Monit on start-up.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# systemctl enable  monit.service<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>Access the web interface by using http:\/\/your-ip-address:2812, use the username and password mentioned in the previous step. Monit home page will look like this.<\/div>\n<div><\/div>\n<div><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1696\" src=\"https:\/\/easy-admin.ca\/wp-content\/uploads\/2017\/08\/monit-002-1.jpg\" alt=\"\" width=\"833\" height=\"469\" srcset=\"https:\/\/easy-admin.ca\/wp-content\/uploads\/2017\/08\/monit-002-1.jpg 833w, https:\/\/easy-admin.ca\/wp-content\/uploads\/2017\/08\/monit-002-1-300x169.jpg 300w, https:\/\/easy-admin.ca\/wp-content\/uploads\/2017\/08\/monit-002-1-768x432.jpg 768w\" sizes=\"auto, (max-width: 833px) 100vw, 833px\" \/><\/div>\n<div style=\"text-align: center;\">CentOS 7 \u2013 Monit 5.6 DashBoard<\/div>\n<div><\/div>\n<div>\n<h3><strong>Configuring services for monitoring:<\/strong><\/h3>\n<p>Once the web interface is up, we can start to setup other services that you want to monitor; you can place the configuration files under \/etc\/monit.d\/ directory.<\/p>\n<p><strong>Configure for <\/strong>sshd<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# vi \/etc\/monit.d\/sshdmonitor\n\u00a0\ncheck process sshd with pidfile \/var\/run\/sshd.pid\nstart program  \"\/usr\/bin\/systemctl start sshd.service\"\nstop program  \"\/usr\/bin\/systemctl stop sshd.service\"\nif failed port 22 protocol ssh then restart<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>Configure for <\/strong>syslog<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# vi \/etc\/monit.d\/syslogmonitor\n\u00a0\ncheck process syslogd with pidfile \/var\/run\/syslogd.pid\nstart program = \"\/usr\/bin\/systemctl start rsyslog.service\"\nstop program = \"\/usr\/bin\/systemctl stop rsyslog.service\"<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>Once configured, test the <\/strong>monit<strong> syntax<\/strong><\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# monit -t\n\u00a0\nControl file syntax OK<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>Reload it, to take effect of changes<\/strong><\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# monit reload<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div>Access the web interface, you would find the new services that we configured earlier.<\/div>\n<div><\/div>\n<div><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1697\" src=\"https:\/\/easy-admin.ca\/wp-content\/uploads\/2017\/08\/monit-003.jpg\" alt=\"\" width=\"831\" height=\"562\" srcset=\"https:\/\/easy-admin.ca\/wp-content\/uploads\/2017\/08\/monit-003.jpg 831w, https:\/\/easy-admin.ca\/wp-content\/uploads\/2017\/08\/monit-003-300x203.jpg 300w, https:\/\/easy-admin.ca\/wp-content\/uploads\/2017\/08\/monit-003-768x519.jpg 768w\" sizes=\"auto, (max-width: 831px) 100vw, 831px\" \/><\/div>\n<div><\/div>\n<div>\n<h3><strong>Test the Monitoring:<\/strong><\/h3>\n<p><strong>Now stop the <\/strong>syslog<strong> daemon<\/strong><\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# \/etc\/init.d\/rsyslog stop<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Wait for 30 second, monit will start the syslog automatically. You can find it in monit log.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# cat \/var\/log\/monit\n[EDT Jul 23 16:28:04] error\u00a0\u00a0\u00a0 : 'syslogd' process is not running\n[EDT Jul 23 16:28:04] info\u00a0\u00a0\u00a0\u00a0 : 'syslogd' trying to restart\n[EDT Jul 23 16:28:04] info\u00a0\u00a0\u00a0\u00a0 : 'syslogd' start: \/usr\/bin\/systemctl\n[EDT Jul 23 16:29:04] info\u00a0\u00a0\u00a0\u00a0 : 'syslogd' process is running with pid 40440<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>That\u2019s All, We have successfully configured Monit on CentOS<\/p>\n<\/div>\n<div><\/div>\n<div><\/div>\n<div><em><strong>Have fun!<\/strong><\/em><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Monit is a opensource process tool for Linux operating system which helps you to monitor system process using web browser and also when ever requires it automatically do the maintenance or repair of particular process in such a way that it can be brought back online. It can also used for managing and monitoring of &hellip; <a href=\"https:\/\/easy-admin.ca\/index.php\/2017\/08\/22\/monitoring-linux-systems-and-services-using-monit\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Monitoring Linux Systems and Services using Monit<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Monitoring Linux Systems and Services using Monit - HP Server","description":"Monit is a opensource process tool for Linux operating system which helps you to monitor system process using web browser and also when ever requires it automat"},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1683","post","type-post","status-publish","format-standard","hentry","category-general"],"_links":{"self":[{"href":"https:\/\/easy-admin.ca\/index.php\/wp-json\/wp\/v2\/posts\/1683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/easy-admin.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/easy-admin.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/easy-admin.ca\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/easy-admin.ca\/index.php\/wp-json\/wp\/v2\/comments?post=1683"}],"version-history":[{"count":0,"href":"https:\/\/easy-admin.ca\/index.php\/wp-json\/wp\/v2\/posts\/1683\/revisions"}],"wp:attachment":[{"href":"https:\/\/easy-admin.ca\/index.php\/wp-json\/wp\/v2\/media?parent=1683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/easy-admin.ca\/index.php\/wp-json\/wp\/v2\/categories?post=1683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/easy-admin.ca\/index.php\/wp-json\/wp\/v2\/tags?post=1683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}