directadmin安装Varnish缓存记录笔记.

资料来源jybb.me和zmrbk.com

组件装一下吧:

$ yum -y install automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig
$ apt-get install automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig

添加varnish官方源并安装

debian和ununtu

$ curl http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add -
$ echo "deb http://repo.varnish-cache.org/debian/ squeeze varnish-3.0" >> /etc/apt/sources.list
$ apt-get update
$ apt-get install varnish

CentOS 5

$ rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.el5.centos.noarch.rpm

Centos6

$ rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release/varnish-release-3.0-1.el6.noarch.rpm

开始安装好 Varnish:

centos $ yum -y install varnish ##  
debian or ubuntu $ apt-get install varnish

修改各个配置.
命令里面有“1.2.3.4”请把它改为你服务器的 IP:

sed -i 's/.port = "80";/.port = "8080";/g' /etc/varnish/default.vcl
sed -i 's/Listen 80/Listen 8080/g' /etc/httpd/conf/httpd.conf
sed -i 's///g' /etc/httpd/conf/extra/httpd-vhosts.conf
mkdir /usr/local/directadmin/data/templates/custom
cp -p /usr/local/directadmin/data/templates/virtual_host2.conf /usr/local/directadmin/data/templates/custom/virtual_host2.conf
cp -p /usr/local/directadmin/data/templates/virtual_host2_sub.conf /usr/local/directadmin/data/templates/custom/virtual_host2_sub.conf
cp -p /usr/local/directadmin/data/templates/redirect_virtual_host.conf /usr/local/directadmin/data/templates/custom/redirect_virtual_host.conf
sed -i 's///g' /usr/local/directadmin/data/templates/custom/*
sed -i 's/VARNISH_LISTEN_PORT=6081/VARNISH_LISTEN_PORT=80/g' /etc/sysconfig/varnish

安装 rpaf 获取真实 IP.
Apache 2.2 安装方法:

wget http://www.stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
tar xzf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6
apxs -cia mod_rpaf-2.0.c

Apache 2.4 安装方法:

wget http://www.stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
tar xzf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6
yum -y install git
git clone git://gist.github.com/2716030.git
patch mod_rpaf-2.0.c 2716030/mod_rpaf-2.0.c.patch
apxs -cia mod_rpaf-2.0.c

安装好 rpaf 之后要修改 http 引入的配置:

vi /etc/httpd/conf/extra/httpd-includes.conf

在最底下加入如下代码:

#For the rpaf

RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1
RPAFheader X-Forwarded-For

DirectAdmin 更新一下配置:

echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue

最后:重启 Apache 与 Varnish,并设置开机启动.

service httpd restart
service varnish start
chkconfig varnish on
点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您必须启用 javascript 在这里查看验证码!

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据