syslog-ngの3.6系をがんばってやります
Glib2.0がインストールされてる必要があるので、確認
Fedora21にしたら3.5.6になってうまくログが取れなくなったので、メモ

3.6.4が最新で公式から出ていたので、パッケージ化してインストールしてもダメ
syslog-ng -sをすると以下のメッセージが出てきたので確認

Using /dev/log Unix socket with systemd is not possible. Changing to systemd-syslog source, which supports socket activation.;

/run/systemd/journalをのぞいてみるとdev-log flushed kernel-seqnum socket stdout syslogのファイルがあって、/dev/logを見ると

/dev/log -> /run/systemd/journal/dev-log

になってるので、/run/systemd/journal/socketに変えたところログが出るようになりましたとさ。メモメモ

と思ったらまたでなくなったので再度調査中でござる。ニンニン

どうやらFedora21のsyslog-ng 3.5.6ではunix-dgramやunix-streamを使わずにsystem();だけでやってくれるようで
さらに3.6.xではsystemd-journal();だけでよいみたいです。
systemd-syslog();の方が良いみたいです?
ここに 載ってましたよ。。。
しかし、これ設定してsyslog-ng再起動したらjournalに残ってた(?)ログがフラッシュされたのか半年前からのログが一斉に流れ始めましたよ。。。。。。。ログのディレクトリ小さい人は要注意です。

# rpm -aq | grep glib glib2-devel~~~

インストールに必要なもののインストール

# cd /usr/local/src
# wget http://my.balabit.com/downloads/syslog-ng/open-source-edition/3.4.8/source/eventlog_0.2.13.tar.gz
# tar zxvf eventlog-0.2.13.tar.gz
# cd eventlog-0.2.13
# ./configure --prefix=/usr
# make
# make install

そしてsyslog-ngのインストールです。

# cd /usr/local/src
# wget http://my.balabit.com/downloads/syslog-ng/open-source-edition/3.6.4/source/syslog-ng_3.6.4.tar.gz
# tar zxvf syslog-ng_3.6.4.tar.gz
# cd syslog-ng-3.6.4
# ./configure --prefix=/usr --sysconfdir=/etc/syslog-ng --sbindir=/sbin --enable-tcp-wrapper --enable-spoof-source --enable-dynamic-linking --localstatedir=/var/lib/syslog-ng --enable-ssl --with-pidfile-dir=/var/run
# make
# make install
# cd contrib/fedora-packaging/
# cp syslog-ng.init /etc/init.d/syslog-ng
# mkdir /etc/syslog-ng
# cp syslog-ng.conf /etc/syslog-ng
# cp syslog-ng.sysconfig /etc/sysconfig/syslog-ng
# chmod 755 /etc/init.d/syslog-ng
# chkconfig --add syslog-ng

/etc/sysconfig/syslog-ng

SYSLOGNG_OPTIONS=""
 ↓ 
SYSLOGNG_OPTIONS="-p /var/run/syslogd.pid

これでインストールは完了です。 次に設定ファイルの移行作業をします。 基本的にデフォルトであればコピーしたままで動くはずです。コンフィグは古いバージョンのままなので、修正を加えておきます。
以下の修正をした後に3.0用にさらに修正しておいてください。

/etc/syslog-ng/syslog-ng.conf
今のうちの設定

@version: 3.6
options {
flush_lines (0);
log_fifo_size (1000);
long_hostnames (off);
use_dns (no);
use_fqdn (no);
chain_hostnames(no);
check_hostname(no);
create_dirs (yes);
keep_hostname (yes);
stats_freq (3600);
owner(root);
group(root);
perm(0644);
dir_perm(0755);
#gc_idle_threshold(50);
#gc_busy_threshold(5000);
};
source s_sys {
file ("/proc/kmsg" program_override("kernel: "));
unix-stream ("/dev/log" max-connections(200));
internal();
tcp();
};
source router {
udp(ip("192.168.0.10") port(514));
};
destination d_cons {
file("/dev/console");
};
destination d_mesg {
file("/var/log/messages");
};
destination d_spam {
file("/var/log/spamd.log");
};
destination d_auth {
file("/var/log/secure");
};
destination d_mail {
file("/var/log/maillog");
};
destination d_spol {
file("/var/log/spooler");
};
destination d_boot {
file("/var/log/boot.log");
};
destination d_cron {
file("/var/log/cron");
};
destination d_sulog {
file("/var/log/sulog");
};
destination d_mlal {
usertty("*");
};
destination d_local0 {
file("/var/log/snmpd.log");
};
destination d_local1 {
file("/var/log/router.log");
};
destination d_local2 {
file("/var/log/pureftpd.log");
};
destination d_local3 {
file("/var/log/bind.log");
};
destination d_local4 {
file("/var/log/local4.log");
};
destination d_local5 {
file("/var/log/local5.log");
};
destination d_local6 {
file("/var/log/samba/smb.log");
};
destination d_ldap {
file("/var/log/ldap.log");
};
destination d_stunnel {
file("/var/log/stunnel.log");
};
destination d_routerlog {
file("/var/log/router.log");
};
destination d_routerlog2 {
file("/var/log/router-debug.log");
};
destination d_iptables {
file("/var/log/iptables.log");
};
destination d_iptables_other {
file("/var/log/iptables-other.log");
};
destination d_iptables_deny {
file("/var/log/iptables-deny.log");
};
destination d_iptables_frag {
file("/var/log/iptables-frag.log");
};
destination d_iptables_ping {
file("/var/log/iptables-ping.log");
};
destination d_iptables_all {
file("/var/log/iptables-all.log");
};
destination d_syslog_ng {
file("/var/log/syslog-ng.log");
};
destination d_proftpd {
file("/var/log/proftpd/proftpd.log");
};
destination d_hotcopy {
file("/var/log/backup.log");
};
destination d_snort {
file("/var/log/snort.log");
};
destination d_dhcpd {
file("/var/log/dhcpd.log");
};
#filter f_filter1 {
facility(kern);
};
filter f_filter2 {
not facility(mail,authpriv,cron,local0,local1,local2,local3,local4,local5,local6,local7)
and not program("su")
and not program("stunnel")
and not message("-- MARK --")
and not message ("Bad tcp packet: ")
and not message ("Bad udp packet: ")
and not message ("Bad icmp packet: ")
and not program("syslog-ng")
and not message ("IPTABLES")
and not message("iptablelog:")
and not message ("nagios:")
and not message ("ntop")
and not program("proftpd")
and not program ("snort")
and not program ("snmpd")
and not program ("named")
and not program ("oinkmaster")
and not message ("entered promiscuous mode")
and not message ("left promiscuous mode")
and not program ("dhcpd")
and not message ('CIFS VFS:');
};
filter f_sulog {
program("su");
};
filter f_stunnel {
program("stunnel");
};
filter f_filter3 {
facility(authpriv)
and not program("su")
and not program("crond")
and not program("CROND")
and not message("/usr/sbin/hddtemp")
and not program("stunnel")
and not program("proftpd");
};
filter f_filter4 {
facility(mail)
and not program("spamd")
and not program("clamd")
and not program("freshclam");
};
filter f_spam {
facility(mail)
and program("spamd");
};
filter f_filter5 {
level(emerg);
};
filter f_filter6 {
facility(uucp)
or (facility(news)
and level(crit..emerg));
};
filter f_filter7 {
facility(local7)
and not program("mysqlhotcopy");
};
filter f_filter8 {
facility(cron);
};
filter f_routerlog {
host(192.168.0.1)
and level(info..emerg)
and not message("(Bound|Released|Rejected)");
};
filter f_routerlog2 {
host(192.168.0.1)
and level(info..emerg)
and message("(Bound|Released|Rejected)");
};
filter f_local0 {
facility(local0);
};
filter f_local1 {
facility(local1);
};
filter f_local2 { 
facility(local2)
and not message("gw.example.com")
and not message("192.168.0.1");
};
filter f_local3 {
facility(local3);
};
filter f_local4 {
facility(local4)
and not program("slapd");
};
filter f_local5 {
facility(local5);
};
filter f_local6 {
facility(local6);
};
filter f_ldap {
facility(local4)
and program("slapd");
};
filter f_iptables {
message("Bad tcp packet: ");
};
filter f_iptables_other1 {
message ("Bad udp packet: ");
};
filter f_iptables_other2 {
message ("Bad icmp packet: ");
};
filter f_iptables_all {
message ("IPTABLES INPUT");
};
filter f_iptables_deny {
message ("IPTABLES DENY_HOST");
};
filter f_iptables_frag {
message ("IPTABLES FRAGMENT");
};
filter f_iptables_ping {
message ("IPTABLES PINGDEATH");
};
filter f_syslog_ng {
program("syslog-ng");
};
filter f_proftpd {
program("proftpd");
};
filter f_hotcopy {
facility(local7)
and program ("mysqlhotcopy");
};
filter f_snort {
program("snort");
};
filter f_snmpd {
program("snmpd");
};
filter f_dhcpd {
program("dhcpd");
};
#log { source(s_sys); filter(f_filter1); destination(d_cons); };
log { source(s_sys); filter(f_filter2); destination(d_mesg); };
log { source(s_sys); filter(f_filter3); destination(d_auth); };
log { source(s_sys); filter(f_filter4); destination(d_mail); };
log { source(s_sys); filter(f_filter5); destination(d_mlal); };
log { source(s_sys); filter(f_filter6); destination(d_spol); };
log { source(s_sys); filter(f_filter7); destination(d_boot); };
log { source(s_sys); filter(f_filter8); destination(d_cron); };
log { source(router); filter(f_routerlog); destination(d_routerlog); };
log { source(router); filter(f_routerlog2); destination(d_routerlog2); };
log { source(s_sys); filter(f_local0); destination(d_local0); };
log { source(s_sys); filter(f_local1); destination(d_local1); };
log { source(s_sys); filter(f_local2); destination(d_local2); };
log { source(s_sys); filter(f_local3); destination(d_local3); };
log { source(s_sys); filter(f_local4); destination(d_local4); };
log { source(s_sys); filter(f_local5); destination(d_local5); };
log { source(s_sys); filter(f_local6); destination(d_local6); };
log { source(s_sys); filter(f_ldap); destination(d_ldap); };
log { source(s_sys); filter(f_spam); destination(d_spam); };
log { source(s_sys); filter(f_sulog); destination(d_sulog); };
log { source(s_sys); filter(f_stunnel); destination(d_stunnel); };
log { source(s_sys); filter(f_iptables); destination(d_iptables); };
log { source(s_sys); filter(f_iptables_other1); destination(d_iptables_other); };
log { source(s_sys); filter(f_iptables_other2); destination(d_iptables_other); };
log { source(s_sys); filter(f_iptables_deny); destination(d_iptables_deny); };
log { source(s_sys); filter(f_iptables_frag); destination(d_iptables_frag); };
log { source(s_sys); filter(f_iptables_ping); destination(d_iptables_ping); };
log { source(s_sys); filter(f_syslog_ng); destination(d_syslog_ng); };
log { source(s_sys); filter(f_iptables_all); destination(d_iptables_all); };
log { source(s_sys); filter(f_proftpd); destination(d_proftpd); };
log { source(s_sys); filter(f_hotcopy); destination(d_hotcopy); };
log { source(s_sys); filter(f_snort); destination(d_snort); };
log { source(s_sys); filter(f_snmpd); destination(d_local0); };
log { source(s_sys); filter(f_dhcpd); destination(d_dhcpd); };

/usr/local/sbin/mailftp.cgi

#!/usr/bin/perl
# メールのタイトル
$subject = 'Syslog-ng ftpd alert';
# 送信先メールアドレス
$mailto = ' webmaster@example.org';
# 送信元メールアドレス
$mailfrom = ' webmaster@example.org';
# sendmailパス
$sendmail = '/usr/sbin/sendmail';
use Jcode;
### メール送信 ###
while ($message = ) {
# 頭の余分な部分を削除
$message =~ s/^\<\w+\>//g; Jcode::convert(\$subject,jis); Jcode::convert(\$message,jis);
open(MAIL,"| $sendmail -t");
print MAIL "To: $mailto\n";
print MAIL "From: $mailfrom\n";
print MAIL "Subject: $subject\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-type: text/plain; charset=ISO-2022-JP\n";
print MAIL "Content-Transfer-Encoding: 7bit\n";
print MAIL "$message\n";
close(MAIL);
}

同様に/usr/local/sbin/mailssh.cgiも作成。

こんな風に細かく設定ができます。
設定が終わったら

# syslog-ng -s

で構文エラーチェックをします。
何も表示されなかったらsyslogdをとめてsyslog-ngを起動します。

# /etc/init.d/syslogd stop
# /etc/init.d/syslog-ng start
# chkconfig --del syslogd

↑これをやっておかないとリブート時におかしなことになるまs

とりあえずその他は次回ということで。

3.x系のコンフィグ
2.xから3.xに置き換え(又は新規インストール)するとデフォルトのコンフィグでは
動きません。

3.x系の新規インストールパッケージに付属するサンプルコンフィグが2.x系のままなので
泣きながら情報見つけてきました。

とりあえず、デフォルトを最小限の修正で動かすには以下を追加/変更します

--- syslog-ng.conf 2008-09-08 01:23:13.000000000 +0900 +++ syslog-ng.conf.new 2009-08-07 07:46:37.034338284 +0900 @@ -1,3 +1,4 @@ +@version: 3.0 # syslog-ng configuration file. # # This should behave pretty much like the original syslog on RedHat. But @@ -30,7 +31,7 @@ # options { - sync (0); + flush_lines (0); time_reopen (10); log_fifo_size (1000); long_hostnames (off); @@ -41,7 +42,7 @@ }; source s_sys { - file ("/proc/kmsg" log_prefix("kernel: ")); + file ("/proc/kmsg" program_override("kernel: ")); unix-stream ("/dev/log"); internal(); # udp(ip(0.0.0.0) port(514)); @@ -50,7 +51,7 @@ destination d_cons { file("/dev/console"); }; destination d_mesg { file("/var/log/messages"); }; destination d_auth { file("/var/log/secure"); }; -destination d_mail { file("/var/log/maillog" sync(10)); }; +destination d_mail { file("/var/log/maillog" flush_lines(10)); }; destination d_spol { file("/var/log/spooler"); }; destination d_boot { file("/var/log/boot.log"); }; destination d_cron { file("/var/log/cron"); };

こんな感じで、動かせば警告表示は出てこないかと思います。

後は、matchを使うときになんか警告が出てるので、それをうまいこと修正すればうちの環境のものは完璧になります?

matchの代わりにmessageを使用することでWARNINGは出なくなるようです。
matchはmatch("xxxx")では無くmatch("regexp" value("xxxx"))のように使うらしいです?

message()はこんな感じでマッチさせることができます
ホストが192.168.0.1でAとBとCがある場合

filter test { host(192.168.0.1) and message("(A|B|C)"); };

そしていつの間にかというかFedora16?くらいからunix-streamだとおかしくなってしまうので、
unix-dgramにしてあげないといけないということが判明しました。

3.3?からは@include "/etc/syslog-ng/conf.d/*.conf"のようにコンフィグをインクルードできるようになったみたいですね。

残りはまた今度

タグ

コメントを追加

Plain text

  • HTMLタグは利用できません。
  • 行と段落は自動的に折り返されます。
  • ウェブページのアドレスとメールアドレスは自動的にリンクに変換されます。
CAPTCHA
半角で
この質問はあなたが人間の訪問者であるかどうかをテストし、自動化されたスパム送信を防ぐためのものです。
ももーい に投稿