【问题标题】:force mediawiki squid cache to fill up with all pages强制 mediawiki squid 缓存填满所有页面
【发布时间】:2016-02-14 05:56:24
【问题描述】:

为了加快 MediaWiki 站点的速度,该站点的内容使用大量模板,但在模板完成工作后几乎具有静态内容,我想设置一个 squid 服务器 见

https://www.mediawiki.org/wiki/Manual:PurgeList.php

https://www.mediawiki.org/wiki/Manual:Squid_caching

然后使用脚本执行 wget/curl 调用来“自动”填充 squid 服务器的缓存,该脚本会访问 Mediawiki 的所有页面。我的预期是,在这个过程之后,每个页面都在 squid 缓存中(如果我把它做得足够大的话),然后每次访问都将由 squid 完成。

我怎样才能让它发挥作用? 例如:

  1. 如何检查我的配置?
  2. 如何知道需要多少内存?
  3. 如何检查页面是否在 squid3 缓存中?

到目前为止我尝试了什么

我开始了解如何使用以下方法安装 squid:

我查到了我的ip地址xx.xxx.xxx.xxx(这里不公开) 通过 ifconfig eth0

在 /etc/squid3/squid.conf 我放了

http port xx.xxx.xxx.xxx:80 transparent vhost defaultsite=XXXXXX
cache_peer 127.0.0.1 parent 80 3130 originserver 

acl manager proto cache_object
acl localhost src 127.0.0.1/32

# Allow access to the web ports
acl web_ports port 80
http_access allow web_ports

# Allow cachemgr access from localhost only for maintenance purposes
http_access allow manager localhost
http_access deny manager

# Allow cache purge requests from MediaWiki/localhost only
acl purge method PURGE
http_access allow purge localhost
http_access deny purge

# And finally deny all other access to this proxy
http_access deny all

然后我配置了我的 apache2 服务器

# /etc/apache2/sites-enabled/000-default.conf   
Listen 127.0.0.1:80

我加了

$wgUseSquid = true;
$wgSquidServers = array('xx.xxx.xxx.xxx');
$wgSquidServersNoPurge = array('127.0.0.1');

到我的 LocalSettings.php

然后我重新启动 apache2 并使用 squid3 启动

service squid3 restart

并进行了第一次访问尝试

wget --cache=off -r http://XXXXXX/mediawiki

结果是:

Resolving XXXXXXX (XXXXXXX)... xx.xxx.xxx.xxx
Connecting to XXXXXXX (XXXXXXX|xx.xxx.xx.xxx|:80... failed: Connection refused.

【问题讨论】:

    标签: apache caching mediawiki squid


    【解决方案1】:

    假设 Apache 2.x.

    虽然与 Squid 无关,但您可以仅使用 Apache 模块来实现此目的。在这里查看 mod_cache:https://httpd.apache.org/docs/2.2/mod/mod_cache.html

    您可以简单地将其添加到您的 Apache 配置中,并要求 Apache 对呈现的内容进行磁盘缓存。

    您需要确保您的内容在生成的 PHP 响应中具有适当的缓存过期信息,MediaWiki 应该为您处理这一点。

    添加这样一个缓存层可能不会产生预期的结果,因为该层不知道页面是否已更改,缓存管理在这里很困难,只能用于实际的静态内容。

    Ubuntu:

    a2enmod cache cache_disk
    

    Apache 配置:

    CacheRoot /var/cache/apache2/mod_disk_cache
    CacheEnable disk /
    

    我不建议通过访问每个页面来预先填充缓存。这只会导致休眠(不经常使用)页面占用宝贵的空间/内存。如果你还想这样做,你可以看看 wget:

    Description from: http://www.linuxjournal.com/content/downloading-entire-web-site-wget
    $ wget \
         --recursive \
         --no-clobber \
         --page-requisites \
         --html-extension \
         --convert-links \
         --restrict-file-names=windows \
         --domains website.org \
         --no-parent \
             www.website.org/tutorials/html/
    
    This command downloads the Web site www.website.org/tutorials/html/.
    
    The options are:
    
        --recursive: download the entire Web site.
    
        --domains website.org: don't follow links outside website.org.
    
        --no-parent: don't follow links outside the directory tutorials/html/.
    
        --page-requisites: get all the elements that compose the page (images, CSS and so on).
    
        --html-extension: save files with the .html extension.
    
        --convert-links: convert links so that they work locally, off-line.
    
        --restrict-file-names=windows: modify filenames so that they will work in Windows as well.
    
        --no-clobber: don't overwrite any existing files (used in case the download is interrupted and
        resumed).
    

    更好的选择:Memcached

    MediaWiki 还支持将 Memcached 用作仅用于数据和模板的非常快速的内存缓存服务。这不像 Squid 或 Apache mod_cache 这样的网站范围缓存那么残酷。 MediaWiki 将管理 Memcached,以便任何更改立即反映在缓存存储中,这意味着您的内容将始终有效。

    请在此处查看 MediaWiki 的安装说明:https://www.mediawiki.org/wiki/Memcached

    我的建议是不要使用 Apache mod_cache 或 Squid 来执行此任务,而是安装 Memcached 并配置 MediaWiki 以使用它。

    【讨论】:

    • 感谢您查看此内容和详细答案。我要鱿鱼的原因现在已添加到问题中。 Mediawiki 可以与 squid 对话,但我不知道它是否会与您在这里提出的 apache 提案对话。
    • 传统上,Mediawiki 被设计为部署在 LAMP 风格的环境(Linux、Apache、MySQL、PHP)中,我已经多次以这种风格部署它。假设您遵循该结构,那么上述内容将正常工作,因为您已经将 Apache 用作您的 HTTP 前端。 Apache 中的 mod_cache 的行为类似于您在此处尝试设置的 Squid 缓存。尽管如此,我不认为像 Squid / Apache 这样的内容缓存在这里会是一个好的选择,像 Memcached 这样设计到 Mediawiki 中的缓存加速器会更适合。
    • 这是一个绝对错误和有害的答案:您混合了不同的缓存层并且没有考虑清除。 Mecached 是一个 _object* 缓存。 MW 使用它来缓存昂贵的查询/计算的结果。对于高性能 wiki(或者,对于单个应用服务器,APC 共享存储)来说,这是必需的,但这还不够。 Squid(或者,更好的是 Varnish)是一个 HTTP 缓存。它缓存生成的 HTTP 响应,因此可以极大地减少 Apache 负载。如果没有经过良好调整的 HTTP 缓存,Wikipedia 将无法在当前的负载水平下运行。
    • (续)说到 mod_cache,我还没有听说有人将它与 MW 一起使用,因此我怀疑它是否得到完全支持。例如,它是否支持在页面编辑时清除 HTCP 以避免提供过时的数据?
    猜你喜欢
    • 1970-01-01
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    • 2013-11-05
    • 1970-01-01
    相关资源
    最近更新 更多