2011年7月6日 星期三

在CentOS上安裝lighttpd

一直以來慣用的web伺服器都是apache,功能是很強,但是在學校裏,實際能用到的功能也不多啦!所以就換個精簡一點的來用用。因為在一些嵌入式的設備中看到滿多廠商使用的是lighttpd這個套件,所以就來試試。

它的功能也不算差啦!最重要的,它至少要支援php,要不就沒戲唱了!

不過很不幸的,CentOS並未將它包含在內,如果要安裝的話,就得下載原始碼自行編譯。「編譯」!?再說吧!先找rpm套件吧!

還好有個套件叫RPMforge,它將一些好用的東東整理成軟件庫,方便使用者可以直接用yum安裝一些套件。先到http://packages.sw.be/網上去找找。
一、先安裝維護者的金鑰
二、下載
三、驗證檔案
四、安裝


[root@centos5 ~]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
[root@centos5 ~]# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
[root@centos5 ~]# rpm -K rpmforge-release-0.5.2-2.el5.rf.i386.rpm
rpmforge-release-0.5.2-2.el5.rf.i386.rpm: (sha1) dsa sha1 md5 gpg OK
[root@centos5 ~]# rpm -ivh rpmforge-release-0.5.2-2.el5.rf.i386.rpm
Preparing... ########################################### [100%]
1:rpmforge-release ########################################### [100%]


接著就來安裝lighttpd

[root@centos5 ~]# yum install lighttpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.tc.edu.tw
* extras: ftp.tc.edu.tw
* rpmforge: fr2.rpmfind.net
* updates: ftp.tc.edu.tw
Setting up Install Process
Resolving Dependencies
--< Running transaction check
---< Package lighttpd.i386 0:1.4.28-2.el5.rf set to be updated
--< Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================
Installing:
lighttpd i386 1.4.28-2.el5.rf rpmforge 1.1 M

Transaction Summary
=============================================================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)

Total download size: 1.1 M
Is this ok [y/N]:
Downloading Packages:
lighttpd-1.4.28-2.el5.rf.i386.rpm | 1.1 MB 00:03
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : lighttpd 1/1

Installed:
lighttpd.i386 0:1.4.28-2.el5.rf

Complete!

修改一下權限

[root@centos5 ~]# mkdir -p /var/run/lighttpd/
[root@centos5 ~]# chown lighttpd /var/run/lighttpd

檢查tcp 80是不是被佔住

[root@centos5 ~]# netstat -an |grep :80

檢查組態檔語法是否正確

[root@centos5 ~]# lighttpd -t -f /etc/lighttpd/lighttpd.conf
Syntax OK

就給它啟動吧!沒想到發生下面的錯誤,起不來…

[root@centos5 lighttpd]# service lighttpd start
Starting lighttpd: 2011-07-06 16:03:23: (server.c.722) couldn't set 'max filedescriptors' Operation not permitted
[FAILED]


原因是和SELinue的policy衝突了,要修改一下。

[root@centos5 lighttpd]# /usr/sbin/semodule -DB
[root@centos5 lighttpd]# service auditd restart
[root@centos5 lighttpd]# grep lighttpd /var/log/audit/audit.log | audit2allow -M lighttpdmaxfds2
******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i lighttpdmaxfds2.pp
[root@centos5 lighttpd]# semodule -i lighttpdmaxfds2.pp
[root@centos5 lighttpd]# service lighttpd restart
Stopping lighttpd: [FAILED]
Starting lighttpd: [ OK ]

不過CentOS預設有啟動iptables,所以tcp 80是不被放行的,另外預設的根目錄裏/srv/www裏沒檔案,所以得自行建個檔案,要不然從瀏覽器中一直會顯示404的錯誤喔!


參考文章:
http://wiki.centos.org/zh-tw/AdditionalResources/Repositories/RPMForge
http://www.howtoforge.com/installing-lighttpd-with-php5-and-mysql-support-on-centos-5.4
http://www.kernelhardware.org/lighttpd-and-centos-5/
https://bugzilla.redhat.com/show_bug.cgi?id=571924