PHP 5.3.1
MySQL 5.0.89
Nginx 0.8.33 或 0.7.65 (可選)
這個可比網上流傳的什麼一鍵安裝包要好得多,強烈推薦此法安裝,適合所有菜鳥和高手。我伺服器上全用的原始碼編譯安裝,也好不到哪去,還很費勁。我這個裝完已經包含 php 的一些常用擴充, PDO,eaccelerator,memcache,tidy等等。
CentOS 迷你安裝,然後先建立一個 repo
# vi /etc/yum.repos.d/centos.21andy.com.repo
放入如下內容
[21Andy.com]
name=21Andy.com Packages for Enterprise Linux 5 - $basearch
baseurl=http://www.21andy.com/centos/5/$basearch/
enabled=1
gpgcheck=0
protect=1
啟用 EPEL repo
CentOS i386 輸入如下命令
rpm -ihv http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
CentOS x86_64 輸入如下命令
rpm -ihv http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm
然後匯入key
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
複製代碼
OK,一鍵安裝吧
yum -y install nginx mysql-server php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator
最後 yum -y update 一下,全是最新的
如果 nginx 你要用 0.7.65 最新穩定版,把
yum -y install nginx
換成
yum -y install nginx-stable
就可以了
裝完你已經可以這樣玩了
service mysqld start
service php-fpm start
service nginx start
別忘了設定開機啟動
chkconfig --level 345 mysqld on
chkconfig --level 345 php-fpm on
chkconfig --level 345 nginx on
設定檔都在 /etc 下自己找
看看安裝多自動
Dependencies Resolved
==========================================================
Package Arch Version Repository Size
==========================================================
Installing:
mysql x86_64 5.0.89-1.el5 21Andy.com 3.5 M
mysql-server x86_64 5.0.89-1.el5 21Andy.com 10 M
nginx x86_64 0.8.33-3.el5 21Andy.com 422 k
php-cli x86_64 5.3.1-2.el5 21Andy.com 2.4 M
php-eaccelerator x86_64 2:0.9.6-1.el5 21Andy.com 118 k
php-fpm x86_64 5.3.1-2.el5 21Andy.com 1.2 M
php-gd x86_64 5.3.1-2.el5 21Andy.com 110 k
php-mbstring x86_64 5.3.1-2.el5 21Andy.com 1.1 M
php-mcrypt x86_64 5.3.1-2.el5 21Andy.com 27 k
php-mysql x86_64 5.3.1-2.el5 21Andy.com 84 k
php-pdo x86_64 5.3.1-2.el5 21Andy.com 91 k
php-pear noarch 1:1.9.0-1.el5 21Andy.com 420 k
php-pecl-memcache x86_64 2.2.5-3.el5 21Andy.com 44 k
php-tidy x86_64 5.3.1-2.el5 21Andy.com 31 k
php-xml x86_64 5.3.1-2.el5 21Andy.com 115 k
php-xmlrpc x86_64 5.3.1-2.el5 21Andy.com 48 k
Installing for dependencies:
gmp x86_64 4.1.4-10.el5 base 201 k
libXaw x86_64 1.0.2-8.1 base 329 k
libXmu x86_64 1.0.2-5 base 63 k
libXpm x86_64 3.5.5-3 base 44 k
libedit x86_64 2.11-2.20080712cvs.el5 epel 80 k
libmcrypt x86_64 2.5.8-4.el5.centos extras 105 k
libtidy x86_64 0.99.0-14.20070615.el5 epel 140 k
php-common x86_64 5.3.1-2.el5 21Andy.com 554 k
sqlite2 x86_64 2.8.17-5.el5 21Andy.com 165 k
t1lib x86_64 5.1.1-7.el5 epel 208 k
Updating for dependencies:
libevent x86_64 1.4.12-1.el5 21Andy.com 129 k
Transaction Summary
==========================================================
Install 26 Package(s)
Update 1 Package(s)
Remove 0 Package(s)
以下分別測試我本地的虛擬機器和 VPS 上 Nginx + php-fpm 的效能
我的本機虛擬機器測試,配置為PD930 雙核3.0G,2G記憶體,給虛擬機器分配的是 1G 記憶體,安裝的系統為 CentOS 5.4 64bit
測試內容為
<?php phpinfo();?>
500 並發測試,CPU使用率到了30%,系統負載在10左右,頁面開啟還是飛快
[root@localhost ~]# webbench -c 500 -t 30 http://127.0.0.1/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://127.0.0.1/
500 clients, running 30 sec.
Speed=223504 pages/min, 21806556 bytes/sec.
Requests: 111752 susceed, 0 failed.
2000 並發測試,CPU使用率35%,系統負載在18左右,頁面開啟還是飛快
[root@localhost ~]# webbench -c 2000 -t 30 http://127.0.0.1/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://127.0.0.1/
2000 clients, running 30 sec.
Speed=429494 pages/min, 39004788 bytes/sec.
Requests: 214747 susceed, 0 failed.
5000 並發測試,CPU使用率30%,系統負載到了35,頁面打還速度還不錯,看了這資料,前些天說的那個1500萬PHP請求也沒啥了
[root@localhost ~]# webbench -c 5000 -t 30 http://127.0.0.1/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://127.0.0.1/
5000 clients, running 30 sec.
Speed=788986 pages/min, 66952700 bytes/sec.
Requests: 394493 susceed, 0 failed.
還不過癮,變態一下,10000並發
10000 並發,CPU使用還是不到30%,系統負載從60左右一直升到1000左右,暈死!居然還能開啟!只是有點卡!負載到600多的時候居然不卡!瘋了,我這還是虛擬機器,webbench 還是在自己機上開的,汗,太強了
[root@localhost ~]# webbench -c 10000 -t 30 http://127.0.0.1/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://127.0.0.1/
10000 clients, running 30 sec.
Speed=1513718 pages/min, -17973622 bytes/sec.
Requests: 756859 susceed, 0 failed.
而我的 VPS , 2G記憶體,8核CPU測試,但我不是使用上面的 yum 安裝,而是全用原始碼編譯安裝的,測試結果如下:
500並發,CPU使用率20%,負載2左右
# webbench -c 500 -t 30 http://127.0.0.1/index.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://127.0.0.1/index.php
500 clients, running 30 sec.
Speed=120520 pages/min, -36244332 bytes/sec.
Requests: 60260 susceed, 0 failed.
2000並發,CPU使用率20%左右,負載2左右,沒啥變化
webbench -c 2000 -t 30 http://127.0.0.1/index.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://127.0.0.1/index.php
2000 clients, running 30 sec.
Speed=111454 pages/min, -44285944 bytes/sec.
Requests: 55727 susceed, 0 failed.
開到3000並發也一樣,但開啟頁面要等幾秒,突然一下出來,說明我進程開少了,還有餘地。
現在我明白了前幾天那個1500萬PHP請求還能穩定訪問是怎麼回事了,哈哈,你只要CentOS 5.4 64bit,再按我上面的 yum 方法安裝,也一樣能頂住。