OS

2022.04.13 17:14

Linux 프로세스 모니티링 및 자동 시작(monit)

  • 비아웹 오래 전 2022.04.13 17:14 인기
  • 5,088
    0

안녕하세요

서버호스팅 비아웹입니다.

리눅스 서버를 운영하다 보면 서버 Down 이 아닌, Process down 이 발생하는 경우가 종종 있습니다.

서비스 공격이나 리소스 부족으로 인한 Out of Memory 발생으로 인한 Process down 이 야간이나 주말에 발생시 담당자 인지까지 장애가 지속되는 경우가 있습니다.

Linux 서버상에서 등록된 프로세스를 모니터링 및 해당 프로세스 down 시 start 시켜주는 monit 에 대해 기록합니다.

 

1. 테스트 환경

CentOS 7.9 minimal

 

2. 설치

# yum install epel-release 

# yum install monit

m01.JPG

 

 

3. 환경 설정 파일 /etc/monitrc

set daemon 30 # 30초 단위로 check 

 

# http://server_IP:2812

    id : admin / password : monit 

 

set httpd port 2812 and 

     use address 192.168.80.158 # 서버 IP 

     allow 192.168.80.0/24 # 접속 허용 IP 

     allow admin:monit # require user 'admin' with password 'monit' 

     #with ssl { # enable SSL/TLS and set path to server certificate 

     # pemfile: /etc/ssl/certs/monit.pem 

     #}

         m02.JPG

 

 

4. 설정 파일 테스트

# monit -t

    2812 port open       m03.JPG 

 

 

5. 웹 모니터링 페이지

   http://서버IP:2812

m04.JPG

 

 

6. apache 모니터링 설정

/etc/monit.d/httpd

 

 
check process httpd with pidfile /var/run/httpd/httpd.pid 
start program = "/usr/bin/systemctl start httpd" 
stop program = "/usr/bin/systemctl stop httpd"

 

 

7. apache 모니터링 테스트

: killall -9 httpd 을 통한 apache 강제 종료 후 모니터링

m05.JPG

 

m06.JPG


8. 추가 모니터링 설정

- nginx

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

start program = "/usr/bin/systemctl start nginx" 

stop program = "/usr/bin/systemctl stop nginx"

 

- mariadb

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

group mysql 

start program = "/usr/bin/systemctl start mariadb" 

stop program = "/usr/bin/systemctl stop mariadb" 

if failed host 127.0.0.1 port 3306 then restart 

if 5 restarts within 5 cycles then timeout

 

- sshd

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

start program "/usr/bin/systemctl start sshd" 

stop program "/usr/bin/systemctl stop sshd" 

if failed host 127.0.0.1 port 22 protocol ssh then restart 

if 5 restarts within 5 cycles then timeout

 

9. bash shell 상에서 상태 체크

# monit status

 

m08.JPG

 

이상과 같이 프로세스에 대해 

서버 내부에서 자체적으로 모니터링 하는 방법 중 하나인 monit 에 대해 정리하였습니다.

 

감사합니다.

서버호스팅 비아웹

 

 

  • 공유링크 복사

    댓글목록

    등록된 댓글이 없습니다.