Достаточно часто пользорватели Линукс, как и я, сталкиваються с задачей сделать что то бысто и не замарачиваться. Такая ситуация у меня возникла с syslog-ng демоном - системой сбора лог информации в gentoo-box
После установки syslog-ng, базовая конфигурация демона логов немного ущербна. Для того, что бы чуточку упростить себе жизнь, ниже представлена
базовая настройка для syslog-ng в ОС gentoo
$ cat /etc/syslog-ng/syslog-ng.conf
@version: 3.0
# $Header: /var/cvsroot/gentoo-x86/app-admin/syslog-ng/files/syslog-ng.conf.gentoo.3,v 1.1 2010/04/06 02:11:35 mr_bones_ Exp $
#
# Syslog-ng default configuration file for Gentoo Linux
options {
chain_hostnames(no);
# The default action of syslog-ng is to log a STATS line
# to the file every 10 minutes. That's pretty ugly after a while.
# Change it to every 12 hours so you get a nice daily update of
# how many messages syslog-ng missed (0).
stats_freq(43200);
};
source src {
unix-stream("/dev/log" max-connections(256));
internal();
# file("/proc/kmsg");
};
source kernsrc { file("/proc/kmsg"); };
# Create message recievers
destination authlog { file("/var/log/auth.log"); };
destination messages { file("/var/log/messages"); };
destination sys_log { file("/var/log/syslog"); };
destination cron { file("/var/log/cron.log"); };
destination daemon { file("/var/log/daemon.log"); };
destination kern { file("/var/log/kern.log"); };
destination lpr { file("/var/log/lpr.log"); };
destination user { file("/var/log/user.log"); };
destination mail { file("/var/log/mail.log"); };
destination mailinfo { file("/var/log/mail.info"); };
destination mailwarn { file("/var/log/mail.warn"); };
destination mailerr { file("/var/log/mail.err"); };
destination newscrit { file("/var/log/news/news.crit"); };
destination newserr { file("/var/log/news/news.err"); };
destination newsnotice { file("/var/log/news/news.notice"); };
destination debug { file("/var/log/debug"); };
destination console { usertty("root"); };
destination console_all { file("/dev/tty12"); };
destination xconsole { pipe("/dev/xconsole"); };
# Create filters
filter f_authpriv { facility(auth, authpriv); };
filter f_syslog { not facility(authpriv, mail); };
filter f_cron { facility(cron); };
filter f_daemon { facility(daemon); };
filter f_kern { facility(kern); };
filter f_lpr { facility(lpr); };
filter f_mail { facility(mail); };
filter f_user { facility(user); };
filter f_debug { not facility(auth, authpriv, news, mail); };
filter f_messages { level(info..warn)
and not facility(auth, authpriv, mail, news); };
filter f_emergency { level(emerg); };
filter f_info { level(info); };
filter f_notice { level(notice); };
filter f_warn { level(warn); };
filter f_crit { level(crit); };
filter f_err { level(err); };
filter f_failed { message("failed"); };
filter f_denied { message("denied"); };
# Connect filters with recievers
log { source(src); filter(f_authpriv); destination(authlog); };
log { source(src); filter(f_syslog); destination(sys_log); };
log { source(src); filter(f_cron); destination(cron); };
log { source(src); filter(f_daemon); destination(daemon); };
log { source(kernsrc); filter(f_kern); destination(kern); };
log { source(src); filter(f_lpr); destination(lpr); };
log { source(src); filter(f_mail); destination(mail); };
log { source(src); filter(f_user); destination(user); };
log { source(src); filter(f_mail); filter(f_info); destination(mailinfo); };
log { source(src); filter(f_mail); filter(f_warn); destination(mailwarn); };
log { source(src); filter(f_mail); filter(f_err); destination(mailerr); };
log { source(src); filter(f_debug); destination(debug); };
log { source(src); filter(f_messages); destination(messages); };
log { source(src); filter(f_emergency); destination(console); };
# By default messages are logged to tty12...
destination console_all { file("/dev/tty12"); };
# ...if you intend to use /dev/console for programs like xconsole
# you can comment out the destination line above that references /dev/tty12
# and uncomment the line below.
#destination console_all { file("/dev/console"); };
#log { source(src); destination(messages); }
По умолчанию все лог сообщения записываються в файл /var/log/messages. Но анализировать такой огромный файл... ох, дело не простое. Там и сообщения от ядра, и от системных демонов. Можно перенастроить все демоны для ведения своих журналов, но дело хлопотное. Но намного проще, если лог файлы разделены логически. Сказано-сделано ) Логика работы syslog-ng такова - разбить поток лог сообщений с определённым критериям и направить в нужный канал
Первая часть конфигурационного файла, получатели
Синтаксис
destination {
destination-driver(params); destination-driver(params); ... };
Пример
destination d_demo_tcp { tcp("10.1.2.3" port(1999)); };
destination указывает, куда сообщение будет послано после применения фильтра к сообщению. Может принимать следующие значения
| Name | Description |
file() | Записать сообщение в файл |
fifo(), pipe() | Отправить канал через определённый pipe. |
program() | Вызвать программу и направить на stdin программы сообщение |
sql()* | Направить сообщение в sql ба
*лоступно лишь в syslog-ng Premium Edition. |
tcp() | Отправить сообщение на указанный порт по протоколу IPv4 (tcp) |
tcp6() | Отправить сообщение на указанный порт по протоколу IPv6 (tcp) |
udp() | Отправить сообщение на указанный порт по протоколу IPv4 (udp) |
udp6() | Отправить сообщение на указанный порт по протоколу IPv6 (udp) |
unix-dgram() | Отправить сообщение на указанный порт по протоколу IPv4 (udp) |
unix-stream() | Отправить сообщение через UNIX_STREAM |
usertty() | Отправить сообщение на определённую консоль (терминал),
если пользователь залогинен | |
|
|
Вторая часть конфигурационного файла - это фильтры, которые в зависимости от условия идентифицируют сообщение
Синтаксис
filter { expression; };
Пример:
filter demo_filter { host("example") and message("deny"); };
Есть небольшой ньюанс в фильтрах сообщений. В документации к syslog-ng можно найти match директиву. Например:
filter demo_filter { match("regexp", "deny"); };
И при запуске syslog-ng выше 3 версии в консоле будет такой Warning:
WARNING: the match() filter without the use of the value() option is deprecated and hinders performance, please update your configuration;
В новой версии лучше использовать message директиву, так как match - устарела.
В третей части конфигурационного файла - связывание фильтров с получателями
Синтаксис
log {
source(s1); source(s2); ...
filter(f1); filter(f2); ...
destination(d1); destination(d2); ...
flags(flag1[, flag2...]);};
Пример
source s_localhost { tcp(ip(127.0.0.1) port(1999) ); };
destination d_tcp { tcp("10.1.2.3" port(1999); localport(999)); };
log { source(s_localhost); destination(d_tcp); }
В нашем конф. файле связывание весьма простое - источники src и kernel-src + определённый фильтр = получатель
Ссылки:
- http://www.gentoo.org/doc/ru/security/security-handbook.xml?part=1&chap=3&style=printable
- http://sial.org/howto/logging/syslog-ng/
- http://www.balabit.com/sites/default/files/documents/syslog-ng-v2.0-guide-admin-en.html/ch03s04.html