technion
Posts: 238
Joined: Sun Dec 02, 2012 9:49 am

Varnish on Raspberry

Thu Jan 03, 2013 10:12 am

Hey guys,

I've managed to workaround several issues and setup a pi with nginx and Varnish. You can see my guide on this here:

http://www.lolware.net/raspberryvarnish.html

Faperdaper
Posts: 10
Joined: Sat Oct 22, 2011 9:40 am

Re: Varnish on Raspberry

Thu Jan 03, 2013 3:29 pm

Thanks for that guide. I've been trying to get varnish working all day, then I decided to take a break and head to the raspberry pi forums where I strumbled upon the thread. :D

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Mon Jan 21, 2013 9:35 pm

Thank you for the guide to install Varnish!

I'm trying to get it working, no luck so far. In the step "sh configure" I get this error:

Code: Select all

checking for PCRE... no
configure: error: Package requirements (libpcre) were not met:

No package 'libpcre' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables PCRE_CFLAGS
and PCRE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
Any idea what this means?

Thanks!
Andras
http://iqjar.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Mon Jan 21, 2013 9:40 pm

Solution:

Code: Select all

apt-get install libpcre3-dev
Andras
http://iqjar.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Mon Jan 21, 2013 10:34 pm

OK, I've successfully installed varnish (at least I got no errors...) by following your guide.
When I try to start it using start-varnish.sh, no errors are shown, one would believe that it actually starts. But if I run

Code: Select all

ps aux | grep varnish
I see no process named varnish. Is this normal? How can I test that it's actually working?

Thanks!
Andras
http://iqjar.com

technion
Posts: 238
Joined: Sun Dec 02, 2012 9:49 am

Re: Varnish on Raspberry

Tue Jan 22, 2013 7:41 am

If you can't see it in ps, it wouldn't be working.
It's hard to tell why - I can only say it worked for me.

What happens if you configure it with:
configure --enable-debugging-symbols --enable-diagnostics
Then re-run make, make install
Then go check /var/log/daemon for any errors after startup?

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Tue Jan 22, 2013 10:23 am

Hi! Thanks you for the help!
I've done what you suugested (reconfigured it, make again, make install again). Now, when I try to run the start-varnish.sh startup script, I get this:

Code: Select all

[email protected]:/soft/varnish# ./start-varnish.sh
Message from VCC-compiler:
No backends or directors found in VCL program, at least one is necessary.
Running VCC-compiler failed, exit 1

VCL compilation failed
Andras
http://iqjar.com

technion
Posts: 238
Joined: Sun Dec 02, 2012 9:49 am

Re: Varnish on Raspberry

Tue Jan 22, 2013 10:26 am

sudo vi /usr/local/etc/varnish/default.vcl

That error would suggest that the default config file is in place. It may have bene overwritten during the reinstall.

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Tue Jan 22, 2013 10:46 am

Indeed, that was the problem. The file was overwritten during install. So I fixed the config file and now I get no error when I start Varnish, but I don't think it really starts. "ps aux | grep varnish" still shows nothing. There is no error in daemon.log.
:(
Andras
http://iqjar.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Tue Jan 22, 2013 8:59 pm

OK, I give up :) I have no idea how to get it working.
Is there any way I can uninstall it?

Thanks!
Andras
http://iqjar.com

technion
Posts: 238
Joined: Sun Dec 02, 2012 9:49 am

Re: Varnish on Raspberry

Tue Jan 22, 2013 9:31 pm

You should be able to:
make uninstall

In order to remove it.

However, I would suggest that it's worth trying to "make clean" then "make install" again.
That will clobber your config file again (which I think is a Varnish bug).

I've just noted that reconfiguring it as per the flags I gave you doesn't actually recompile anything unless you "clean" it first.

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Tue Jan 22, 2013 10:33 pm

"make uninstall" - wow! I never can stop being surprised by the greatness of the Linux command line world!

OK, thank you for the cleaning suggestion, I will try it.
Andras
http://iqjar.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Tue Jan 22, 2013 11:09 pm

I'm starting to wonder how exactly the backend servers should be set up in the default.vlc file. All I did was uncomment the default backend and set the port to 80 (which is my Apache port). Is this correct?

Code: Select all

backend default {
    .host = "127.0.0.1";
    .port = "80";
}
Andras
http://iqjar.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Tue Jan 22, 2013 11:12 pm

I did the make clean, configure, make, make install again, as you suggested, but nothing has changed. It still doesn't run. I wish it would at least give some error message instead of this silent death.
I've read good things about Varnish and on a system with the hardware resources of the Pi it could probably work wonders. too bad it doesn't work...
Andras
http://iqjar.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Tue Jan 22, 2013 11:25 pm

I managed to extract some error messages from /var/log/syslog:

Code: Select all

Jan 23 01:24:13 raspberrypi varnishd[10570]: Platform: Linux,3.6.11+,armv6l,-smalloc,-smalloc,-hcritbit
Jan 23 01:24:14 raspberrypi varnishd[10570]: Child start failed: could not open sockets
Seems to be some networking error...
Andras
http://iqjar.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Tue Jan 22, 2013 11:43 pm

I wonder if the problem could be that Apache and Varnish are both configured to listen on port 80. I thought they were supposed to work together somehow, but now I'm not so sure anymore...
Andras
http://iqjar.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Tue Jan 22, 2013 11:51 pm

I have stopped the Apache2 service and tried to start varnish like that. And surprise, surprise, it works!
I'm a bit confused... Having Varnish means getting rid of Apache?

With Varnish not all of my pages work well. For some I get the error: "Error 413 Request Entity Too Large"
Andras
http://iqjar.com

technion
Posts: 238
Joined: Sun Dec 02, 2012 9:49 am

Re: Varnish on Raspberry

Wed Jan 23, 2013 2:03 am

Un4Seen wrote:I have stopped the Apache2 service and tried to start varnish like that. And surprise, surprise, it works!
I'm a bit confused... Having Varnish means getting rid of Apache?
Varnish is meant to take the place of the primary thing receiving your service. The idea is, you use the "backend" configuration in default.vcl to tell Varnish where your real website is, which in your case, is running Apache2.

The trick will be to edit Apache's configuration to run on a port other than 80, such as 81. You should be able to start Apache and Varnish in this configuration.
The purpose of Varnish is the store in memory a copy of your website, so that, once that .png files you referred to have been downloaded once, they won't need to be read from the disk again, and everything should run faster.

EDIT: I just noticed you set your backend server to localhost, port 80. This alternate config should be fine, IF you tell varnish not to use localhost. If your IP is static, you can edit the start script to use:
-a address:80

Where "address" is your public IP. You will now have varnish on your public IP and apache on the localhost, both port 80.

titanicsaled
Posts: 15
Joined: Tue Feb 28, 2012 4:24 pm
Contact: Website

Re: Varnish on Raspberry

Wed Jan 23, 2013 10:06 am

Does varnish provide a significant speed boost for the Pi?

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Wed Jan 23, 2013 10:42 am

I've tried to tell Varnish to use the public IP and port 80 while leaving Apache on localhost and port 80, but for some reason as soon as I specify the address in the startup script, Varnish fails to start:

Code: Select all

Jan 23 12:34:06 raspberrypi varnishd[1390]: Child start failed: could not open sockets
This happens regardless if Apache is running or not.

My Varnish startup script looks like this:

Code: Select all

#!/bin/sh

ulimit -n 10240
ulimit -l 16384
/usr/local/sbin/varnishd -f /usr/local/etc/varnish/default.vcl \
        -a X.Y.Z.W:80 \
        -s malloc,16M -l 8m,1m,+ -u varnishd
If I remove the -a parameter (the address line), Varnish starts (if I stop Apache, of course).
Perhaps the only solution is to move Apache to a different port.
Andras
http://iqjar.com

Faperdaper
Posts: 10
Joined: Sat Oct 22, 2011 9:40 am

Re: Varnish on Raspberry

Wed Jan 23, 2013 1:14 pm

Un4Seen wrote:Perhaps the only solution is to move Apache to a different port.
True, Apache has to listen on another port than 80, since Varnish is going to use port 80. Now if you access the website, Varnish will ask Apache for the webpage and cache it and then serve it to the webbrowser.

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Varnish on Raspberry

Wed Jan 23, 2013 1:30 pm

I'm wondering if, for testing purposes, I could start Varnish on port 81 and leave Apache on 80.
I suspect that the Varnish default backend file should be left with the 80 value in it and the varnish startup script should somehow specify 81 as the port. Unfortunately if I try adding the "-a IP:PORT" option into the startup script, Varnish doesn't start anymore...
Andras
http://iqjar.com

technion
Posts: 238
Joined: Sun Dec 02, 2012 9:49 am

Re: Varnish on Raspberry

Wed Jan 23, 2013 9:36 pm

titanicsaled wrote:Does varnish provide a significant speed boost for the Pi?
It would depend heavily on use case.
If your lag is mostly related to CPU use whilst PHP pages execute, boost would be minor.

If your lag is mostly related to SD card speed whilst reading files, particularly static files such as images, speed increase should be very significant.

technion
Posts: 238
Joined: Sun Dec 02, 2012 9:49 am

Re: Varnish on Raspberry

Wed Jan 23, 2013 9:37 pm

Un4Seen wrote:I'm wondering if, for testing purposes, I could start Varnish on port 81 and leave Apache on 80.
I suspect that the Varnish default backend file should be left with the 80 value in it and the varnish startup script should somehow specify 81 as the port. Unfortunately if I try adding the "-a IP:PORT" option into the startup script, Varnish doesn't start anymore...

Unfortunately I'm just not sure about this one - I've always run Varnish on its default port and only tested it this way.

Return to “Networking and servers”