리눅스 서버는 살아 있는데,

특정 프로세스만 Down 되어 서비스가 먹통이 되는 때가 간혹 있다.

예를들어, 서버의 ICMP는 되나 nginx만 죽었다던지...그런 것이다.


방법을 찾던 중에 Monit 이라는 오픈소스를 알게 되었다.


- 설치

# On RedHat/CentOS(AMI)/Fedora/

yum install monit

# On Ubuntu/Debian/Linux Mint

apt-get install monit


# vi /etc/monit.conf   또는  vi /etc/monit/monitrc


주석 처리 된 내용 중 원하는 설정의 # 을 제거하여 활성화 한다.

set daemon  120           # check services at 2-minute intervals

 - 실행
service monit start
/etc/init.d/monit start

원하는 것을 골라서 실행 시키면 된다.

 - 사용자 설정 (모니터링)
vi /etc/monit/conf.d/httpd

check process httpd with pidfile /var/run/httpd.pid
    start program = "/etc/init.d/httpd start"
    stop program = "/etc/init.d/httpd stop"
    if failed host www.example.com port 80
      protocol HTTP request /alive.html then restart
    group httpd


vi /etc/monit/conf.d/nginx 

 check process nginx with pidfile /var/run/nginx.pid
   group nginx
   start program = "/etc/init.d/nginx start"
   stop program = "/etc/init.d/nginx stop"
   if failed 127.0.0.1 port 80 protocol http request "/check.html" then restart

 

vi /etc/monit/conf.d/mysql
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group mysql
start program = "/etc/init.d/mysqld start"
stop program = "/etc/init.d/mysqld stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

vi /etc/monit/conf.d/vsftpd

check process vsftpd with pidfile /var/run/vsftpd/vsftpd.pid
start program = "/etc/init.d/vsftpd start"
stop program = "/etc/init.d/vsftpd stop"
if failed host 127.0.0.1 port 21 then restart


stop start 프로그램이 없을 경우,

check process nginx with pidfile /var/run/nginx.pid
start program = "/opt/cac/sbin/nginx"
stop program = "/opt/cac/sbin/nginx -s stop"
if failed host 127.0.0.1 port 80 then restart

원하는 모니터링을 생성 후 설정 저장

- config 오류 확인
monit -t
Control file syntax OK

- monit 재실행
/etc/init.d/monit restart




 - 부팅시 monit 실행

vi /etc/rc.local

/usr/bin/monit cnrk







참고 url : https://mmonit.com/monit/documentation/monit.html

https://nolboo.kim/blog/2016/08/13/monitoring-linux-monit/



by 초보인척 2018. 10. 23. 11:27