いつきコンテンツ

ヘルプ

カウンター


2015-12-05 サーバーの設定をしよう

眠れなかったので(笑)

[Unix][FreeBSD] qmail/postfix/MySQL/Redisのログ

結論から言うと、ほっといて良かった。

MySQL/Redisは起動終了しか書かないので、そもそも量が無い。

qmail/postfixはsyslogに吐く設定になってるので、newsyslogが勝手にローテートしてた。

しばらく様子見はいるけど、まぁこいつらはほっといてよさげ。

[Unix][FreeBSD] Apacheのログ(低負荷バージョン)

あんまり負荷が無いサーバー向け。

こいつはあんまりログが書き出されないとはいえ、/var/log/httpd-access.logやら/var/log/httpd-error.logやらに勝手に書き出すので、ほっとくと溜まる。

ちょいと調べてみた所、newsyslogに任せれば良いんじゃないかな? という事になった(ことにした)

アクセス目安としては……まぁ運用して決めて下さい。ウチは「自分しかアクセスしなさそう」なサーバーはこの設定にしてみました。


やり方は簡単。ApacheのPIDが/var/run/httpd.pidに書いてあるので、これを指定するだけ。

で、FreeBSD 10に付いてるnewsyslogは(/etc/newsyslog.conf.d/も読むけど)/usr/local/etc/newsyslog.conf.d/も読み込む設定になってるので、このディレクトリーを作って適当にファイルを置く。

今回はapache24のログなので、apache24ってファイルで置いた。

以下、サンプル。

/var/log/httpd-access.log	644	24	*	$W1D2	J	/var/run/httpd.pid	30
/var/log/httpd-error.log 644 24 * $W1D2 J /var/run/httpd.pid 30

左から順に、ログファイル名、パーミッション、ローテートする回数(一応6ヶ月分)、サイズは気にしないので無制限(*)、毎週月曜日($W1)のAM2時(D2)、bz圧縮してやる。んで、PIDは/var/run/httpd.pidに書いてある。最後の30はcat /usr/include/sys/signal.h| grep USRってやった時に、#define SIGUSR1 30って書いてあったので、30(つまり、SIGUSR1)

このシグナルはApacheに対して、gracefulってやった時に送られるシグナル。「接続が終了次第再起動」という便利なヤツです。

このシグナル送らないとログが切れないんで(笑)

要約すると

・毎週月曜のAM2に最大24個(=6ヶ月分)ログ取るよ!

という設定、やる気無しバージョン。まぁ、負荷が低い子はこれで良いでしょうヽ(´ー`)ノ

参考:On-line Manual of "newsyslog.conf"

[Unix][FreeBSD] Apacheのログ(高負荷バージョン)

中程度の負荷しかかからないなら、低負荷用のを流用して、

/var/log/httpd-access.log	644	24	10240	*	J	/var/run/httpd.pid	30
/var/log/httpd-error.log 644 24 10240 * J /var/run/httpd.pid 30

で良いんじゃないかな?(10M超えたら最大24個までローテート)

問題は、「1時間でログ溢れるぜヒャッハー!」とかいうアホ負荷のかかるサーバー。滅多に無いけど設定だけはしておくネ。


まずは、pkgで必要なモノを入れます。方針的には、fifoに出力して、multilogでログ量制御です。

pkg install daemontools ucspi-tcp


次に、rc.confに追加します(/var/serviceに本体を置いて、/serviceからシンボリックリンクを張って利用するので、こんな感じに)

svscan_enable="YES"

svscan_servicedir="/service"


rdfifoを取ってきてインストール

fetch http://fc.to/ituki/software/unix/rdfifo.c

cc -o rdfifo rdfifo.c

cp rdfifo /usr/local/bin

chmod 755 /usr/local/bin/rdfifo


httpd-logr (ログ読み込み用ユーザー)とhttpd-logw(ログ書き出し用ユーザー)を作る


ログ書き出し領域を作る

mkdir /var/log/httpd

mkdir /var/log/httpd/access

mkdir /var/log/httpd/error

chown httpd-logw:httpd-logw /var/log/httpd/access

chown httpd-logw:httpd-logw /var/log/httpd/error


httpd-access.log用のreadファイルを作る(/var/service/httpd-access-log/run パーミッションは700

#!/bin/sh

exec 2>&1
exec /usr/local/bin/setuidgid httpd-logr /usr/local/bin/rdfifo \
/var/log/httpd-access.log

httpd-access.log用のwriteファイルを作る(/var/service/httpd-access-log/log/run パーミッションは700


#!/bin/sh
exec /usr/local/bin/setuidgid httpd-logw /usr/local/bin/multilog t s1024000 n64 \
/var/log/httpd/access


同じようにして、httpd-error.log用のファイル(/var/service/httpd-error-log)を作る


シンボリックリンクを張る

cd /service

ln -s ../var/service/httpd-access-log .

ln -s ../var/service/httpd-error-log .


/var/log/httpd-access.log及び/var/log/httpd-error.logを、fifoにする

rm /var/log/httpd-access.log

mkfifo /var/log/httpd-access.log

chmod 750 /var/log/httpd-access.log

chgrp httpd-logr /var/log/httpd-access.log


rm /var/log/httpd-error.log

mkfifo /var/log/httpd-error.log

chmod 750 /var/log/httpd-error.log

chgrp httpd-logr /var/log/httpd-error.log


この後、apacheのリスタートを忘れずに。


これで意味不明なアクセスがあってもログは溢れなくなりました。多分ね。

Last Update: 2015-12-05 08:45:15

カレンダー

2003|04|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|07|08|11|
2013|03|05|08|
2014|01|
2015|04|05|06|07|09|10|12|
2016|01|03|05|06|10|11|
2017|06|
2018|05|08|09|10|11|
2019|04|08|12|
2020|03|08|09|11|
2021|05|
2022|04|
2023|12|
Generated by tDiary version 4.1.2 + amazon(DB Patch 0.2.1) + counter(DB Patch 0.2) + IKPatch version beta 4.0.1.
Powered by Ruby version 2.1.5-p273 with ruby-fcgi