GNU/Linux >> Linux の 問題 >  >> Ubuntu

Monitをインストールおよび構成する方法。

はじめに

Monitは、サーバープログラムを自動的に監視および管理して、サーバープログラムが常にオンラインであるだけでなく、ファイルサイズ、チェックサム、またはアクセス許可が常に正しいことを確認する便利なプログラムです。

# yum install monit ( To install monit On RedHat/CentOS/Fedora/ )

# sudo apt-get install monit ( To install monit On Ubuntu/Debian )

Monitデーモンを構成する

# vi /etc/monit.conf ( Configuration file in RedHat/CentOS/Fedora/ )

# vi /etc/monit/monitrc ( Configuration file in Ubuntu/Debian )

今すぐ設定ファイルを監視するためのサービスを追加します

構成ファイルを開きます。つまり、

For RedHat/CentOS/Fedora (# vi /etc/monit.conf)
For Ubuntu/Debian (# vi /etc/monit/monitrc)

設定ファイルのすべての行を削除し、以下の行を追加します。 (すべての行は以下に簡単に定義されています)

デーモン間隔を設定

これは、Monitがテストを実行する間隔(秒単位)です。選択する値は、定義するテストの数によって異なります。この値を変更する場合は、Monitを再起動する必要があります。

# check services at 30 seconds of intervals
set daemon 30

ログファイルを設定

# set logfile syslog facility log_daemon                       
set logfile /var/log/monit.log

メモリ使用量の設定を確認して再インストールします

##To check the memory usage and restart the services.    
	check system localhost
    	if memory usage > 93%
        then exec "/usr/local/bin/httpd-start"
を実行します。

HTTPDサービスを確認して再起動します

ここで、Httpdサービスはmonitによって監視されます。つまり、サービスが実行されていない場合、またはloadavgがそれ以上の場合、monitはhttpdサービスを実行して再起動します

#To check the Httpd service and restart the services.
# Httpd
        check process httpd with pidfile /var/run/httpd/httpd.pid
        start program = "/usr/local/bin/httpd-start"
        stop program = "/usr/local/bin/httpd-kill"
        if loadavg (1min) greater than 10 for 1 cycles then restart

mysqldサービスを確認して再起動します

ここで、Mysqldサービスはmonitによって監視されます。つまり、サービスが実行されていない場合、またはloadavgがそれ以上の場合、monitはMysqlサービスを実行して再起動します

#To check the mysql service and restart the services.
# mysqld
        check process mysqld with pidfile /var/run/mysqld/mysqld.pid
        start program = "/etc/init.d/mysqld start"
        stop program = "/etc/init.d/mysqld stop"
        if memory usage > 70% for 1 cycles then restart
        if failed host 127.0.0.1 port 3306 then restart
        if loadavg (1min) greater than 5 for 1 cycles then restart

同じように、監視して再起動する必要があるサービスを追加できます

すべてのサービスが構成ファイルに追加されたら。設定ファイルは次のようになります。

# check services at 2-minute intervals
set daemon 30
# set logfile syslog facility log_daemon                       
set logfile /var/log/monit.log
##To check the memory usage and restart the services.    
	check system localhost
    	if memory usage > 93%
        then exec "/usr/local/bin/httpd-start"

#To check the Httpd service and restart the services.
# Httpd
        check process httpd with pidfile /var/run/httpd/httpd.pid
        start program = "/usr/local/bin/httpd-start"
        stop program = "/usr/local/bin/httpd-kill"
        if loadavg (1min) greater than 10 for 1 cycles then restart

#To check the mysql service and restart the services.
# mysqld
        check process mysqld with pidfile /var/run/mysqld/mysqld.pid
        start program = "/etc/init.d/mysqld start"
        stop program = "/etc/init.d/mysqld stop"
        if memory usage > 70% for 1 cycles then restart
        if failed host 127.0.0.1 port 3306 then restart
        if loadavg (1min) greater than 5 for 1 cycles then restart

注:構成ファイルで次の行を定義したので

start program =“ / usr / local / bin / httpd-start”
stop program =“ / usr / local / bin / httpd-kill”

httpd-start、httpd-killスクリプトを追加する必要があります。つまり

次のコマンドでファイルを作成し、次の行を追加します

vi /usr/local/bin/httpd-start
#!/bin/bash
/usr/bin/killall -9 httpd; /usr/bin/killall -9 php-cgi; /usr/bin/ipcs |grep apache | /bin/cut -d" " -f2 | /usr/bin/xargs /usr/bin/ipcrm sem {};
/bin/sleep .5;
/usr/sbin/apachectl start
#/sbin/swapoff -a
#/sbin/swapon -a
exit 0;

コマンドを使用して保存して終了します

 :wq!

httpd-killスクリプトについても同じです

次のコマンドでファイルを作成し、次の行を追加します

 vi /usr/local/bin/httpd-kill
#!/bin/bash
/usr/bin/killall -9 httpd; /usr/bin/ipcs |grep apache | /bin/cut -d" " -f2 | /usr/bin/xargs /usr/bin/ipcrm sem {};
/bin/sleep .5;
exit 0;

Mysqldスクリプトに対して定義する必要があるのと同じ方法です。

監視用にすべてのプログラムを構成したら、monit構文でエラーを確認します。エラーが見つかった場合、それらを修正します。何が問題だったのかを理解するのはそれほど難しくありません。以下のコマンドを使用する

# monit -t

monit Configファイルが正しい場合は、「制御ファイルの構文はOKです」のようなメッセージが表示されます。エラーが表示されない場合は、

考えられるすべてのエラーを修正したら、次のコマンドを入力してmonitサービスを開始できます。

# /etc/init.d/monit start

Monitサービスの確認

ログファイルを確認することで、monitサービスが開始されていることを確認できます。

# tail -f /var/log/monit

ログ出力の例は次のとおりです

[BDT Apr  3 03:06:04] info     : Starting monit HTTP server at [localhost:2812]
[BDT Apr  3 03:06:04] info     : monit HTTP server started
[BDT Apr  3 03:06:04] info     : 'e2enetworks.com' Monit started
[BDT Apr  3 03:06:04] error    : 'nginx' process is not running
[BDT Apr  3 03:06:04] info     : 'nginx' trying to restart
[BDT Apr  3 03:06:04] info     : 'nginx' start: /etc/init.d/nginx

Ubuntu
  1. WindowsにAnsibleをインストールして構成する方法

  2. Ubuntu18.04にRedisをインストールして構成する方法

  3. Monitをインストールおよび構成する方法。

  1. Ubuntu18.04にRedmineをインストールして設定する方法

  2. Ubuntu18.04にSambaをインストールして設定する方法

  3. Ubuntu20.04にRedisをインストールして構成する方法

  1. Ubuntu20.04にJenkinsをインストールして構成する方法

  2. Ubuntu16.04にAskbotをインストールして構成する方法

  3. Ubuntu14.04にMongoDBをインストールして構成する方法