웹사이트 검색

Monit - Linux 시스템 관리 및 모니터링 도구


Monit은 무료 오픈 소스이며 프로세스, 파일, 디렉터리, 디렉터리, 프로세스를 자동으로 모니터링하고 관리하는 매우 유용한 도구입니다. Strong>체크섬, 권한, 파일 시스템Apache, Nginx, 와 같은 서비스 UNIX/Linux 기반 시스템의 MySQL, FTP, SSH, SMTP 등 시스템 관리자에게 우수하고 유용한 모니터링 기능을 제공합니다.

monit에는 기본 HTTP(S) 웹 서버 또는 명령줄 인터페이스를 통해 시스템 상태를 직접 확인하고 프로세스를 설정할 수 있는 사용자 친화적인 웹 인터페이스가 있습니다. 즉, 모니터 웹 인터페이스에 액세스하고 보려면 시스템에 Apache 또는 Nginx와 같은 웹 서버가 설치되어 있어야 합니다.

모니트가 할 수 있는 일

Monit에는 프로세스가 실행되고 있지 않으면 시작하고, 응답하지 않으면 프로세스를 다시 시작하고, 리소스를 많이 사용하는 경우 프로세스를 중지하는 기능이 있습니다. 또한 Monit를 사용하여 파일, 디렉터리파일 시스템의 변경 사항, 체크섬 변경, < Strong>파일 크기 변경 또는 타임스탬프 변경.

Monit을 사용하면 원격 호스트의 TCP/IP 포트, 서버 프로토콜ping을 모니터링할 수 있습니다. Monit은 자체 로그 파일을 유지하고 심각한 오류 조건 및 복구 상태에 대해 경고합니다.

이 문서는 RHEL 기반 및 Debian 기반 Linux 배포판의 Monit 설치 및 구성에 대한 간단한 가이드를 설명하기 위해 작성되었습니다.

1단계: Linux에 Monit 설치

기본적으로 Monit 모니터링 프로그램은 기본 시스템 기본 저장소에서 사용할 수 없습니다. RHEL에 monit 패키지를 설치하려면 타사 epel 저장소를 추가하고 활성화해야 합니다. CentOS, Rocky LinuxAlmaLinux와 같은 기반 배포판.

--------- On RHEL 9 based Systems --------- 
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm 

--------- On RHEL 8 based Systems --------- 
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

--------- On RHEL 7 based Systems ---------
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

epel 저장소를 추가한 후 다음 yum 명령을 실행하여 Monit 패키지를 설치합니다.

yum install monit
OR
dnf install monit  [On Fedora Linux]

Ubuntu/Debian/Linux Mint의 경우 사용자는 그림과 같이 apt 명령을 사용하여 쉽게 설치할 수 있습니다.

sudo apt install monit

2단계: Linux에서 Monit 구성

Monit은 구성이 매우 쉽습니다. 실제로 구성 파일은 읽기 쉽고 사용자가 이해하기 쉽도록 만들어졌습니다. 2분마다 실행 중인 서비스를 모니터링하고 "/var/log/monit"에 로그를 유지하도록 설계되었습니다.

Monit에는 웹 서버를 사용하여 포트 2812에서 실행되는 웹 인터페이스가 있습니다. 웹 인터페이스를 활성화하려면 monit 구성 파일을 변경해야 합니다.

monit의 기본 구성 파일은 (RedHat/CentOS/Fedora) 및 /etc/monit/monitrc 아래의 /etc/monit.conf에 있습니다. (Ubuntu/Debian/Linux Mint)용 파일입니다.

선택한 편집기를 사용하여 이 파일을 엽니다.

vi /etc/monitrc
Or
sudo nano /etc/monit/monitrc

다음으로, 다음 섹션의 주석 처리를 제거하고 서버의 IP 주소 또는 도메인 이름을 추가하고 누구나 연결하고 monit 사용자 및 비밀번호를 변경할 수 있도록 허용하거나 기본 사용자 및 비밀번호를 사용할 수 있습니다.

set httpd port 2812 and
     use address 0.0.0.0  # only accept connections from localhost
     allow 0.0.0.0/0        # 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

구성한 후에는 monit 서비스를 시작, 활성화 및 확인하여 새 구성 설정을 다시 로드해야 합니다.

systemctl start monit
systemctl enable monit
systemctl status monit

이제 다음 URL로 이동하여 monit 웹 인터페이스에 액세스할 수 있습니다.

http://localhost:2812
OR
http://ip-address:2812
Or
http://example.com:2812

그런 다음 사용자 이름을 "admin"으로, 비밀번호를 "monit"로 입력합니다. 아래와 비슷한 화면이 나타납니다.

3단계: Monit 모니터링에 Linux 서비스 추가

monit 웹 인터페이스가 올바르게 설정되면 모니터링하려는 프로그램을 RedHat/CentOS/Fedora< 아래의 /etc/monitrc에 추가하기 시작합니다.) 및 /etc/monit/monitrc 파일(Ubuntu/Debian/Linux Mint)이 맨 아래에 있습니다.

다음은 monit에 대한 몇 가지 유용한 구성 예입니다. 이는 서비스 실행 방법, 프로필 유지 위치, 서비스 시작 및 중지 방법 등을 확인하는 데 매우 유용할 수 있습니다.

Monit에서 Apache 모니터링

check process httpd with pidfile /var/run/httpd.pid
group apache
start program = "/usr/bin/systemctl httpd start"
stop program = "/usr/bin/systemctl httpd stop"
if failed host 127.0.0.1 port 80
protocol http then restart
if 5 restarts within 5 cycles then timeout

Monit에서 Apache2 모니터링

check process apache with pidfile /run/apache2.pid
start program = "/usr/bin/systemctl apache2 start" with timeout 60 seconds
stop program  = "/usr/bin/systemctl apache2 stop"

Monit에서 Nginx 모니터링

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

Monit에서 MySQL 모니터링

check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group mysql
start program = "/usr/bin/systemctl mysqld start"
stop program = "/usr/bin/systemctl mysqld stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

Monit에서 SSH 모니터링

check process sshd with pidfile /var/run/sshd.pid
start program "/usr/bin/systemctl sshd start"
stop program "/usr/bin/systemctl sshd stop"
if failed host 127.0.0.1 port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout

모니터링할 모든 프로그램을 구성한 후 모니터 구문에 오류가 있는지 확인하세요. 오류가 발견되면 수정하세요. 무엇이 잘못되었는지 파악하는 것이 그리 어렵지 않습니다. '제어 파일 구문 확인'과 같은 메시지가 표시되거나 오류가 표시되지 않으면 계속 진행할 수 있습니다.

monit -t
Or
sudo monit -t

가능한 모든 오류를 수정한 후 다음 명령을 입력하여 monit 서비스를 시작할 수 있습니다.

systemctl monit restart
OR
sudo systemctl monit restart

모니터링을 위해 모든 Linux 서비스를 추가한 후 모니터의 모습입니다.