用戶端 | ===> |負載平衡器| ===> |反向 Proxy/緩衝| ===> |web伺服器| ===> |資料庫教程伺服器|
-------- ---------- ------------- --------- ------------
nginx squid apache,php mysql教程
eaccelerator/memcache準備工作:
引用伺服器: intel(r) xeon(tm) cpu 3.00ghz * 2, 2gb mem, scisc 硬碟
操作系統:centos4.4,核心版本2.6.9-22.elsmp,gcc版本3.4.4
軟體:
apache 2.2.3(能使用mpm模式)
php 5.2.0(選用該版本是因為5.2.0的引擎相對更高效)
eaccelerator 0.9.5(加速php引擎,同時也可以加密php源程式)
memcache 1.2.0(用於快取常用資料)
libevent 1.2a(memcache工作機制所需)
mysql 5.0.27(選用二進位版本,省去編譯工作)
nginx 0.5.4(用做負載平衡器)
squid-2.6.stable6(做反向 Proxy的同時提供專業緩衝功能)
二、編譯安裝
一、) 安裝nginx
1.) 安裝
nginx發音為[engine x],是由俄羅斯人igor sysoev建立的項目,基於bsd許可。據說他當初是f5的成員之一,英文首頁:http://nginx.net。俄羅斯的一些大網站已經使用它超過兩年多了,一直表現不凡。
nginx的編譯參數如下:
[root@localhost]#./configure --prefix=/usr/local/server/nginx --with-openssl=/usr/include
--with-pcre=/usr/include/pcre/ --with-http_stub_status_module --without-http_memcached_module
--without-http_fastcgi_module --without-http_rewrite_module --without-http_map_module
--without-http_geo_module --without-http_autoindex_module
在這裡,需要說明一下,由於nginx的配置檔案中我想用到正則,所以需要 pcre 模組的支援。我已經安裝了 pcre 及 pcre-devel 的rpm包,但是 ngxin 並不能正確找到 .h/.so/.a/.la 檔案,因此我稍微變通了一下:
[root@localhost]#mkdir /usr/include/pcre/.libs/
[root@localhost]#cp /usr/lib/libpcre.a /usr/include/pcre/.libs/libpcre.a
[root@localhost]#cp /usr/lib/libpcre.a /usr/include/pcre/.libs/libpcre.la
然後,修改 objs/makefile 大概在908行的位置上,注釋掉以下內容:
./configure --disable-shared
接下來,就可以正常執行 make 及 make install 了。
2.) 修改設定檔 /usr/local/server/nginx/conf/nginx.conf
以下是我的 nginx.conf 內容,僅供參考:
#運行使用者
user nobody nobody;
#啟動進程
worker_processes 2;
#全域錯誤日誌及pid檔案
error_log logs/error.log notice;
pid logs/nginx.pid;
#工作模式及串連數上限
events {
use epoll;
worker_connections 1024;
}
#設定http伺服器,利用它的反向 Proxy功能提供負載平衡支援
http {
#設定mime類型
include conf/mime.types;
default_type application/octet-stream;
#設定日誌格式
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
log_format download '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$http_range" "$sent_http_content_range"';
#設定請求緩衝
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
#開啟gzip模組
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
output_buffers 1 32k;
postpone_output 1460;
#設定access log
access_log logs/access.log main;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
#設定負載平衡的伺服器列表
ups教程tream mysvr {
#weigth參數表示權值,權值越高被分配到的幾率越大
#本機上的squid開啟3128連接埠
server 192.168.8.1:3128 weight=5;
server 192.168.8.2:80 weight=1;
server 192.168.8.3:80 weight=6;
}