Tag

Saat ingin menggunakan fasilitas untuk melakukan testing terhadap sertifikat SSL, ternyata fasilitas tersebut hanya ada di monit versi yang terbaru (klik link https://mmonit.com/monit/dist/binary/ untuk melihat versi terbaru) , sedangkan di Ubuntu yang saya gunakan sekarang masih menggunakan versi lama.

$ sudo monit -V

Langkah kemudian adalah mematikan monit yang lama dan melakukan copy terhadap versi monit binary yang sesuai, di mana versi yang akan saya copy adalah untuk 64 bit.

PERHATIAN: Sampai di sini anda harus melakukan proses backup terhadap setting monit yang anda miliki.

$ cd /tmp
$ wget https://mmonit.com/monit/dist/binary/5.20.0/monit-5.20.0-linux-x64.tar.gz
$ tar -xf monit-5.20.0-linux-x64.tar.gz
$ cd monit-5.20.0
$ sudo service monit stop
$ sudo cp bin/monit /usr/bin/monit
$ sudo service monit restart
$ sudo monit -V
This is Monit version 5.20.0

Perhatikan bahwa Monit telah terupdate ke versi terakhir di versi 5.20.0.

Langkah berikutnya adalah melakukan update terhadap setting monit di monitrc.

$ sudo mv /etc/monit/monitrc /etc/monit/monitrc.ori
$ sudo touch /etc/monit/monitrc
$ sudo chmod 0700 /etc/monit/monitrc
$ sudo nano /etc/monit/monitrc
$ sudo ln -s /etc/monit/monitrc /etc/monitrc

Silahkan lakukan copy dengan isi yang baru …

set daemon 60 #check services every 60 seconds
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state

#Event queue
set eventqueue
basedir /var/lib/monit/events
# set the base directory where events will be stored
slots 100 # optionally limit the queue size

#Mail settings
# set mail-format {
# from: monit@$HOST
# subject: monit alert — $EVENT $SERVICE
# message: $EVENT Service $SERVICE
# Date: $DATE
# Action: $ACTION
# Host: $HOST
# Description: $DESCRIPTION
#
# Your faithful employee,
# Monit }
# set mailserver smtp.gmail.com port 587
# username “wp” password “bullet”
# using TLSV1 with timeout 30 seconds
# set alert admin@wp-bullet.com #email address which will receive monit alerts

#http settings
# set httpd port 2812 address 0.0.0.0
# allow port 2812 connections on all network adapters
# ssl enable
# pemfile /var/certs/monit.pem
# allow 0.0.0.0/0.0.0.0 # allow all IPs, can use local subnet too
# allow wp-bullet.crabdance.com # allow dynamicdns address to connect
# allow wp:”bullet” # require user wp with password bullet

#allow modular structure
include /etc/monit/conf.d/*.conf
# include /etc/monit/conf-enabled/*

Pada setting di atas untuk lebih modular saya akan menyimpan setting untuk monitoring service di folder /etc/monit/conf.d/ dengan ekstensi file adalah conf.

Untuk memastikan semua berjalan baik-baik saja lakukan check …

$ sudo monit -t

Kalau berjalan baik, coba tambahkan berikut untuk melakukan monitoring ssh di port 1429.

# file di /etc/monit/conf.d/sshd.conf
check process sshd with pidfile /var/run/sshd.pid
start program "/usr/sbin/service ssh start"
stop program "/usr/sbin/service ssh stop"
if failed port 1428 protocol ssh then restart
if 5 restarts within 5 cycles then timeout

Kemudian tambahkan lagi untuk check apache …

#file di /etc/monit/conf.d/apache.conf
check process apache with pidfile /var/run/apache2/apache2.pid
group www
start program = "/usr/sbin/service apache2 start"
stop program = "/usr/sbin/service apache2 stop"
if failed host localhost port 80 protocol http
#and request "/monit/token"
then restart
if cpu is greater than 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if totalmem > 500 MB for 5 cycles then restart
if children > 250 then restart
if loadavg(5min) greater than 10 for 8 cycles then stop
if 3 restarts within 5 cycles then timeout

Lakukan kembali check terhadap konfigurasi …

$ sudo monit -t

Kalau sudah oke lakukan restart service

$ sudo service monit restart

Lalu lakukan testing dengan mematikan service apache2.

$ sudo service apache2 stop

Check pada bagian log apakah monit berjalan? Bila berjalan semestinya ada pesan bahwa apache2 berhenti dan monit melakukan restart terhadap service apache2. Seperti ini kurang lebih contohnya pada salah satu box server yang kami punyai …

$ sudo tail -f /var/log/monit.log
[WIB Feb 7 09:50:20] error : 'apache' process is not running
[WIB Feb 7 09:50:20] info : 'apache' trying to restart
[WIB Feb 7 09:50:20] info : 'apache' start: '/usr/sbin/service apache2 start'
[WIB Feb 7 09:51:22] info : 'kpukaltengprov' connection succeeded to [kpu-kaltengprov.go.id]:443 [TCP/IP SSL]
[WIB Feb 7 09:51:22] info : 'apache' process is running with pid 861

Referensi: