Monit Aplikasi Linux Untuk Menjaga Service Server Tetap Jalan

Monit Aplikasi Linux Untuk Menjaga Service Server Tetap Jalan

Aplikasi monit yaitu aplikasi yang berfungsi untuk memonitor aplikasi yang jalan di server. Mengapa aplikasi diserver perlu dilakukan monitoring? ada beberapa alasan antara lain :

  1. Aplikasi diserver tidak 100% baik, sebagai misal aplikasi yang jalan 24 jam kemungkinan ada kelemahan manajemen memory (memory leak) selalu ada walaupun kecil. Apabila ini dibiarkan terus dapat menyebabkan sumberdaya (resource) server khususnya memory menjadi penuh an perlu dikosongkan, yaitu dengan cara paling mudah restart aplikasi atau restart servernya
  2. Aplikasi di server dalam beban kecil dapat berjalan dengan baik, akan tetapi ketika ada beban besar, misal yang akses tiba tiba datang dalam jumlah ribuan bersamaan dan menyebabkan aplikasi bahkan server menjadi hank

Aplikasi kecil monit ini mempunyai fungsi adalah memonitor aplikasi server yang kita daftarkan di monit, apabila terjadi sesuatu di aplikasi server berdasarkan pengecekan monit maka akan dilakukan sesuai oleh monit.

Pengecekan monit dapat dilakukan antara lain :

  1. Cek apakah port layanan server aktif
  2. Cek apakah file .pid ada atau tidak

Aksi yang dilakukan monit yang melakukan restart aplikasi ataupun restart server.

Dalam artikel ini saya menggunakan centos 5.4, dan tahapan instalasi yang dilakukan yaitu :

  1. Aktifkan repository rpmforge
  2. jalankan install monit

    # yum install monit –disablerepo=* –enablerepo=rpmforge

    Loaded plugins: fastestmirror

    Loading mirror speeds from cached hostfile

    * rpmforge: apt.sw.be

    rpmforge | 1.1 kB 00:00

    rpmforge/primary | 2.3 MB 01:16

    rpmforge 10725/10725

    Setting up Install Process

    Resolving Dependencies

    –> Running transaction check

    —> Package monit.i386 0:5.2.5-1.el5.rf set to be updated

    –> Finished Dependency Resolution

    Dependencies Resolved

    ================================================================================================================

    Package Arch Version Repository Size

    ================================================================================================================

    Updating:

    monit i386 5.2.5-1.el5.rf rpmforge 560 k

    Transaction Summary

    ================================================================================================================

    Install 0 Package(s)

    Upgrade 1 Package(s)

    Total download size: 560 k

    Is this ok [y/N]: y

    Downloading Packages:

    monit-5.2.5-1.el5.rf.i386.rpm | 560 kB 00:19

    Running rpm_check_debug

    Running Transaction Test

    Finished Transaction Test

    Transaction Test Succeeded

    Running Transaction

    Updating : monit 1/2

    Cleanup : monit 2/2

    Updated:

    monit.i386 0:5.2.5-1.el5.rf

    Complete!

  3. Hasil instalasi akan membuat file “/etc/monit.conf” yang berisi contoh file konfigurasi dan membuat sebuah folder “/etc/monit.d/” yang bisa kita isi dengan file konfigurasi kita.
  4. Tahap terakhir adalah menulis konfigurasi monit yang berisikan aplikasi a-plikasi server apa saja yang akan dimonitor.

Contoh konfigurasi :

1. Server, yaitu fungsi untuk remote akses monit melalui webserver. Untuk pembatasan akses bisa melalui alamat IP ataupun user dan password

set httpd port 2812

allow monit:monit

# use address localhost # only accept connection from localhost

# allow localhost # allow localhost to connect to the server and

# allow admin:monit # require user ‘admin’ with password ‘monit’

# allow @monit # allow users of group ‘monit’ to connect (rw)

# allow @users readonly # allow users of group ‘users’ to connect readonly

#

2. Apache webserver

check process httpd with pidfile /var/run/httpd.pid

start program = “/etc/init.d/httpd start” with timeout 60 seconds

stop program = “/etc/init.d/httpd stop”

if cpu > 60% for 2 cycles then alert

if cpu > 80% for 5 cycles then restart

if totalmem > 450.0 MB for 5 cycles then restart

if children > 250 then restart

 

if loadavg(5min) greater than 10 for 8 cycles then stop

if failed host 127.0.0.1 port 80 protocol http

then restart

if 3 restarts within 5 cycles then timeout

group server

Konfigurasi nomor 2 diatas apat dijelaskan sebagai berikut :

– Status apache webs server dimonitor melalui filepid /var/run/httpd.pid

– Proses restart aplikasi dilakukan melalui start dan stop program

– Apabila CPU 60% dalam 2 periode pengecekan maka akan memberikan alert

– Apabila CPU 80% dalam 5 periode pengecekan maka akan memberikan warning

– Apabila total memory yang terpakai lebih besar 450MB selama 5 periode maka restart

– Apabila jumlah proses apache mencapai 250, maka restart

– Apabila port 80 protokol http (tcp) gagal diakses, maka webserver akan di restart

– Apabila restart terjadi 5x, maka monitoring dihentikan

3. LDAP dengan openldap

check process ldap with pidfile /var/run/openldap/slapd.pid

start program = “/etc/init.d/ldap start” with timeout 60 seconds

stop program = “/etc/init.d/ldap stop”

if failed port 389 use type tcp

then restart

if 3 restarts within 5 cycles then timeout

group server

4. MySQL

check process mysqld with pidfile /var/run/mysqld/mysqld.pid

start program = “/etc/init.d/mysqld start” with timeout 60 seconds

stop program = “/etc/init.d/mysqld stop”

if cpu > 60% for 2 cycles then alert

if cpu > 80% for 5 cycles then restart

if totalmem > 300.0 MB for 5 cycles then restart

if loadavg(5min) greater than 10 for 8 cycles then stop

if failed host 127.0.0.1 port 3306

then restart

if failed unixsocket /var/lib/mysql/mysql.sock protocol mysql

then restart

group database

5. snmp

check process snmpd with pidfile /var/run/snmpd.pid

start program = “/etc/init.d/snmpd start” with timeout 60 seconds

stop program = “/etc/init.d/snmpd stop”

if failed port 161 use type udp

then restart

if 3 restarts within 5 cycles then timeout

group server

Langkah terakhir yaitu menjalankan monit. Pada setiap server perintah menjalankan monit saya masukkan dalam file “/etc/rc.local” yang dieksekusi setiap kali server start.

/usr/bin/monit -c /etc/monit.conf -l /var/log/monit.log -p /var/run/monit.pid -d 120 -v

monit: Debug: Adding credentials for user ‘monit’.

monit: Error opening the idfile ‘/var/monit/id’ — No such file or directory

——————————————————————————-

/usr/bin/monit [0x805442e]

/usr/bin/monit(LogError+0×22) [0x8054842]

/usr/bin/monit(Util_monitId+0×2da) [0x806149a]

/usr/bin/monit(File_init+0×3e) [0x80525fe]

/usr/bin/monit(main+0×545) [0x80570f5]

/lib/libc.so.6(__libc_start_main+0xdc) [0x383e9c]

/usr/bin/monit [0x804ee51]

——————————————————————————-

Runtime constants:

Control file = /etc/monit.conf

Log file = /var/log/monit.log

Pid file = /var/run/monit.pid

Debug = True

Log = True

Use syslog = False

Is Daemon = True

Use process engine = True

Poll time = 120 seconds with start delay 0 seconds

Expect buffer = 256 bytes

Mail from = (not defined)

Mail subject = (not defined)

Mail message = (not defined)

Start monit httpd = True

httpd bind address = Any/All

httpd portnumber = 2812

httpd signature = True

Use ssl encryption = False

httpd auth. style = Basic Authentication

The service list contains the following entries:

Process Name = snmpd

Group = server

Pid file = /var/run/snmpd.pid

Monitoring mode = active

Start program = ‘/etc/init.d/snmpd start’ timeout 60 second(s)

Stop program = ‘/etc/init.d/snmpd stop’ timeout 30 second(s)

Existence = if does not exist 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

Pid = if changed 1 times within 1 cycle(s) then alert

Ppid = if changed 1 times within 1 cycle(s) then alert

Port = if failed localhost:161 [DEFAULT via UDP] with timeout 5 seconds 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

Timeout = If restarted 3 times within 5 cycle(s) then unmonitor

Process Name = mysqld

Group = database

Pid file = /var/run/mysqld/mysqld.pid

Monitoring mode = active

Start program = ‘/etc/init.d/mysqld start’ timeout 60 second(s)

Stop program = ‘/etc/init.d/mysqld stop’ timeout 30 second(s)

Existence = if does not exist 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

Pid = if changed 1 times within 1 cycle(s) then alert

Ppid = if changed 1 times within 1 cycle(s) then alert

Unix Socket = if failed /var/lib/mysql/mysql.sock [protocol MYSQL] with timeout 5 seconds 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

Port = if failed 127.0.0.1:3306 [DEFAULT via TCP] with timeout 5 seconds 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

Load avg. (5min) = if greater than 10.0 8 times within 8 cycle(s) then stop else if succeeded 1 times within 1 cycle(s) then alert

Children = if greater than 1000 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

Memory amount limit (incl. children) = if greater than 307201 5 times within 5 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

CPU usage limit = if greater than 80.0% 5 times within 5 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

CPU usage limit = if greater than 60.0% 2 times within 2 cycle(s) then alert else if succeeded 1 times within 1 cycle(s) then alert

Process Name = ldap

Group = server

Pid file = /var/run/openldap/slapd.pid

Monitoring mode = active

Start program = ‘/etc/init.d/ldap start’ timeout 60 second(s)

Stop program = ‘/etc/init.d/ldap stop’ timeout 30 second(s)

Existence = if does not exist 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

Pid = if changed 1 times within 1 cycle(s) then alert

Ppid = if changed 1 times within 1 cycle(s) then alert

Port = if failed localhost:389 [DEFAULT via TCP] with timeout 5 seconds 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

Timeout = If restarted 3 times within 5 cycle(s) then unmonitor

Process Name = httpd

Group = server

Pid file = /var/run/httpd.pid

Monitoring mode = active

Start program = ‘/etc/init.d/httpd start’ timeout 60 second(s)

Stop program = ‘/etc/init.d/httpd stop’ timeout 30 second(s)

Existence = if does not exist 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

Pid = if changed 1 times within 1 cycle(s) then alert

Ppid = if changed 1 times within 1 cycle(s) then alert

Port = if failed 127.0.0.1:80 [HTTP via TCP] with timeout 5 seconds 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

Load avg. (5min) = if greater than 10.0 8 times within 8 cycle(s) then stop else if succeeded 1 times within 1 cycle(s) then alert

Children = if greater than 250 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

CPU usage limit = if greater than 80.0% 5 times within 5 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert

CPU usage limit = if greater than 60.0% 2 times within 2 cycle(s) then alert else if succeeded 1 times within 1 cycle(s) then alert

System Name = system_ldapdev

Monitoring mode = active

——————————————————————————-

monit: pidfile ‘/var/run/monit.pid’ does not exist

Starting monit daemon with http interface at [*:2812]

Semoga aplikasi monit dapat bermanfaat bagi anda semua. Amien

Lampiran :

htttp://www.stisitelkom.ac.id

monit-system

monit-snmp

monit-mainpage
http://kusprayitna.staff.uii.ac.id/

 

 

 

www.stisitelkom.ac.id www.di.stisitelkom.ac.id www.ktm.stisitelkom.ac.id

www.dkv.stisitelkom.ac.id www.dp.stisitelkom.ac.id www.srm.stisitelkom.ac.id

www.blog.stisitelkom.ac.id www.multimedia.stisitelkom.ac.id

www.elearning.stisitelkom.ac.id www.library.stisitelkom.ac.id

www.digilib.stisitelkom.ac.id www.mirror.stisitelkom.ac.id

www.sisfo.stisitelkom.ac.id www.hilfan.blog.stisitelkom.ac.id

www.hilfans.wordpress.com www.hilfan-s.blogspot.com www.askaf.co.id

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s