ユーザにかけたクオータの解除 CentOS

ユーザディレクトリにクオータをかけたは良いが解除する方法が紹介されていない為書き込んでおこうと思う。
ユーザ:testのクオータを解除する。

# edquota -u test
Disk quotas for user test (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/cciss/c0d0p6 432 500000 512000 96 0 0

上記をviの方法で下記のように書き換える。

# edquota -u test
Disk quotas for user test (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/cciss/c0d0p6 432 0 0 96 0 0

あとは保存することでクオータが解除される。

Apacheのアクセスログを一斉にIPからHOSTへ変換する方法 CentOS

Apacheのアクセスログ(/var/log/httpd/access_log)に含まれるIPアドレスを一斉にHOST名に変更したいと思うことがしばしばある。
しかし、あまり方法が紹介されていないようなので今回書いておこうと思った。

Apachjeにはログに含まれるIPアドレスを自動的にHOST名に変換してくれるlogresolveというコマンドがある。今回これを使い一括して変換を行なおうと思う。

コマンドの形式
# logresolve < 生ログのファイル > 変換した出力先ファイル
例:
# logresolve < /var/log/httpd/access_log > ./laccess_log

これにより/var/log/httpd/access_logに含まれるIPアドレスを一括して変換し./laccess_logへ結果を保存することができる。

eAccelerator ディスクキャッシュしない

/ パーティション肥満化原因が/var/cache関連でしたのでeAcceleratorのディスクキャッシュを止めました。
又、メモリーを大量消費しないように16MBまでに制限しました。

# vi /etc/php.d/eaccelerator.ini

; Enable eAccelerator extension module
zend_extension = /usr/lib/php/modules/eaccelerator.so
; Options for the eAccelerator module
eaccelerator.cache_dir = /var/cache/php-eaccelerator
;eaccelerator.shm_size = 0
eaccelerator.shm_size = 16
eaccelerator.enable = 1
eaccelerator.optimizer = 1
eaccelerator.check_mtime = 1
eaccelerator.filter = ""
eaccelerator.shm_max = 0
eaccelerator.shm_ttl = 3600
eaccelerator.shm_prune_period = 0
;eaccelerator.shm_only = 0
eaccelerator.shm_only = 1
eaccelerator.compress = 1
eaccelerator.compress_level = 9
;eaccelerator.keys = "shm_and_disk"
eaccelerator.keys = "shm_only"
;eaccelerator.sessions = "shm_and_disk"
eaccelerator.sessions = "shm_only"
;eaccelerator.content = "shm_and_disk"
eaccelerator.content = "shm_only"
eaccelerator.debug = 0

eaccelerator.shm_only = 1
CPU使用率を監視しながら使用率が大幅に上がる場合等は考え直そうと思う。

Apache 特定サイトからのアクセスを個別にログする CentOS

あまり必要ないのか紹介が一切ないのでメモしておく。
試しに2chからのアクセスのみ別のログに保存しておくようにしてみる。

# vi /var/log/httpd/2ch_log
# vi /etc/httpd/conf.d/2ch.conf

SetEnvIf Referer "^http://.*.2ch.net" 2ch_log
SetEnvIf Referer "^http://ime.nu" 2ch_log
CustomLog /var/log/httpd/2ch_log combined env=2ch_log

# service httpd restart

余談だが、その気になれば特定のサイトからアクセスがあった場合はメールで知らせることも可能である。
参考元:今週のお題 – Apache のエラーログをメールする
# vi /root/2ch_log.pl

#!/usr/bin/perl
use strict;

my $addr = $ARGV[0] ? shift:"orbit";
while(1) {
    my $r = sysread(STDIN, my $m, 4096);
    if($m) {
        if(open(MAIL, "|/usr/bin/Mail -s '[httpd] 2ch Access' $addr")) {
            print MAIL $m;
            close MAIL;
        }
    }
    if($r <= 0) {
        last;
    }
}

# vi /etc/httpd/conf.d/2ch.conf

SetEnvIf Referer "^http://.*.2ch.net" 2ch_log
SetEnvIf Referer "^http://ime.nu" 2ch_log
CustomLog "/var/log/httpd/2ch_log" combined env=2ch_log
CustomLog "| /root/2ch_log.pl" combined env=2ch_log

# service httpd restart

追記
LAN内からのアクセスをロギングしない設定

SetEnvIf Referer "^http://.*.2ch.net" 2ch_log
SetEnvIf Referer "^http://ime.nu" 2ch_log
SetEnvIf Remote_Addr "^127.0.0." !2ch_log
SetEnvIf Remote_Addr "^192.168.24." !2ch_log
CustomLog "/var/log/httpd/2ch_log" combined env=2ch_log
CustomLog "| /root/2ch_log.pl" combined env=2ch_log

2ch ジャンプ確認 再現 ime.nu

全く同じ働きをするCGIを書いてみました。
※私の妄想にしか過ぎないので間違ってる可能性もあります。

#!/usr/bin/perl
#===================================
#スクリプト名:ジャンプCGI
#作者:ORBIT
#===================================

# URLの後ろパスがついているかチェック
if ($ENV{'PATH_INFO'} eq ""){&error;}

# パスにhttp:/が含まれている場合削除
$ENV{'PATH_INFO'} =~ s/http:///;

# URLの作成
$PATH = "http:/$ENV{'PATH_INFO'}";

# 出力
print "Content-type: text/htmlnn";
print <<EOT
<html><head>
<title>jump</title></head>
<body>
以下のURLに飛びますよろしいですか?<br>
<a href="$PATH">$PATH</a>
</body></html>
EOT
;

# パスが見つからなかった場合は下記を出力
sub error {
print "Content-type: text/htmlnn";
print <<EOT
<html><head>
<title>jump</title></head>
<body>
test
</body></html>
EOT
;
exit;
}

これをエラーページにしてるのかリダイレクトしてるのか多分そんなところかと思います。

CentOS 5.4 Python CGI対応

自分は使うことは無いので触る予定はありませんでしたが利用者が使いたい方もおられるでしょうので一応対応させました。
これはその際のメモです。

# yum install *python*
# ln -s /usr/bin/python /usr/local/bin/python

これで対応します。

Python CGIプログラミング入門
ここの例文を利用させていただいたところ無事動作を確認できました^^

攻撃の多い国を自働遮断 CentOS 5.4

いつもお世話になってる方法ですが今回はうざい国からのアクセスを全て遮断様の内容を若干発展させて自動的にデータベースを更新してくれるように設定しみました。

Redhat系用に作成した改造版countryfilter.plを下記のリンクを右クリックして保存する。
countryfilter
※拡張子を.plに変更してサーバの/rootへ転送する。

サーバ上から直接行う場合
# su -
# wget http://www.rosx.net/blog/wp-content/uploads/2010/03/countryfilter1.txt
# mv countryfilter.txt countryfilter.pl

オリジナル自動化シェルスクリプトを下記のリンクから右クリックでダウンロードしてファイル名をcountryfilter.shへ変更する。
countryfilter_sh
ファイル名変更後サーバの/rootディレクトリへ転送する。

サーバ上から直接行う場合
# wget http://www.rosx.net/blog/wp-content/uploads/2010/03/countryfilter_sh1.txt
# mv countryfilter_sh.txt countryfilter.sh

ここからはサーバ上で操作を行う
# chmod +x countryfilter.sh   ←実行権の投与
# mv countryfilter.sh /etc/cron.monthly/   ←月一回データベースを更新
動作チェックを行う場合は下記の一行を実行してみる。
※思いの他時間がかかると思われるが紅茶でもすすりながらゆっくりする。
# /etc/cron.monthly/countryfilter.sh

※おそらくVine Linuxでも同じように使える方法かと思う。

Usermin メール返信文字化け警告 CentOS 5.4

メールの転送機能のメールの返信
はい、以下のメッセージを差出人に自動で返します
に日本語を入力すると激しく文字化けするので(日本語非対応)と追記する。
/usr/libexec/usermin/forward/lang/ja_JP.euc
上記をファイルを何らかの方法で編集する。

編集箇所
index_autoyes=はい、以下のメッセージを差出人に自動で返します(日本語非対応)

Geo::IPfree インストールエラー CentOS 5.4

Geo::IPfreeをインストールしようとしたら下記のようなエラーが出たので対策方法をメモしておく。

- module: Geo::IPfree –
Found: Geo-IPfree-1.100470.tar.gz
At: http://search.cpan.org//CPAN/authors/id/B/BR/BRICAS
Retrieving URL
Metadata retrieval
Tarball extraction: [/usr/src/redhat/SOURCES/Geo-IPfree-1.100470.tar.gz]
Generating spec file
SPEC: /usr/src/redhat/SPECS/Geo-IPfree.spec
Generating package
Signing package (pass phrase required)
エラー: マクロファイル内で “%_gpg_name” を設定しなければなりません。
パスフレーズのチェックに失敗しました。
RPM build failed [1] at /usr/bin/cpan2rpm line 1053.
– Done –

下記のコマンドでインストールするとエラーを回避できる。
# cpan2rpm –no-sign –install Geo::IPfree