CentOS5 には rpmforge から syslog-ng パッケージが出ているけれど、CentOS4 にはそれがないので、 tarball から rpm を作成して CentOS4 にインストールするhow to のメモ。
残念ながら、10分じゃちと無理だと思う。
syslog-ng を入れるのは、フィルタ機能を使って ssh への攻撃を自動遮断できるようにするため。
参考ページ → 「CentOS4にsyslog-ngを導入してみる」 id:omomom:20070722
http://www.balabit.com/network-security/syslog-ng/ から [Downloads] -> [Open Source] -> [syslog-ng OPEN SOURCE EDITION] -> [src] と巡って、 syslog-ng と eventlog の tarball をダウンロードする。
$ wget http://www.balabit.com/downloads/files/syslog-ng/sources/stable/src/syslog-ng-2.0.9.tar.gz $ wget http://www.balabit.com/downloads/files/syslog-ng/sources/stable/src/eventlog-0.2.7.tar.gz
syslog-ng には eventlog が必要なので、そちらを先にインストールする。
まず、tarball から spec ファイルを抜き出し、RPM構築環境に放り込む。
RPM/SPECS/ は環境に合わせて任意に読み替えること。(適宜 .rpmmacros などを設定のこと)
$ tar zxf eventlog-0.2.7.tar.gz $ cp eventlog-0.2.7/eventlog.spec.bb RPM/SPECS/
tarball のファイル名が spec の内容と食い違っているのでソースをRPM構築環境に放り込むついでに '-' を '_' にしておく。そして rpmbuild。
$ mv eventlog-0.2.7.tar.gz RPM/SOURECES/eventlog_0.2.7.tar.gz $ rpmbuild -bb RPM/SPECS/eventlog.spec.bb ......省略...... + umask 022 + cd /home/foo/RPM/BUILD + cd eventlog-0.2.7 + '[' /var/tmp/libevtlog0-root = / ']' + rm -rf /var/tmp/libevtlog0-root + exit 0
RPMS下に3つのrpmができるので、全てインストールしておく。
$ sudo rpm -ivh RPM/RPMS/i386/libevtlog*
続いて、syslog-ng 本体のインストール。
eventlog と同様に syslog-ng の spec ファイルを rpm構築環境に入れる。
$ tar zxf syslog-ng-2.0.9.tar.gz $ cp syslog-ng-2.0.9/syslog-ng.spec.bb RPM/SPECS/
こちらも spec の内容とファイル名が食い違っているのでソースをRPM環境に放り込む際に '-' を '_' にしておく。
$ mv syslog-ng-2.0.9.tar.gz RPM/SOURCES/syslog-ng_2.0.9.tar.gz
一般ユーザでは rpmbuild 時に Operation not permitted のエラーが出るので sudo で。
$ sudo rpmbuild --bb RPM/SPECS/syslog-ng.spec.bb
インストール。syslog-ng がすぐに走り出すので注意
$ sudo rpm -ivh RPM/RPMS/i386/syslog-ng-* Shutting down kernel logger: [ OK ] Shutting down system logger: [ OK ] Starting syslog-ng: [ OK ]
設定ファイルの準備が出来ていないので一旦 syslog-ng を止めて、syslog に戻す。
$ sudo /etc/init.d/syslog-ng stop Shutting down syslog-ng: [ OK ] $ sudo /etc/init.d/syslog start システムロガーを起動中: [ OK ] カーネルロガーを起動中: [ OK ]
設定ファイルを CentOS5 用(by rpmforge) に提供されているものと同じように書き換える。
$ sudo vi /etc/syslog-ng/syslog-ng.conf
内容は以下の通り。
# syslog-ng configuration file. # # This should behave pretty much like the original syslog on RedHat. But # it could be configured a lot smarter. # # See syslog-ng(8) and syslog-ng.conf(5) for more information. # # 20000925 gb@sysfive.com # # Updated by Frank Crawford (<Frank.Crawford@ac3.com.au>) - 10 Aug 2002 # - for Red Hat 7.3 # - totally do away with klogd # - add message "kernel:" as is done with klogd. # # Updated by Frank Crawford (<Frank.Crawford@ac3.com.au>) - 22 Aug 2002 # - use the log_prefix option as per Balazs Scheidler's email # # Updated by Jose Pedro Oliveira (<jpo at di.uminho.pt>) - 05 Apr 2003 # - corrected filters 'f_filter2' and 'f_filter6' # these filters were only allowing messages of one specific # priority level; they should be allowing messages from that # priority and upper levels. # # Updated by Jose Pedro Oliveira (<jpo at di.uminho.pt>) - 25 Jan 2005 # - Don't sync the d_mail destination # # Updated by Jose Pedro Oliveira (<jpo at di.uminho.pt>) - 01 Feb 2005 # - /proc/kmsg is a file not a pipe. # (https://lists.balabit.hu/pipermail/syslog-ng/2005-February/006963.html) # options { sync (0); time_reopen (10); log_fifo_size (1000); long_hostnames (off); use_dns (no); use_fqdn (no); create_dirs (no); keep_hostname (yes); stats (86400); perm (0644); owner (nobody); group (nobody); }; source s_sys { file ("/proc/kmsg" log_prefix("kernel: ")); unix-stream ("/dev/log"); internal(); # udp(ip(0.0.0.0) port(514)); }; 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_spol { file("/var/log/spooler"); }; destination d_boot { file("/var/log/boot.log"); }; destination d_cron { file("/var/log/cron"); }; destination d_mlal { usertty("*"); }; #filter f_filter1 { facility(kern); }; filter f_filter2 { level(info..emerg) and not facility(mail,authpriv,cron); }; filter f_filter3 { facility(authpriv); }; filter f_filter4 { facility(mail); }; filter f_filter5 { level(emerg); }; filter f_filter6 { facility(uucp) or (facility(news) and level(crit..emerg)); }; filter f_filter7 { facility(local7); }; filter f_filter8 { facility(cron); }; #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); };
念のため、設定ファイルの構文チェック。設定ファイルに問題がなければ何も表示されない。
# syslog-ng -s #
syslog を止めて、syslog-ng を起動する。
$ sudo /etc/init.d/syslog stop カーネルロガーを停止中: [ OK ] システムロガーを停止中: [ OK ] $ sudo /etc/init.d/syslog-ng start Starting syslog-ng: [ OK ]
再起動時に syslog-ng が動くように変更。
$ sudo /sbin/chkconfig syslog off $ sudo /sbin/chkconfig syslog-ng on $ sudo /sbin/chkconfig --list syslog syslog 0:off 1:off 2:off 3:off 4:off 5:off 6:off $ sudo /sbin/chkconfig --list syslog-ng syslog-ng 0:off 1:off 2:on 3:on 4:on 5:on 6:off $
logrotate に影響が出るので、logrotate の syslog を対象にした設定を変更する。
# vi /etc/logrotate.d/syslog
以下のように修正。
--- /etc/logrotate.d/syslog~ 2008-04-11 00:17:49.000000000 +0900 +++ /etc/logrotate.d/syslog 2008-09-24 17:15:45.000000000 +0900 @@ -1,6 +1,6 @@ /var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron { sharedscripts postrotate - /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true + /bin/kill -HUP `cat /var/run/syslogd-ng.pid 2> /dev/null` 2> /dev/null || true endscript }