Monitoring Sistem Service dengan Monit, Instalasi & Konfigurasi Monit Service Manager di Debian/Ubuntu

Monit adalah free & open-source utilitas untuk memanajemen dan monitoring sistem Unix-like. Monit dapat memonitor, melakukan pemeliharaan, perbaikan otomatis, dan kontrol penuh ketika terjadi kesalahan proses pada sistem.
Sebelum melakukan instalasi Monit pada Debian/Ubuntu ada baiknya melakukan update repository agar tidak terjadi error saat melakukan instalasi, Jalankan perintah :
sudo apt update -y
Instalasi Monit pada Debian/Ubuntu
Untuk melakukan instalasi monit, Jalankan perintah berikut ;
sudo apt install monit

Konfigurasi Monit
Setelah selesai proses instalasi sekarang mengkonfigurasi Monit, File konfigurasi Monit terletak pada /etc/monit/monitrc , Anda dapat mengedit untuk menambah program yang akan di monitoring :
sudo nano /etc/monit/monitrc

Tambahkan bagian baris berikut pada bawah konfigurasi untuk menambahkan service dan file yang akan di monitoring.
Apache2 :
# Apache2
check process apache with pidfile /var/run/apache2/apache2.pid
group www
group apache
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if 4 restarts within 20 cycles then timeout
if failed host localhost port 80 with protocol http and request "/server-sta>
depend apache_bin
depend apache_rc check file apache_bin with path /usr/sbin/apache2
group apache
include /etc/monit/templates/rootbin check file apache_rc with path /etc/init.d/apache2
group apache
include /etc/monit/templates/rootbin
Nginx :
# Nginx
check process nginx with pidfile /var/run/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
MySQL/MariaDB :
# MySQL/MariaDB
check process mysql with pidfile /run/mysqld/mysqld.pid
start program = "/usr/sbin/service mysql start" with timeout 60 seconds
stop program = "/usr/sbin/service mysql stop"
if failed unixsocket /var/run/mysqld/mysqld.sock then restart
Vsftpd :
# Vsftpd
check process vsftpd
matching vsftpd
start program = "/etc/init.d/vsftpd start"
stop program = "/etc/init.d/vsftpd stop"
if failed port 21 protocol ftp then restart
Postfix :
# Postfix
check process postfix with pidfile /var/spool/postfix/pid/master.pid
group system
group mail
group postfix
start program = "/etc/init.d/postfix start"
stop program = "/etc/init.d/postfix stop"
if failed host localhost port 25 with protocol smtp for 2 times within 3 cyc>
if 5 restarts with 5 cycles then timeout
depend master_bin
depend postfix_rc
depend postdrop_bin
depend postqueue_bin
depend master_cf
depend main_cf check file master_bin with path /usr/lib/postfix/sbin/master
group postfix
include /etc/monit/templates/rootbin check file postdrop_bin with path /usr/sbin/postdrop
group postfix
if failed checksum then unmonitor
if failed permission 2555 then unmonitor
if failed uid root then unmonitor
if failed gid postdrop then unmonitor check file postqueue_bin with path /usr/sbin/postqueue
group postfix
if failed checksum then unmonitor
if failed permission 2555 then unmonitor
if failed uid root then unmonitor
if failed gid postdrop then unmonitor check file master_cf with path /etc/postfix/master.cf
group postfix
include /etc/monit/templates/rootrc check file main_cf with path /etc/postfix/main.cf
group postfix
include /etc/monit/templates/rootrc check file postfix_rc with path /etc/init.d/postfix
group postfix
include /etc/monit/templates/rootbin
Dovecot :
# Dovecot
check process dovecot with pidfile /run/dovecot/master.pid
start program = "/usr/sbin/service dovecot start"
stop program = "/usr/sbin/service dovecot stop"
if failed port 993 type tcpssl sslauto protocol imap then unmonitor
if failed host localhost port 143 type tcp protocol imap then restart
if failed port 993 for 5 cycles then restart
BIND9 :
# BIND9
check process bind with pidfile /var/run/named/named.pid
start program = "/etc/init.d/named start"
stop program = "/etc/init.d/named stop"
if failed host localhost port 53 type tcp protocol dns then restart
if failed host localhost port 53 type udp protocol dns then restart
if 5 restarts within 5 cycles then timeout
SSHD :
# SSHD
check process sshd with pidfile /var/run/sshd.pid
group system
group sshd
start program = "/etc/init.d/ssh start"
stop program = "/etc/init.d/ssh stop"
if failed host localhost port 22 with proto ssh then restart
if 5 restarts with 5 cycles then timeout
depend on sshd_bin
depend on sftp_bin
depend on sshd_rc
depend on sshd_rsa_key
depend on sshd_dsa_key check file sshd_bin with path /usr/sbin/sshd
group sshd
include /etc/monit/templates/rootbin check file sftp_bin with path /usr/lib/openssh/sftp-server
group sshd
include /etc/monit/templates/rootbin check file sshd_rsa_key with path /etc/ssh/ssh_host_rsa_key
group sshd
include /etc/monit/templates/rootstrict check file sshd_dsa_key with path /etc/ssh/ssh_host_dsa_key
group sshd
include /etc/monit/templates/rootstrict check file sshd_rc with path /etc/ssh/sshd_config
group sshd
include /etc/monit/templates/rootrc

Konfigurasi web interface Monit
Monit web server secara default berjalan pada localhost port 2812, dengan login akun “admin” dan password “monit”, anda dapat merubah pengaturan pada file /etc/monit/monitrc bagian :
....set httpd port 2812 and
use address localhost # only accept connection from localhost (drop if you use M/Monit)
allow localhost # allow localhost to connect to the server and
allow admin:monit # require user 'admin' with password 'monit'
allow @monit
allow @users readonly....
Anda dapat merubah port pada baris :
set httpd port 2812 and
Ubah 2812 dengan port yang anda inginkan (gunakan port diatas 1000 dan jangan sampai tabrakan dengan port yang lain).
Anda dapat mengakses monit secara lokal atau pun melalui internet (jika anda memiliki ip address public).
use address localhost # only accept connection from localhost (drop if you use M/Monit)
Anda dapat mengubah localhost dengan ip address public yang anda miliki.
Untuk mengubah user dan password admin ubah pada bagian :
allow admin:monit # require user 'admin' with password 'monit'
Anda dapat merubah monit dengan password admin yang anda inginkan (tidak diperkenankan menggunakan spasi).

Konfigurasi selesai, Simpan dan keluar dari Nano text editor (CTRL+S lalu CTRL+X).
Restart service monit dengan perintah :
sudo systemctl restart monit.service

Uji Coba Web Interface Monit
Untuk memastikan monit berjalan dengan benar anda dapat mengaksesnya dengan web browser, ketikkan alamat ini pada adress bar :
http://localhost:port
Ganti port dengan port yang telah anda tentukan tadi (jika anda tidak merubah port, port default monit adalah 2812).
Browser akan menampilkan promp login, login dengan user admin dan kata sandi yang telah anda tetapkan sebelumnya.

Jika anda berhasil login tampilannya kurang lebih akan seperti ini :

Anda dapat melakukan kontrol penuh (start/stop/restart) terhadap service yang dimonitoring.
Demikian cara Monitoring Sistem Service dengan Monit, Instalasi & Konfigurasi Monit Service Manager di Debian/Ubuntu, Semoga tutorial ini bermanfaat, Selamat mencoba.