Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

[Ubuntu] Monit 설치 및 설정

2017-06-28 by 편리

서버 모니터링 용도로 오픈소스 monit 을 사용하고 있다. 설치 및 설정이 간단하지만 기능은 강력하다. monit 공식사이트는 https://mmonit.com/monit/ 이다.

설치

$ sudo apt-get install monit

우분투 환경에서는 위 명령을 실행해서 monit을 설치할 수 있다. monit 설정은 /etc/monit 에서 한다. 설정 파일은 monitrc 이며 모니터링할 서비스 설정은 conf-available 디렉토리에 제공되고 있다. 아래는 기본 제공되는 설정 파일이다. 이 중 php7.0-fpm 파일은 별도로 추가한 것이다.

-rw-r--r-- 1 root root  481  2월 17  2016 acpid
-rw-r--r-- 1 root root  640  2월 17  2016 apache2
-rw-r--r-- 1 root root  455  2월 17  2016 at
-rw-r--r-- 1 root root  691  2월 17  2016 cron
-rw-r--r-- 1 root root  602  2월 17  2016 mdadm
-rw-r--r-- 1 root root  669  2월 17  2016 memcached
-rw-r--r-- 1 root root  703  2월 17  2016 mysql
-rw-r--r-- 1 root root  521  2월 17  2016 nginx
-rw-r--r-- 1 root root  471  2월 17  2016 openntpd
-rw-r--r-- 1 root root  950  2월 17  2016 openssh-server
-rw-r--r-- 1 root root  683  2월 17  2016 pdns-recursor
-rw-r--r-- 1 root root  305  6월 28 12:13 php7.0-fpm
-rw-r--r-- 1 root root 1421  2월 17  2016 postfix
-rw-r--r-- 1 root root  867  2월 17  2016 rsyslog
-rw-r--r-- 1 root root  501  2월 17  2016 smartmontools
-rw-r--r-- 1 root root  306  2월 17  2016 snmpd

monit 에서 모니터링할 서비스는 conf-enabled 에 넣어주면 되는데 나의 경우는 아래처럼 심볼릭 링크를 이용했다.

lrwxrwxrwx 1 root root   23  6월 28 12:15 mysql -> ../conf-available/mysql
lrwxrwxrwx 1 root root   23  6월 28 12:15 nginx -> ../conf-available/nginx
lrwxrwxrwx 1 root root   28  6월 28 12:15 php7.0-fpm -> ../conf-available/php7.0-fpm
$ sudo monit -t
$ sudo monit reload

-t 옵션으로 설정 파일의 오류를 체크할 수 있고 reload 로 설정을 다시 로드한다. php7.0-fpm 체크를 위한 설정은 아랭와 같다.

check process php7.0-fpm with pidfile /var/run/php/php7.0-fpm.pid
  group www #change accordingly
  start program = "/etc/init.d/php7.0-fpm start"
  stop program  = "/etc/init.d/php7.0-fpm stop"
  if failed unixsocket /var/run/php/php7.0-fpm.sock then restart
  if 3 restarts within 5 cycles then timeout

설정 중 pid 파일 등의 경로 및 파일명 등은 환경에 맞게 수정해야 한다. nginx 와 mysql은 기본 제공되는 설정 파일을 그대로 사용했다. monitrc 파일에서는 메일 관련 설정과 httpd를 통한 웹접속 환경을 수정한다.

# set mailserver mail.bar.baz,               # primary mailserver
#                backup.bar.baz port 10025,  # backup mailserver on port 10025
#                localhost                   # fallback relay
#
#
 set mailserver localhost      # primary mailserver

#

아래는 메일 내용 설정이다.

## --8<--
##
 set mail-format {
   from:    monit@example.com
   subject: monit alert --  $EVENT $SERVICE
   message: $EVENT Service $SERVICE
                 Date:        $DATE
                 Action:      $ACTION
                 Host:        $HOST
                 Description: $DESCRIPTION

            Your faithful,
            Monit
 }
## --8<--

경고 메일을 수신할 주소를 지정한다.

## You can set alert recipients whom will receive alerts if/when a 
## service defined in this file has errors. Alerts may be restricted on 
## events by using a filter as in the second example below.
#
 set alert example@example.com                       # receive all alerts

웹접속을 위한 httpd 설정은 아래와 같다.

## Monit has an embedded HTTP interface which can be used to view status of 
## services monitored and manage services from a web interface. The HTTP 
## interface is also required if you want to issue Monit commands from the
## command line, such as 'monit status' or 'monit restart service' The reason
## for this is that the Monit client uses the HTTP interface to send these
## commands to a running Monit daemon. See the Monit Wiki if you want to 
## enable SSL for the HTTP interface. 
#
 set httpd port 2812 and
     use address  192.168.0.1 # only accept connection from localhost
     allow 0.0.0.0/0.0.0.0        # allow localhost to connect to the server and
     allow monit:monit      # require user 'admin' with password 'monit'
#

포트는 2812를 사용하며 use address 192.168.0.1 부분은 서버의 ip로 변경한다. allow 0.0.0.0/0.0.0.0 는 모든 ip 에서의 접속을 허용하기 위함이고 allow monit:monit 는 웹접속 때 인증을 위한 아이디와 비밀번호이다. 만약 ufw 등의 방화벽을 사용하고 있다면 아래와 같이 2812 포트를 개방해줘야 한다.

$ sudo ufw allow 2812

d

monit 데몬을 재시작한 후 웨접속 등을 체크해본다. 쉘 접속에서는 아래 명령을 통해 상태를 확인할 수 있다.

$ sudo monit status

아래는 상태 출력 내용이다.

/etc/monit/monitrc:306: Include failed -- Success '/etc/monit/conf.d/*'
The Monit daemon 5.16 uptime: 2h 20m 

Process 'php7.0-fpm'
  status                            Running
  monitoring status                 Monitored
  pid                               914
  parent pid                        1
  uid                               0
  effective uid                     0
  gid                               0
  uptime                            4h 3m 
  threads                           1
  children                          33
  memory                            34.3 MB
  memory total                      1.0 GB
  memory percent                    0.4%
  memory percent total              13.0%
  cpu percent                       0.0%
  cpu percent total                 0.0%
  unix socket response time         0.039 ms to /var/run/php/php7.0-fpm.sock type TCP protocol DEFAULT
  data collected                    Wed, 28 Jun 2017 14:47:41

Process 'nginx'
  status                            Running
  monitoring status                 Monitored
  pid                               1036
  parent pid                        1
  uid                               0
  effective uid                     0
  gid                               0
  uptime                            4h 3m 
  threads                           1
  children                          8
  memory                            2.1 MB
  memory total                      51.5 MB
  memory percent                    0.0%
  memory percent total              0.6%
  cpu percent                       0.0%
  cpu percent total                 0.0%
  data collected                    Wed, 28 Jun 2017 14:47:41

File 'nginx_bin'
  status                            Accessible
  monitoring status                 Monitored
  permission                        755
  uid                               0
  gid                               0
  size                              1.2 MB
  timestamp                         Tue, 20 Jun 2017 00:13:37
  checksum                          f7a3de6c57b1ef56ee1f306cb4120b94 (MD5)
  data collected                    Wed, 28 Jun 2017 14:47:41

File 'nginx_rc'
  status                            Accessible
  monitoring status                 Monitored
  permission                        755
  uid                               0
  gid                               0
  size                              4.2 kB
  timestamp                         Tue, 20 Jun 2017 00:13:38
  checksum                          7224be660d7c280a775bd6eca2547df4 (MD5)
  data collected                    Wed, 28 Jun 2017 14:47:41

Process 'mysqld'
  status                            Running
  monitoring status                 Monitored
  pid                               1276
  parent pid                        1
  uid                               112
  effective uid                     112
  gid                               121
  uptime                            4h 3m 
  threads                           30
  children                          0
  memory                            477.2 MB
  memory total                      477.2 MB
  memory percent                    6.0%
  memory percent total              6.0%
  cpu percent                       0.0%
  cpu percent total                 0.0%
  port response time                0.404 ms to [localhost]:3306 type TCP/IP protocol MYSQL
  unix socket response time         0.098 ms to /var/run/mysqld/mysqld.sock type TCP protocol MYSQL
  data collected                    Wed, 28 Jun 2017 14:47:41

File 'mysql_bin'
  status                            Accessible
  monitoring status                 Monitored
  permission                        755
  uid                               0
  gid                               0
  size                              16.3 MB
  timestamp                         Tue, 20 Jun 2017 00:17:06
  checksum                          f6ba1cc1e4c291fd46c3820a5859ac84 (MD5)
  data collected                    Wed, 28 Jun 2017 14:47:41

File 'mysql_rc'
  status                            Accessible
  monitoring status                 Monitored
  permission                        755
  uid                               0
  gid                               0
  size                              5.6 kB
  timestamp                         Tue, 20 Jun 2017 00:17:09
  checksum                          7b92942b33eef917e2a702225ed77570 (MD5)
  data collected                    Wed, 28 Jun 2017 14:47:41

System 'example'
  status                            Running
  monitoring status                 Monitored
  load average                      [0.00] [0.00] [0.00]
  cpu                               0.0%us 0.0%sy 0.0%wa
  memory usage                      793.3 MB [10.0%]
  swap usage                        0 B [0.0%]
  data collected                    Wed, 28 Jun 2017 14:47:41

Monit Manual : https://mmonit.com/monit/documentation/monit.html

Post navigation

Previous Post:

Ubuntu 16.04 에서 리부팅 때 ufw 시작되지 않는 문제

Next Post:

[PHP] github webhook을 이용한 소스코드 서버 자동배포

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • SK 세븐모바일 유심 셀프교체
  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes