设为首页 收藏本站
查看: 1612|回复: 0

[经验分享] 利用nginx的url_hash提高squid的缓存效率

[复制链接]
发表于 2018-12-27 12:44:04 | 显示全部楼层 |阅读模式
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 %

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-656489-1-1.html 上篇帖子: Squid 开启大内存导致进程内存溢出解决方法 下篇帖子: linux中squid的配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表