六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 698|回复: 0

配置lighttpd mod_mem_cache 模块做静态资源服务器

[复制链接]
 楼主| 发表于 2013-12-11 19:29:25 | 显示全部楼层 |阅读模式
一   lighttpd 简介
Lighttpd 是一个德国人领导的开源Web服务器软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的web server环境。具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。
二 下载lighttpd,并编译安装lighttpd
     wget http://lighttpd-improved.googlec ... he.v.1.8.3-2.tar.gz
     #tar  xf  lighttpd-1.4.26.modcache.v.1.8.3-2.tar.gz
     #cd   lighttpd-1.4.26
     # ./configure --prefix=/usr/local/lighttpd --with-zlib --with-bzip2 --with-memcache
     #make && make install
     #cd  doc
     #cp   rc.lighttpd.redhat    /etc/init.d/lighttpd
     #cp sysconfig.lighttpd  /etc/sysconfig/lighttpd
     #vim /etc/sysconfig/lighttpd  
      修改如下
       LIGHTTPD_CONF_PATH=/usr/local/lighttpd/conf/lighttpd.conf
     #
     #chmod 700   /etc/init.d/lighttpd
     #vim 修改如下选项
       config: /usr/local/lighttpd/conf/lighttpd.conf
       config: /etc/sysconfig/lighttpd
       pidfile: /var/run/lighttpd.pid
       LIGHTTPD_CONF_PATH="/usr/local/lighttpd/conf/lighttpd.conf"
       lighttpd="/usr/local/lighttpd/sbin/lighttpd"
     #mkdir /usr/local/lighttpd/{cache,logs,conf,htdocs}
     #cp  lighttpd.conf /usr/local/lighttpd/conf
三 配置详解
  #cd  /usr/local/lighttpd/conf
  # cat lighttpd.conf

  # lighttpd configuration file
  #
  # use it as a base for lighttpd 1.0.0 and above
  #
  # $Id: lighttpd.conf,v 1.7 2004/11/03 22:26:05 weigon Exp $

  ############ Options you really have to take care of ####################
  ## modules to load
  # at least mod_access and mod_accesslog should be loaded
  # all other module should only be loaded if really neccesary
  # - saves some time

  # - saves memory
  #lighttpd 加载的模块
  server.modules              = (
                                "mod_rewrite",
                                "mod_redirect",
                                "mod_access",
                                "mod_expire",
                                "mod_mem_compress",
                                "mod_compress",                        
                                "mod_mem_cache",
                                "mod_cache",
                                "mod_dirlisting",

                                "mod_status",,
                                "mod_fastcgi",
                                "mod_proxy",                        
                                "mod_usertrack",
                                "mod_accesslog" )
  ## a static document-root, for virtual-hosting take look at the
  ## server.virtual-* options
  server.document-root        = "/usr/local/lighttpd/htdocs/"
  ## where to send error-messages to
  server.errorlog             = "/usr/local/lighttpd/logs/error.log"  /
http://tech.ddvip.com/2013-03/1364128553192508.html

Lighttpd +mod_mem_cache的效果简直太好了


    公司的图片服务器一直以来负载都比较高,原因是图片比较分散而且比较小。经常把iowait搞的特别的高。但是只有一台机器也法用squid,经测试squid和apache在同一台机器效果会很糟糕的。因为squid要写磁盘,Apache要读磁盘(本公司的情况是大量的随机读)。
      经过测试,决定用lighttpd加上一个国产的模块mod_mem_cache来缓解次问题。经过一天的运行,通过数据的分析,感觉效果简直太明显了。
      之前iowait会达到20-30现在最高维持到6左右。
     负载有以前的10下降到1以下。
     以下是命中率的统计:
      
       mem-cache.cached-items: 843700
     mem-cache.hitrate(%): 91
     mem-cache.used-memory(MB): 2047


       安装方法很简单,只需要到官方网站上下载支持mod_mem_cache的patch,安装方法没有什么特别的。安装好后在配置文件中加入如下几行:

    mem-cache.filetypes = ("image/jpg", "image/gif", "image/bmp", "image/png","image/jpeg")#Cache image file in memory
    mem-cache.max-memory = 2048 # Use 1G memory cache
    mem-cache.max-file-size = 64 # Cache maxium 1M-size file

   
    如果有类似问题的公司也采用此方法,相信lighttpd+mod_mem_cache不会让你失望的。http://tech.ddvip.com/2013-03/1364128553192508.html

该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

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