Trang chủ / Linux / Cài đặt Varnish Cache trên DirectAdmin

Cài đặt Varnish Cache trên DirectAdmin

varnish-diagram3

Installing Varnish Cache on a DirectAdmin box is not complicated, just follow these steps:

 

Install dependencies:

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

For 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

For CentOS 6:

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

Now install Varnish Cache:

yum install varnish

Now edit /etc/varnish/default.vcl and make the following changes (we assume you are going to use port 8080 for Apache), obviously you need to change 123.123.123.123 to your own public IP address:

backend default {
        .host = "123.123.123.123";
        .port = "8080";
}

Now edit /etc/httpd/conf/httpd.conf and change the listening port to 8080:

Listen 8080

Edit  /etc/httpd/conf/extra/httpd-vhosts.conf and modify this:

Include /etc/httpd/conf/ips.conf

# -SNIP-
#
<VirtualHost 123.123.123.123:80>

To:

#Include /etc/httpd/conf/ips.conf
LogFormat "%O \"%r\"" homedir
NameVirtualHost 127.0.0.1:8080
NameVirtualHost 123.123.123.123:8080
NameVirtualHost 123.123.123.123:443
# -SNIP-
#
<VirtualHost 127.0.0.1:8080 123.123.123.123:8080>

Copy the DirectAdmin templates to the “custom” directory, so we can safely edit those files:

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

Now we need to change the template files, we are going to replace a variable in all files:

cd /usr/local/directadmin/data/templates/custom

sed -i 's/<VirtualHost |IP|:|PORT_80| |MULTI_IP|>/<VirtualHost 127.0.0.1:8080 |IP|:8080 |MULTI_IP|>/g' *

Next is installing the reverse proxy module for Apache:

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

If you have Apache 2.4 installed you will get an error when you execute apxs:

mod_rpaf-2.0.c:150: error: 'conn_rec' has no member named 'client_ip'
mod_rpaf-2.0.c:151: error: 'conn_rec' has no member named 'client_addr'
mod_rpaf-2.0.c:151: error: 'conn_rec' has no member named 'client_ip'
mod_rpaf-2.0.c: In function 'change_remote_ip':
mod_rpaf-2.0.c:164: error: 'conn_rec' has no member named 'client_ip' mod_rpaf-2.0.c:183: error: 'conn_rec' has no member named 'client_ip' mod_rpaf-2.0.c:186: error: 'conn_rec' has no member named 'client_ip' mod_rpaf-2.0.c:187: error: 'conn_rec' has no member named 'client_addr' mod_rpaf-2.0.c:187: error: 'conn_rec' has no member named 'client_ip' apxs:Error: Command failed with rc=65536

We need to patch the file before executing apxs:

yum install git
git clone https://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

Now edit /etc/httpd/conf/extra/httpd-includes.conf and add:

<IfModule mod_rpaf-2.0.c>
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1
RPAFheader X-Forwarded-For
</IfModule>

Now we let DirectAdmin change all the config files for your current users:

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

edit /etc/sysconfig/varnish and change the VARNISH_LISTEN_PORT to 80:

VARNISH_LISTEN_PORT=80

Now you can restart httpd and start varnish:

service httpd restart
service varnish start

And let’s make sure varnish starts after a server reboot:

chkconfig varnish on

 

Giới thiệu về Văn Phương

Văn Phương
Là một người bình thường, thích làm những việc bình thường cho mình và mọi người

Bài viết khác...

Tìm thông tin mật khẩu thiết lập ban đầu của Direct Admin(DA)

Sau khi cài xong thông tin cấu hình chi tiết được lưu ở đây: ‘/usr/local/directadmin/scripts/setup.txt’. ...

Bình luận