Jump to content


Photo

Install Varnish Cache on a DirectAdmin box


  • Please log in to reply
8 replies to this topic

#1 John

John

    Administrator

  • Administrators
  • 73 posts

Posted 06 January 2014 - 10:15 AM

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 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

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

  • danitfk likes this

#2 danitfk

danitfk

    Newbie

  • Members
  • Pip
  • 2 posts
  • LocationTehran

Posted 21 March 2014 - 06:45 AM

It's really good tip for installing Varnish on directadmin , and absolutely worked without any problems or issue.

Can you guide about optimize varnish?


  • John likes this

#3 John

John

    Administrator

  • Administrators
  • 73 posts

Posted 22 March 2014 - 10:34 AM

Thanks!

 

I'm not that familiar with Varnish yet, so I can't write a guide for it. Maybe somebody else that reads this can write a guide here?



#4 danitfk

danitfk

    Newbie

  • Members
  • Pip
  • 2 posts
  • LocationTehran

Posted 22 March 2014 - 10:54 AM

Thanks!

 

I'm not that familiar with Varnish yet, so I can't write a guide for it. Maybe somebody else that reads this can write a guide here?

Hmmm... Seems nice idea.

I will research about varnish and get some experience with this AWESOME cache server.


  • John likes this

#5 basante

basante

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 15 May 2014 - 01:41 PM

Hi,

 

I have multiple domains hosted on a directadmin box, is it posible to activate varnish only for one domain ?

If i change httpd listen port from 80 -> 8080 will not be affected all hosted sites ?

 

Regards,

Mihai



#6 basante

basante

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 16 May 2014 - 02:21 PM

any one ? 



#7 John

John

    Administrator

  • Administrators
  • 73 posts

Posted 05 June 2014 - 07:50 PM

The guide above will change *all* hosts to use Varnish cache. I'm not sure how you are able to use Varnish on one domain, sorry. 


  • firescanner likes this

#8 loganlo

loganlo

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 06 September 2014 - 10:33 PM

HI John .. i were follow the topic and i got stuck at here
 
[root@server mod_rpaf-0.6]# cd /usr/local/directadmin/data/templates/custom
[root@server custom]# sed -i 's/<VirtualHost |IP|:|PORT_80| |MULTI_IP|>/<VirtualHost 127.0.0.1:8080 |IP|:8080 |MULTI_IP|>/g' *
sed: couldn't edit mod_rpaf-0.6: not a regular file
 
i were skip the error and keep go to the step by step untill it done .. and after the install i got problem with httpd 
 
[root@server ~]# service httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd: httpd: Syntax error on line 87 of /etc/httpd/conf/httpd.conf: Syntax error on line 7 of /etc/httpd/conf/extra/httpd-includes.conf: </IfModule> without matching <IfModule> section
 
And i tried to rebuild httpd  by comants 
cd /usr/local/directadmin/custombuild
./build rewrite_confs
 
and the httpd can not restart !
 
Please can you help me to fix thiz cause my site down now :(
 
 
P/S i am using php 5.3.29 and Apache 2/ Centos 6.5
 
 
 
NOTE : i found the error and it was fix 
 
THANKS !!


#9 loganlo

loganlo

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 10 September 2014 - 11:25 PM

Hi John .. its me again :D

 

i still have problem with varnish... i thuoght it was run ok.. but its not. i got error 503 sometime.

 

and i duoble check varnish in ssh . its look ok 

Stopping Varnish Cache:                                    [  OK  ]
Starting Varnish Cache:                                    [  OK  ]
and i found out i stuck at here 
[root@server ~]# sed -i 's/<VirtualHost |IP|:|PORT_80| |MULTI_IP|>/<VirtualHost 127.0.0.1:8080 |IP|:8080 |MULTI_IP|>/g' *
sed: couldn't edit csf: not a regular file
 
i were try to reinstall a again and i have same problem.
 
apache still running on 80 ..  i did edit the file httpd.conf Listen 8080 . 
Please can you tell me where did i do wrong ! 
THanks !!!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users