关于lighttpd的资料
分页: 1/2 第一页 1 2 下页 最后页 [ 显示模式: 摘要 | 列表 ]
今天某个服务器根分区已经满了,导致很多服务出错。

究其原因,是 /var/tmp 目录写满了文件:

引用
lighttpd-upload-eIZa83  lighttpd-upload-JwV3xq  lighttpd-upload-P44hE4  lighttpd-upload-Uinkoj  lighttpd-upload-Zs2kwX
lighttpd-upload-eJ03lT  lighttpd-upload-JWvG2m  lighttpd-upload-p4dNCH  lighttpd-upload-uIpAlx  lighttpd-upload-Zs3OTO
lighttpd-upload-eJ0Soy  lighttpd-upload-JwxFM6  lighttpd-upload-p4Fpth  lighttpd-upload-uiq7qV  lighttpd-upload-ZS9G7z
lighttpd-upload-Ej1kY9  lighttpd-upload-Jx3QIZ  lighttpd-upload-P4ghIw  lighttpd-upload-uiQ8r6  lighttpd-upload-ZSa7yh

容易从文件名称看出来跟lighttpd有关
检查lighttpd的配置得知,默认的上传路径是 /var/tmp

引用
Description
server.upload-dirs option
defaults to /var/tmp as we assume it is a local harddisk

server.upload-dirs = ( "/var/tmp" )

那相应的解决办法就是自己指定一个空间足够的目录了,比如:

server.upload-dirs = ("/Cache/aslibra.com/lighttpd-upload")

注意是数组的形式,那估计可以设定多个目录
Tags:
我个人喜欢用lighttpd作为php的web服务器,其中最欣赏的是信息统计。在这点上,apache和nginx还真的比不上,作为后端服务器,我比较推荐你使用,配置也简单。

安装和配置就不多说,网上另外可以找到。
我们看看lighttpd里面的一些监测设置:

status.status-url          = "/aslibra-status"
status.config-url          = "/aslibra-config"
status.statistics-url  = "/aslibra-counters"

第一个(status.status-url)是当前服务器的状态,一般情况下,你可以很清楚的知道现在在处理的是什么地址,也明白什么请求一直在处理并且处理了多少时间。很多时候你可以容易发现一些不容易看到的问题,毕竟处理时间久的请求肯定因为出问题了。
第二个(status.config-url)是服务器的配置,比如:
引用
lighttpd 1.4.20
Server-Features
RegEx Conditionals enabled
Network Engine
fd-Event-Handler linux-sysepoll
Config-File-Settings
Loaded Modules indexfile
rewrite
redirect
alias
access
status
fastcgi
proxy
expire
accesslog
dirlisting
staticfile

你可以知道现在加载的有什么模块,可以在配置里增添。
第三个(status.statistics-url)是今天要介绍的,它可以很清楚的知道php的压力分布,在mod_cache版本还可以知道缓存的命中率以及缓存的个数。

引用
fastcgi.active-requests: 0
fastcgi.backend.0.0.connected: 1145
fastcgi.backend.0.0.died: 0
fastcgi.backend.0.0.disabled: 0
fastcgi.backend.0.0.load: 0
fastcgi.backend.0.0.overloaded: 0
fastcgi.backend.0.load: 1
fastcgi.requests: 1145

你可以从上述信息了解到,当前php处理过1145个请求,压力很小,没有正在处理的php请求。

配置文件里,你可以自定义fastcgi服务器的名称来区分不同的请求,比如:

#默认的
fastcgi.server = ( ".php" =>(
    ( "host" => "127.0.0.1","port" => 9000,)
  )
)

$HTTP["host"] == "www.aslibra.com" {
  server.document-root = "/Data/webapps/www.aslibra.com"
  fastcgi.server = ( ".php" =>(
      "www"=>( "host" => "127.0.0.1","port" => 9000,)
    )
  )
}

$HTTP["host"] == "dl.aslibra.com" {
  server.document-root = "/Data/webapps/dl.aslibra.com"
  fastcgi.server = ( ".php" =>(
      "dl"=>( "host" => "127.0.0.1","port" => 9000,)
    )
  )
}

你可以看到如下的统计信息:
引用
fastcgi.active-requests: 3
fastcgi.backend.0.0.connected: 4775
fastcgi.backend.0.0.died: 0
fastcgi.backend.0.0.disabled: 0
fastcgi.backend.0.0.load: 0
fastcgi.backend.0.0.overloaded: 0
fastcgi.backend.0.load: 0
fastcgi.backend.dl.0.connected: 863
fastcgi.backend.dl.0.died: 0
fastcgi.backend.dl.0.disabled: 0
fastcgi.backend.dl.0.load: 0
fastcgi.backend.dl.0.overloaded: 0
fastcgi.backend.dl.load: 0
fastcgi.backend.www.0.connected: 696191
fastcgi.backend.www.0.died: 0
fastcgi.backend.www.0.disabled: 0
fastcgi.backend.www.0.load: 3
fastcgi.backend.www.0.overloaded: 0
fastcgi.backend.www.load: 3
fastcgi.requests: 701829

说明什么问题呢?

1 压力主要来自www,dl的站点php的处理压力很小
2 www的并发处理有3个,也许这个数字比较高时,你可以看看status.status-url里到底有哪些地址正在处理
3 都还没有发生php请求死掉(died)的情况,还是良好的

有了这些统计信息,有助于你避免一些问题的发生,总比蒙着眼睛用nginx和apache好。
Tags: , ,
lighttpd可以rewrite地址到一个php文件处理所有相关的请求,比如:
url.rewrite-once = (
        "^/c/" => "/page_c.php"
)

这个/是从网站根目录开始算的,所以不能指定其它目录的文件
需要制定其它目录的文件,那可以先alias处理,比如

$HTTP["host"] == "www.aslibra.com" {
        server.document-root = "/Data/webapps/www.aslibra.com"
        alias.url = (
                "/page_c.php" => "/Data/webapps/test.aslibra.com/page_c.php"
        )
        url.rewrite-once = (
                "^/c/" => "/page_c.php"
        )
}


先定义一个本地文件为文件系统的另外一个文件
然后rewrite到此文件即可!
Tags: ,
今日发现lighttpd的日志有大量的错误是同样的错误提示:

2009-05-21 18:39:06: (mod_cache.c.2080) failed to delete old cache file /cache/web/www.aslibra.com/search/article/11433 before update Is a directory


因为存在11433/1 的下级目录,而lighttpd根据地址认为 11433 是一个文件,删除的时候出错了,代码位置是:

   if (unlink(file->ptr) && errno != ENOENT) {
    log_error_write(srv, __FILE__, __LINE__, "sbss", "failed to delete old cache file",
      hctx->file, "before update", strerror(errno));


unlink只能删除文件,不能删除文件夹,所以删除失败。
在linux下同一个目录下不会有同名的文件和文件夹

[root@localhost test]# ll
total 8
-rw-r--r--  1 root root 1 May 24 02:08 a
[root@localhost test]# mkdir a
mkdir: `a' exists but is not a directory
[root@localhost test]# mkdir b
[root@localhost test]# ll
total 16
-rw-r--r--  1 root root    1 May 24 02:08 a
drwxr-xr-x  2 root root 4096 May 24 02:16 b
[root@localhost test]# echo>b
-bash: b: Is a directory


也就是说,如果 /a/1 的地址先访问,/a/1 的文件就先创建了
如果 /a/1/index.htm 先访问,/a/1 的文件夹先创建,老外一种形式就无法再缓存,这个就给后端带来了压力。

这个可以用redirect或者rewrite修正,参考做法:

$HTTP["host"] == "www.aslibra.com" {
  #指定规则补全地址
        url.redirect = (
                "^/search/(article|pic)/([^/]+)$" => "/search/$1/$2/",
        )
        $HTTP["url"] =~ "^/search/" {
    #可以重新制定目录缓存文件,避免原先的文件冲突
    cache.bases = ("/cache/web/search/")
                cache.support-queries = "disable"
        }
        proxy.server  = ( "" =>(
                ( "host" => "192.168.1.2")
        ))
}
Tags: , ,
一直使用lighttpd的modcache,作者博客是:

http://blog.quehy.com/

我一直不理解quehy是什么意思,query的变异?还是英文名?今天无意中看到人物介绍才理解意思:

引用
不知道你有没有印象,之前我介绍的magent就出自该牛人,顺便八卦一下,google了一下,果然强

“阙宏宇是一名传奇人物。阙宏宇却连跳数级,15岁便一举考中清华大学自动系,19岁被保送到中国科学院计算机系攻读硕士研究生。毕业后历任Chinaren校友录的技术总监和sohu无线事业部总监,sohu网站的闪电邮系统和chinaren的校友录架构都是以他为主开发的。”


出自:http://www.sysbus.com/?p=184

从名字我就知道域名的意思了,原来是强人一个,我也很希望以后能做点开源项目。

他启动的两个开源项目我都非常喜欢:
1 lighttpd的modcache
我一直在使用,已经代替了squid的位置,使用效果还是不错的
2 memagent
这个也很实用,一直也在考虑加强memcached的稳定性的问题,看来这又给我带来了解决方案

Tags:
lighttpd的cache功能一直使用的都比较不错:

1 配置简洁
2 cpu和内存占用不算多,性能良好

但也是有缺点的地方:

1 文件缓存数量巨大时在不断蚕食内存,最好有大内存的服务器做这事,当然了,缓存项目多了自然占用内存多

引用
cache.cached-itmes: 707831
cache.hitrate(%): 18
cache.memory-inuse(KB): 44239
#这个状态会占用了500多M内存


2 文件体系的缓存模式,不知道是否在文件夹文件过多的时候效率不好呢,猜的
3 不知道是否协议上的小问题,导致部分缓存不成功
4 单进程重启有中断

今天是讨论这第三点,在日志里可以找到症状:

引用
2009-04-22 19:18:26: (mod_cache.c.1336) ignore no content-length and no chunked transfer-encoding uri /
2009-04-22 19:18:37: (mod_cache.c.1336) ignore no content-length and no chunked transfer-encoding uri /article/4559/
2009-04-22 19:18:44: (mod_cache.c.1336) ignore no content-length and no chunked transfer-encoding uri /article/4559/
2009-04-22 19:19:01: (mod_cache.c.1336) ignore no content-length and no chunked transfer-encoding uri /article/4559/
2009-04-22 19:19:09: (mod_cache.c.1336) ignore no content-length and no chunked transfer-encoding uri /aslibra/com/
2009-04-22 19:19:24: (mod_cache.c.1336) ignore no content-length and no chunked transfer-encoding uri /aslibra/com/


某些PHP处理的请求一直都缓存不上,幸好后端服务器加了缓存控制,否则会疯了的。
Tags: , ,
点击在新窗口中浏览此图片

图:更换lighttpd+php fast-cgi的变化

原先服务器是apache的,加载php5模块,还有mysql运行,但一直负载很高,把mysql用到局域网的另外一个机器,占用CPU更加高,快疯了。可能apache进程太多,每个进程都吃太多内存了?具体原因不知道。

昨天晚上把php-fastcgi安装好了,打包文件见新浪的资料共享:
http://ishare.iask.sina.com.cn/cgi-bin/fileid.cgi?fileid=4537134

安装好后,把apache的日志对应lighttpd写好,转换好之前的配置,然后发现一个问题,rewrite后的url已经是变化了的,大家要注意(示例说明):


$HTTP["host"] == "test.aslibra.com" {
  url.rewrite-once = (
        "^/s" => "/__s.php",
  )
  server.document-root = "/Data/webapps/test.aslibra.com"
        $HTTP["url"] =~ "^\/__s" {
        accesslog.filename = "|/Data/apps/cronolog/sbin/cronolog /log/%Y/%m/%d/sub.%m%d%H"
        }
}


启动后,负载变轻了好多好多,流量还正常。
看来php的fast-cgi应该好好配置好,apache的确有点重了。。
不过今天有发现假死情况,重启也无法启动lighttpd,不知道是否php-cgi占用内存多了还是啥,有待观察。。。
Tags:
分页: 1/2 第一页 1 2 下页 最后页 [ 显示模式: 摘要 | 列表 ]

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐