Apache の mod_security をインストールしました。
- yum で簡単にお手軽に mod_security をインストール
- CentOS 5.9
- できるだけ最新版のバージョンの mod_security を導入したい
以上の条件での記録を残します。
ポイント
- 本家で紹介されているリポジトリ RHEL/CentOS Yum Repository (Jason Litka) よりも、EPEL の方がより最新のバージョンの mod_security を CentOS へインストールできる
- ルールを設定しなくとも mod_security をインストールするだけで性能は落ちる
性能の低いサーバには入れないほうがよいという判断も充分にありえますわ。セキュリティのルールをたくさん設定しても性能は落ちるのでしょうけれども、インストールするだけで落ちますから。
実践!yum で mod_security 簡単導入♪
次の流れで進めていきました。
- リポジトリの確認、導入
- yum で mod_security インストール
- Apache Bench で性能確認
1.リポジトリの確認、導入
CentOS 5.9 です。できるだけ最新版の mod_security をインストールしたいです!となりますと、リポジトリの導入が必要であるとピンときます♪
こちらの本家ページを拝見しますと、「RHEL/CentOS Yum Repository (Jason Litka)」という CentOS 用のリポジトリがございます。これ?ですの?
いいえ!
下にある「Fedora Core (Michael Fleming)」リポジトリを採用いたします。これ、実は EPEL です。以前、リポジトリについて調べました時に、EPEL を入れております。
実際に確かめてみましたところ、EPEL の方がより最新版です。
- 「RHEL/CentOS Yum Repository (Jason Litka)」の utterramblings ⇒ 2.5.9
- 「Fedora Core (Michael Fleming)」の EPEL ⇒ 2.6.8
「RHEL/CentOS Yum Repository (Jason Litka)」の utterramblings で確認しましたログです。
[root@localhost ~]# yum --enablerepo=utterramblings info mod_security
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.tsukuba.wide.ad.jp
* extras: ftp.tsukuba.wide.ad.jp
* remi: mirror.smartmedia.net.id
* rpmforge: mirror-fpt-telecom.fpt.net
* updates: ftp.tsukuba.wide.ad.jp
Available Packages
Name : mod_security
Arch : i386
Version : 2.5.9
Release : 1.jason.1
Size : 1.2 M
Repo : utterramblings
Summary : Security module for the Apache HTTP Server
URL : http://www.modsecurity.org/
License : GPLv2
Description: ModSecurity is an open source intrusion detection and prevention engine
: for web applications. It operates embedded into the web server, acting
: as a powerful umbrella - shielding web applications from attacks.
[root@localhost ~]#
つづいて、「Fedora Core (Michael Fleming)」の EPEL と比較して確認した時の模様です。
[root@localhost ~]# yum --enablerepo=epel,utterramblings info mod_security
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.tsukuba.wide.ad.jp
* epel: ftp.iij.ad.jp
* extras: ftp.tsukuba.wide.ad.jp
* remi: mirror.smartmedia.net.id
* rpmforge: mirror-fpt-telecom.fpt.net
* updates: ftp.tsukuba.wide.ad.jp
epel | 3.6 kB 00:00
Available Packages
Name : mod_security
Arch : i386
Version : 2.6.8
Release : 4.el5
Size : 159 k
Repo : epel
Summary : Security module for the Apache HTTP Server
URL : http://www.modsecurity.org/
License : ASL 2.0
Description: ModSecurity is an open source intrusion detection and prevention engine
: for web applications. It operates embedded into the web server, acting
: as a powerful umbrella - shielding web applications from attacks.
[root@localhost ~]#
ですから、迷わず EPEL リポジトリでの mod_security 導入に決めました♪
もっとも、本当の最新版はバージョン 2.7.5 ですので、たとえ EPEL リポジトリを使用しても真の最新バージョンをインストールできませんこと、注意です!
2.yum で mod_security インストール
- yum –enablerepo=epel install mod_security
とコマンドするだけですの、簡単ですの♪
なお、次で実際に行った時は、EPEL リポジトリを常にオンするように [epel] の enabled の値を「1」にしておりましたので「–enablerepo=epel」は記述しませんでしたこと、予めお断り申し上げますわ。
また、依存の関係で mod_security と同時に lua というパッケージもインストールされるようです。この lua がなにものであるかは、掘り下げませんの。
[root@localhost ~]# yum install mod_security Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.tsukuba.wide.ad.jp * epel: ftp.iij.ad.jp * extras: ftp.tsukuba.wide.ad.jp * remi: mirror.smartmedia.net.id * rpmforge: mirror-fpt-telecom.fpt.net * updates: ftp.tsukuba.wide.ad.jp base | 1.1 kB 00:00 epel | 3.6 kB 00:00 extras | 2.1 kB 00:00 pgdg92 | 2.8 kB 00:00 remi | 2.5 kB 00:00 rpmforge | 1.9 kB 00:00 updates | 1.9 kB 00:00 Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package mod_security.i386 0:2.6.8-4.el5 set to be updated --> Processing Dependency: liblua-5.1.so for package: mod_security --> Running transaction check ---> Package lua.i386 0:5.1.4-4.el5 set to be updated --> Finished Dependency Resolution Dependencies Resolved =============================================================================================== Package Arch Version Repository Size =============================================================================================== Installing: mod_security i386 2.6.8-4.el5 epel 159 k Installing for dependencies: lua i386 5.1.4-4.el5 epel 228 k Transaction Summary =============================================================================================== Install 2 Package(s) Upgrade 0 Package(s) Total download size: 387 k Is this ok [y/N]: y Downloading Packages: (1/2): mod_security-2.6.8-4.el5.i386.rpm | 159 kB 00:00 (2/2): lua-5.1.4-4.el5.i386.rpm | 228 kB 00:00 ----------------------------------------------------------------------------------------------- Total 538 kB/s | 387 kB 00:00 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing : lua 1/2 Installing : mod_security 2/2 Installed: mod_security.i386 0:2.6.8-4.el5 Dependency Installed: lua.i386 0:5.1.4-4.el5 Complete! [root@localhost ~]#
3.Apache Bench で性能確認
mod_security インストール前に一度測定し、インストール後に
- /etc/init.d/httpd restart
などで Apache を再起動しましてまた測定します。結果、性能が落ちました><。
- mod_security インストール前 → Requests per second: 3.25 [#/sec] (mean)
- mod_security インストール後 → Requests per second: 3.16 [#/sec] (mean)
インストール前の測定の詳細です。
[root@localhost ~]# ab -n 100 -c 10 http://192.168.56.111/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.56.111 (be patient).....done
Server Software: Apache
Server Hostname: 192.168.56.111
Server Port: 80
Document Path: /
Document Length: 44604 bytes
Concurrency Level: 10
Time taken for tests: 30.746842 seconds
Complete requests: 100
Failed requests: 1
(Connect: 0, Length: 1, Exceptions: 0)
Write errors: 0
Non-2xx responses: 1
Total transferred: 4433864 bytes
HTML transferred: 4416059 bytes
Requests per second: 3.25 [#/sec] (mean)
Time per request: 3074.684 [ms] (mean)
Time per request: 307.468 [ms] (mean, across all concurrent requests)
Transfer rate: 140.79 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 1.2 0 4
Processing: 283 2992 7018.4 313 30160
Waiting: 183 2596 6483.2 204 29353
Total: 283 2992 7018.9 313 30164
Percentage of the requests served within a certain time (ms)
50% 313
66% 320
75% 363
80% 927
90% 14852
95% 25665
98% 29768
99% 30164
100% 30164 (longest request)
[root@localhost ~]#
次に、インストール後の測定結果詳細です。
[root@localhost ~]# ab -n 100 -c 10 http://192.168.56.111/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.56.111 (be patient).....done
Server Software: Apache
Server Hostname: 192.168.56.111
Server Port: 80
Document Path: /
Document Length: 44604 bytes
Concurrency Level: 10
Time taken for tests: 31.610292 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 4478100 bytes
HTML transferred: 4460400 bytes
Requests per second: 3.16 [#/sec] (mean)
Time per request: 3161.029 [ms] (mean)
Time per request: 316.103 [ms] (mean, across all concurrent requests)
Transfer rate: 138.34 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 771 3062 6297.7 1251 31607
Waiting: 560 2791 6281.8 1048 31396
Total: 771 3062 6297.7 1251 31607
Percentage of the requests served within a certain time (ms)
50% 1251
66% 1336
75% 1591
80% 1829
90% 2943
95% 26894
98% 31282
99% 31607
100% 31607 (longest request)
[root@localhost ~]#
測定回数はたったの 1 回ですけれども、ウェブページをウェブブラウザへ返すときに、セキュリティーのルールが設定されていなくとも mod_security が動くだけでその分性能が落ちる、というのは充分に納得がいきます。
おそらくそういうことなのでしょう。
おわりに
本投稿は以前の次の投稿を少しだけ進めたものになります。
mod_security はこれからが本番ですの。設定ファイル、CRS(Core Rule Set コア・ルール・セット)、わけがわかりませんの!
mod_security はインストールして終わりではなく、Tripwire のようにインストール後の設定、運用が大変なタイプと存じます。
つまづき、惑い、苦労しながら、でも確実に進めていきたいですわ。
以上です。

