July 19

Ставим и настраиваем систему мониторинга. под хитрым названием Monit

Итак, поехали.

Шаг номер один – Установка:
apt-get install monit
Как бы просто и говорить нечего, главное не втыкать а отредактировать файлик:
nano /etc/default/monit
Указав там значение равное одному, для того чтобы монит воскресал стартовал вместе с системой, в итоге имеем:
startup=1
еще не плохо сменить дефолтное время проверки с его раз в три минуты на гуманное и нужное – раз в 30ть секунд, ибо как не как а в жизни и на практике уже получше:

было:
# CHECK_INTERVALS=180
стало:
CHECK_INTERVALS=30

Шаг номер два – Конфиги:
Далек в лес за правдой ходить не будем, а зальем простенький конфиг, в данном случае мониторинг будет работать для nginx, apache, exim, mysql, ssh, ftp (proftpd), named (bind9), hdd (отслеживаем свободное место). Так сказать. все просто и со вкусом.

Поехали:

rm -v /etc/monit/monitrc
nano /etc/monit/monitrc

set daemon 30
set logfile syslog facility log_daemon
set mailserver localhost # fallback relay

set eventqueue
basedir /var/monit # set the base directory where events will be stored
slots 100 # optionaly limit the queue size
#
set mail-format {
from: monit@имя_твоего_сервера
Subject: monit alert - $EVENT $SERVICE
message:Action-> $ACTION
$DATE
$DESCRIPTION
}

set alert твое_мыло #кому пишем
set httpd port 2812 and # на каком порт ему жить
use address твой_ip_адрес # на каком адресе живет вебморда
allow твой_логин:твой_пароль # логин и пароль для доступа разделены двоеточием

# Proftpd

check process proftpd with pidfile /var/run/proftpd.pid
start program = "/etc/init.d/proftpd start"
stop program = "/etc/init.d/proftpd stop"
if failed port 21 protocol ftp within 2 cycles then alert
if failed port 21 protocol ftp within 5 cycles then restart
if 5 restarts within 5 cycles then timeout

# Exim

check process exim with pidfile /var/run/exim4/exim.pid
start program = "/etc/init.d/exim4 start"
stop program = "/etc/init.d/exim4 stop"
if failed port 25 protocol smtp within 1 cycles then alert
if failed port 25 protocol smtp within 2 cycles then restart
if 5 restarts within 5 cycles then timeout

# Bind

check process named with pidfile /var/run/bind/run/named.pid
start program = "/etc/init.d/bind9 start"
stop program = "/etc/init.d/bind9 stop"
if failed host 127.0.0.1 port 53 type tcp protocol dns then alert
if failed host 127.0.0.1 port 53 type udp protocol dns then alert
if failed host 127.0.0.1 port 53 type tcp protocol dns within 5 cycles then restart
if failed host 127.0.0.1 port 53 type udp protocol dns within 5 cycles then restart
if 5 restarts within 5 cycles then timeout

# SSHD

check process sshd with pidfile /var/run/sshd.pid
start program "/etc/init.d/ssh start"
stop program "/etc/init.d/ssh stop"
if failed port 22 protocol ssh within 2 cycles then alert
if failed port 22 protocol ssh within 5 cycles then restart
if 5 restarts within 5 cycles then timeout

# Nginx

check process nginx with pidfile /var/run/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if failed host твой_ip_адрес port 80 type tcp protocol http within 2 cycles then alert
if failed host твой_ip_адрес port 80 type tcp protocol http within 5 cycles then restart
if 5 restarts within 5 cycles then timeout

# Apache

check process httpd with pidfile /var/run/apache2.pid
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if cpu > 60% for 3 cycles then alert
if cpu > 90% for 5 cycles then restart
if totalmem > 350.0 MB for 1 cycles then alert
if totalmem > 400.0 MB for 5 cycles then restart
if children > 80 for 1 cycles then alert
if children > 100 for 2 cycles then restart
if failed host твой_ip_адрес port 8080 type tcp protocol http then alert
if failed host твой_ip_адрес port 8080 type tcp protocol http within 5 cycles then restart
if 10 restarts within 10 cycles then timeout

# Mysqld

check process mysqld with pidfile /var/run/mysqld/mysqld.pid
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if cpu > 60% for 2 cycles then alert
if cpu > 70% for 5 cycles then restart
if failed host 127.0.0.1 port 3306 protocol mysql within 2 cycles then alert
if failed host 127.0.0.1 port 3306 protocol mysql within 5 cycles then restart
if 5 restarts within 5 cycles then timeout

# HDD
check device HDD_Usage with path /dev/simfs
if space usage > 50 % then alert
if space usage > 55 % then alert
if space usage > 60 % then alert
if space usage > 65 % then alert
if space usage > 70 % then alert
if space usage > 75 % then alert
if space usage > 80 % then alert
if space usage > 85 % then alert
if space usage > 90 % then alert
if inode usage > 80 % then alert
if inode usage > 85 % then alert
if inode usage > 90 % then alert

проверяем синтаксис:
monit -t
Control file syntax OK

Если все ок, то дальше делаем
/etc/init.d/monit restart
На этом настройка закончена, нас ждем управление с вебморды, в которую мы согласно этому конфигу и попадем перейдя по
http://твой_ip_адрес:2812/

Enjoy!

July 1

Нужные команды для Exim

Подсчитать количество сообщений в очереди
exim -bpc

Подсчитать количество «замерзших» сообщений в очереди
exim -bpr|grep frozen|wc -l

Удаляем все баунсы старше 10 минут
exiqgrep -o 600 -if '^<>$' |xargs exim -Mrm

Удаляем любые сообщения отправленные скриптами, если они не доставлись за 10 минут
exiqgrep -f "$domain" -o 600 -i|xargs exim -Mrm

Удалить «замершие» сообщения из очереди
exim -bpr|grep frozen|awk {’print $3′}|xargs exim -Mrm

Очистить все сообщения из очереди
exipick -i | xargs exim -Mrm