Jump to content

Monit

From DawoumWiki, the free Mathematics self-learning
Monit
Developer(s)Tildeslash Ltd
Stable release
5.32.0 / March 23, 2022; 2 years ago (2022-03-23)[1]
Repositorybitbucket.org/tildeslash/monit/overview
Written inC[2]
Available inEnglish
TypeProcess supervision
LicenseAGPL 3.0
Websitemmonit.com/monit/

Monit유닉스리눅스에 대해 자유와 오픈-소스 프로세스 감독 도구입니다. Monit과 함께, 시스템 상태는 명령 줄에서 직접 보거나, 기본 HTTP(S) 웹 서버를 통해 볼 수 있습니다. Monit은 오류 상황에서 자동 유지보수와 복구를 수행하고 의미있는 인과 관계 작업을 수행할 수 있습니다.[3] Monit은 Ruby on RailsMongrel 웹 서버와 함께 인기를 얻었는데, 왜냐하면 확장성있는 Ruby on Rails 사이트를 지원하기 위해 실행해야 하는 많은 동일한 Mongrel 프로세스를 관리할 수 있는 도구가 필요했었고, Monit은 Ruby on Rails 커뮤니티의 요구에 고유하게 상당히 적합했습니다.[4] 많은 대중적인 Rails 사이트는, Twitter[5]scribd[6] 포함하여, Monit을 사용해오고 있습니다.

Monit은 프로세스가 죽거나 메모리 또는 CPU 주기와 같은 프로세스 특성을 모니터링하고 이메일로 알림을 보내거나[7] 실행과 동작과 같은 프로세스를 자동으로 다시 시작할 수 있습니다.[7]

추가적으로 M/Monit은 분산 컴퓨터 시스템을 모니터링하고 관리할 수 있고, M/Monit은 Monit을 에이전트로 사용하고 관리와 모니터링할 수 있습니다. M/Monit은 라이선스가 부여된 소프트웨어입니다.

Installation

데비안 저장소에서 설치할 수 있습니다:

  • sudo apt-get install monit

Configuration

Monit config file

monit 프로그램은 /etc/monit/monitrc 설정 파일을 활용합니다.

시스템 모니터링 정의를 쉽게 추가하거나 제거하기 위해서, monit은 상술된 디렉토리 내부의 파일들을 설정에 포함하는 것을 지원합니다. 설정 파일 /etc/monit/monitrc에서 이 부분을 아래와 같이 변경할 수 있습니다:

# 우편으로 알려줄 내용을 정합니다.
set alert user@email.com not on { instance }
## It is possible to include additional configuration parts from other files or
## directories.
#
   include /etc/monit/conf.d/*
   include /etc/monit/conf-enabled/*

어떤 내용을 전자-우편으로 보낼지 경고-메시지 목록을 보고 선택할 수 있습니다.

monit과 관련된 설정 파일을 바꾸고 나면 monit이 바뀐 설정을 다시 읽게 해야 합니다.

  • sudo monit reload

Monit auto startup

monit/etc/init/monit.conf 설정으로 시작하여 init 자체에서 monit 프로그램을 시작하도록 하고 monit이 갑자기 죽었을 때 자동으로 다시 시작하도록 하는 것이 좋습니다.[8]

description "Monit service manager"

limit core unlimited unlimited

start on runlevel [2345]
stop on starting rc RUNLEVEL=[016]

expect daemon
respawn

exec /usr/bin/monit -c /etc/monit/monitrc

pre-stop exec /usr/bin/monit -c /etc/monit/monitrc quit

설정을 추가하고 나면 다시 읽어 드리도록 명령해야 합니다.

  • sudo monit reload

Systemd Init script

Systemd 서비스를 이용할 경우에는 /lib/systemd/system/monit.service 파일을 만듭니다.[9]

[Unit]
Description=Pro-active monitoring utility for unix systems
After=network.target

[Service]
Type=simple
KillMode=process
ExecStart=/usr/bin/monit -I -c /etc/monit/monitrc
ExecStop=/usr/bin/monit -c /etc/monit/monitrc quit
ExecReload=/usr/bin/monit -c /etc/monit/monitrc reload

[Install]
WantedBy=multi-user.target

파일을 생성하셨다면 아래와 같이 서비스를 시작하고, 시작시에 자동으로 시작하도록 설정할 수 있습니다.

  • sudo systemctl start monit
  • sudo systemctl enable monit

Manage users

사용자를 monit 또는 users 그룹에 추가하면 해당 사용자는 웹 인터페이스를 통해 monit에 접근할 수 있습니다.

이 그룹에 사용자를 추가하려면 gpasswd 명령을 사용해야 합니다.[10]

  • sudo gpasswd -a $USER monit
  • sudo gpasswd -a $USER users

/etc/moint/monitrc 파일에서 allow 구문은 이 그룹을 다음과 같이 참조해야합니다:

 set httpd port 2812 and
     use address localhost  # only accept connection from localhost
     allow localhost        # allow localhost to connect to the server and
     allow @users           # allow members of @users group
#     allow admin:monit      # require user 'admin' with password 'monit'

monitrc 파일에 하드코딩한 사용자 이름 및 암호를 넣을 수 있습니다만, 추천하지 않습니다. monitrc 파일에 기본 암호가 있는지 확인하고, 제거하거나 더 강력하고 특별한 암호로 바꾸는 것을 추천합니다. 여기서 사용하는 설정 방식은 allow <username>:<password>입니다.

Monit web service

웹 인터페이스 기본 위치는 localhost:2812이며 @users에 등록한 사용자이름과 암호로 접근할 수 있습니다.

monit으로 프로그램 감시

monit 프로그램은 PID 파일을 사용하여 프로그램이 여전히 동작중인지를 확인합니다. PID 파일은 프로그램이 실행하는동안 반드시 있어야 하며, 그렇지 않으면 monit의 실행 여부를 보장하지 못합니다. 데몬에서 PID 파일을 만들지 않으면 래퍼en로 PID 파일을 만드십시오.

감시 목적의 PID 파일 활용(및 ps와 같은 도구로 PID 검증)은 종종 문제가 나타납니다.[11] Monit은 이런 취약점을 극복하기 위해 PID 파일을 좀 더 자주 점검하여 신뢰성을 높입니다.

/etc/monit/conf-enabled 또는 /etc/monit/conf.d 위치를 활용하면 감시 규칙을 쉽게 추가할 수 있습니다.

monit이 설치되면 감시할 프로그램에 대한 설정이 /etc/monit/conf-available에 존재합니다. 여기서 필요한 프로그램을 /etc/monit/conf-enabled에 심볼릭 링크를 걸어주면 됩니다.

  • cd /etc/monit/conf-enabled
  • sudo ln -sf /etc/monit/conf-available/memcached .
  • sudo ln -sf /etc/monit/conf-available/mysql .
  • sudo ln -sf /etc/monit/conf-available/nginx .
  • sudo ln -sf /etc/monit/conf-available/postfix .

그러나 memcached는 현재 pid 파일이 존재하지 않기 때문에 /etc/monit/conf-available/memcached 파일 수정이 필요합니다.[12]

 check process memcached with match memcached
   group cache
   group memcache

그룹도 memcached가 존재하지 않으므로 memcache로 바꾸어 줍니다.

만약 새롭게 감시할 프로그램 중에 프로세스의 메모리 사용량이 설정한 한계점을 넘었을 때, 예를 들어, /etc/monit/conf.d/squid 파일에, 경고를 나타내도록 합니다:

 check process squid with pidfile /var/run/squid.pid
   start program = "/bin/systemctl start squid"
   stop program = "/bin/systemctl stop squid"
   if totalmem > 512 MB then alert

php5.6-fpm이 기동하도록 /etc/monit/conf.d/php5.6-fpm 파일에 설정해 봅니다.

check process php5.6-fpm with pidfile /var/run/php/php5.6-fpm.pid
  group www-data
  start program = "/bin/systemctl start php5.6-fpm"
  stop program  = "/bin/systemctl stop php5.6-fpm"
  if failed unixsocket /var/run/php/php5.6-fpm.sock then restart
  if 3 restarts within 5 cycles then timeout

이 이외의 설정들은 github에서 구할 수 있습니다.

monit debugging

monit 전면 실행

monit을 전면에서 실행하고 감지하는 모든 상황에 대한 피드백을 받으려면 -lvv 옵션을 사용하십시오:

  • sudo monit -Ivv
...
'squid' total mem amount of 525748kB matches resource limit [total mem amount>524288kB]

이제 monit 자체의 설정은 끝났습니다. 이제 monit에서 감시하고 있는 상황을 이미 동작하고 있는 postfix에 전달하도록 설정해 볼 차례입니다.

Postfix config

우선은 시스템에서 이상이 생겼을 때 메일을 발송해야 하므로 메일 서버를 반드시 설정을 해야 합니다.

Monit config

Monit에서 메일을 발송할 수 있도록 /etc/monit/monitrc 설정을 해야 합니다.

 set mailserver localhost                                # 76 줄 

 set mail-format {                                       # 108 줄 
   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 alert username@localhost not on { instance, action }  # 138 줄 

  check system $HOST                                     # 163 줄 
    if loadavg (1min) > 4 then alert
    if loadavg (5min) > 2 then alert
    if cpu usage > 95% for 10 cycles then alert
    if memory usage > 75% then alert
    if swap usage > 25% then alert

 check filesystem rootfs with path /                     # 170 줄 추가함.
    if space usage > 90% then alert

시스템의 메일 서버에서 사용자의 정해진 시스템 자원이상을 사용하게 되면 username@localhost로 정해진 형식에 따라 메일을 보내줍니다.

Troubleshootings

Monit/Troubleshootings

References

  1. ^ "Monit Updates and Release Notes". Retrieved 17 May 2022.
  2. ^ "tildeslash / Monit". Bitbucket. Atlassian. Retrieved 25 November 2014.
  3. ^ Pott, Kyle (2007-08-01). "Monitor Ubuntu services with Monit". Lifehacker. Retrieved 2018-09-30.
  4. ^ Ruby on Rails author talks about Monit and mongrel Archived 2011-04-24 at the Wayback Machine
  5. ^ Sandofsky, Ben (2010-03-30). "Unicorn Power | Twitter Blogs". Engineering.twitter.com. Retrieved 2013-08-20.
  6. ^ stark (2007-05-13). "Scaling Scribd". Slideshare.net. Retrieved 2013-08-20.
  7. ^ a b "Monit Manual".
  8. ^ 이 내용은 /usr/share/doc/monit/examples/monit.upstart 파일에 있습니다.
  9. ^ 이 내용은 /usr/share/doc/monit/examples/monit.service 파일에 있습니다.
  10. ^ 우분투에는 monit 그룹이 없습니다.
  11. ^ Greg Wooledge. Process management, Retrieved on January 1st, 2015
  12. ^ 기본으로 제공되는 설정파일과 시스템에 설치된 프로그램과는 맞지 않는 부분이 존재합니다. 오류 로그를 보고 수정을 하거나, 직접 파일을 열어서 일일이 확인한 후에 추가하시기 바랍니다.

External Resources