|
nginx的url_hash模块(第三方)
含义:按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效。
nginx本身是不支持url_hash的,需要打第三方的patch,下载地址:
http://anotherbug.blog.chinajavaworld.com/servlet/AttachmentServlet/download/123297-4298-2148/nginx_upstream_hash-0[1].2.tar.gz
See http://wiki.codemongers.com/NginxHttpUpstreamRequestHashModule for more details.
关于nginx的url_hash模块的解释就到此为止,下面我们来看看怎么用nginx的url_hash模块来提高squid的缓存效率的:
一.实验环境
四台服务器,主机名和IP分别为:
192.168.4.191----------nginx
192.168.4.188----------squid01
192.168.4.190----------squid02
192.168.4.189----------真实web
二.nginx和squid的安装
1.nginx以及nginx的url_hash模块的安装
wget http://anotherbug.blog.chinajavaworld.com/servlet/AttachmentServlet/download/123297-4298-2148/nginx_upstream_hash-0[1].2.tar.gz
wget http://www.nginx.eu/download/sources/nginx-0.5.21.tar.gz
1) tar -zxvf nginx_upstream_hash-0.2.tar.gz -C /usr/local
mv nginx_upstream_hash-0.2 nginx
2) tar -zxvf nginx-0.5.21.tar.gz
cd nginx-0.5.21
patch -p0 < /usr/local/nginx/nginx-0.5.21.patch
./configure --with-http_stub_status_module --add-module=/usr/local/nginx/
make && make install
3) cd /usr/local/nginx/conf/
vi nginx.conf 内容如下:
user nobody nobody;
worker_processes 4;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
# include mime.types;
default_type application/octet-stream;
keepalive_timeout 20;
tcp_nodelay on;
upstream www.jialisong.com {
server 192.168.4.188 ;
server 192.168.4.190 ;
hash $request_uri;
}
server
{
listen 80;
server_name www.jialisong.com;
location / {
proxy_pass http://www.jialisong.com;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /usr/local/nginx/logs/access_log ;
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
# auth_basic_user_file htpasswd;
}
}
}
4) /usr/local/nginx/sbin/nginx -t 测试nginx的配置文件
/usr/local/nginx/sbin/nginx 启动nginx
2.squid服务器的安装
1)tar -jxvf squid-2.7.STABLE5.tar.bz2
cd squid-2.7.STABLE5
./configure --prefix=/usr/local/squid --enable-dlmalloc --with-pthreads --enable-poll --disable-internal-dns --enable-stacktrace --enable-removal-policies="heap,lru" --enable-delay-pools --enable-storeio="aufs,coss,diskd,ufs"
make && make install
useradd -s /sbin/login squid
chown -R squid:squid /usr/local/squid/var/
mkdir /tmp1
chmod -R 777 /tmp1
2) cd /usr/local/squid/etc/
vi squid.conf
内容如下:
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl Localhost src 127.0.0.1 192.168.4.188 192.168.4.191
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80
acl CONNECT method CONNECT
#acl SNMP snmp_community public
#acl myip dst 192.168.4.191
#http_access deny !myip
http_access allow all
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
#snmp_access allow SNMP Localhost
#acl myip dst 192.168.30.93
#http_access deny !myip
#acl Manager proto cache_object
#acl Localhost src 127.0.0.1 192.168.30.93
#http_access allow Manager Localhost
#http_access deny Manager
#acl Safe_ports port 81
#http_access deny !Safe_ports
#http_access allow all
#acl OverConnLimit maxconn 16
#http_access deny OverConnLimit
http_access deny all
icp_access allow all
http_port 192.168.4.188:80 vhost vport
cache_peer 192.168.4.189 parent 80 0 no-digest no-query originserver name=www
cache_peer_domain www www.jialisong.com
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
cache deny QUERY
cache_mem 300 MB
maximum_object_size_in_memory 4096 KB
cache_dir ufs /tmp1 2048 16 512
ie_refresh on
cache_swap_low 90
cache_swap_high 95
#ipcache_size 4096
#ipcache_low 90
#ipcache_high 95
fqdncache_size 1024
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs % |
|
|
|
|
|
|