I have been working on getting the Varnish module to work with Varnish 3 servers, and I think I have a solution that will work for all versions from 2.0 to 3.x.
This patch changes the varnish_legacy variable to varnish_version, we can then use the version number to determine which commands we need to execute in different situations.
The biggest change for us in varnish 3 is that the purge command has been changed to "ban". This patch fixes this by checking against the version number when doing a purge of specific pages.
The tests seems to pass for all versions I have tested (2.0.x, 2.1.x and 3.x), but I would really need some reviewers to test this out properly before commiting this.
This patch should solve the following issues automaticly:
#1171946: pressflow6 + varnish3b -- varnish working, but status report page is empty
#1179672: error on 'drush up', "WD varnish: Recieved status code 101 running purge req.http.host ..."
| Comment | File | Size | Author |
|---|---|---|---|
| #64 | default.txt | 10.43 KB | guruslot |
| #47 | 1179964-support-for-varnish-3-47.patch | 7.27 KB | joshk |
| #46 | 1179964-support-for-varnish-3-46.patch | 7.27 KB | joshk |
| #44 | 1179964-support-for-varnish-3-44.patch | 7.2 KB | joshk |
| #41 | 1179964-support-for-varnish-3-40.patch | 35.3 KB | joshk |
Comments
Comment #1
_-. commented@ attempt to get/apply this patch,
cd ./sites/all/modules/varnish
patch -p1 < /tmp/varnish3-compatibility.patch
patching file varnish.admin.inc
Hunk #1 FAILED at 31.
1 out of 1 hunk FAILED -- saving rejects to file varnish.admin.inc.rej
patching file varnish.module
patching file varnish.test
and,
cat varnish.admin.inc.rej
that's with,
drush @test pm-list | grep -i varnish
Caching Varnish (varnish) Module Enabled 6.x-1.x-dev
Comment #2
_-. commented'crossed in the mail' ...
drush @test up
...
Code updates will be made to the following projects: Varnish HTTP Accelerator Integration [varnish-6.x-1.x-dev]
...
patch -p1 < /data/webapps/varnish3-compatibility.patch
patching file varnish.admin.inc
patching file varnish.module
patching file varnish.test
can't replicate
#1179672: error on 'drush up', "WD varnish: Recieved status code 101 running purge req.http.host ..."
on demand, so i'll have to watch for that.
as for,
#1171946: pressflow6 + varnish3b -- varnish working, but status report page is empty
with patch in place, after just-in-case system reboot,
varnishd -V
varnishd (varnish-3.0.0-beta1 revision edd0d11)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2011 Varnish Software AS
@ https://.../admin/reports/varnish is still empty, and
varnishstat -1
client_conn 92 0.81 Client connections accepted
client_drop 0 0.00 Connection dropped, no sess/wrk
client_req 203 1.80 Client requests received
...
is populated, as expected.
Comment #3
fabsor commentedHmm... strange with the status page. It does work for me, but I will have to have a look on that again. Could you have a look in your watchdog and see if there are any errors from the varnish module after you go into the status page? If there are, please post the error code here, It will be easier for me to debug.
Comment #4
_-. commentedon nav to https://.../admin/reports/varnish, @ watchdog,
Jun 6 15:07:49 test6 loc-pf6: https://test6.loc|1307398069|varnish| 127.0.0.1|https://test6.loc/admin/reports/varnish||1||Recieved status code 101 running stats. Full response text: Unknown request.#012Type 'help' for more info.#012
hm. this make me a bit suspicious,
http://drupal.org/node/941788
'tho i don't see a 'secret' file anywhere.
EDIT: i think this is not relevant :-/
Comment #5
_-. commentedi'm able to reproducibly cause the reported error; unclear whether it's the ONLY way to cause it.
but,
iiuc, 'drush cc all' _should_ be the equivalent of running all of the other commands. apparently, there's a difference.
Comment #6
fabsor commentedI did another test run with my patch, and I really can't reproduce any of the bugs you are reporting. Did you go to the settings page and set the Varnish Version setting to 3.x ? If you don't, everything will fail miserably.
Also, make sure that you got the patch applied properly. If you see a drop-down of varnish versions on the varnish settings page (admin/settings/varnish), then you should be all set with the patch and you can ignore the rest of the instructions. If not, here is the procedure:
Get the code from git:
Go into the module directory, download the patch and apply it:
Hope that solves your problems!
Comment #7
_-. commented> Did you go to the settings page and set the Varnish Version setting to 3.x ? ... If you see a drop-down of varnish versions ... you can ignore the rest of the instructions.
yes, @ ".../admin/settings/varnish" i've set the dropdown to,
VARNISH VERSION: 3.x
that page also reports,
STATUS: Varnish running. Observer more detailed statistics .
where the link to,
.../admin/reports/varnish
works to redirect on click, but the report page's content, beneath the usual drupal site's headers, etc. is simply
blank :-/
i can verify that varnish is working -- pages are cached as expected, etc. reports at varnishstat/hist/etc at command line all are OK.
and, all other modules' reports etc are just fine. no additional errors reported in logs of my site; main status page is 'all systems go'.
Comment #8
_-. commentedminor progress?
upgrading to latest,
as well as latest drush, now
varnish status page in drupal admin still blank, though, and in watchdog log,
Jun 12 09:57:55 test6 loc-pf6: https://test6.loc|1307897875|varnish| 127.0.0.1|https://test6.loc/admin/reports/varnish||1||Recieved status code 101 running stats. Full response text: Unknown request.#012Type 'help' for more info.#012at cmd line, all's ok,
Comment #9
fabsor commentedAlright, so you are not getting the errors when clearing the cache anymore? That's a good thing, that means the module is probably working as intended. I can't really see why the stats page would stop working though, the stats command is still in place in the varnish terminal and I got everything working on my end.
I will keep digging and try to see what might have gone wrong with the stats page, too bad I don't have a way of reproducing this =/
Comment #10
_-. commented> you are not getting the errors when clearing the cache anymore?
not when doing 'drush cc all' ... which _was_ causing the error repeatedly before.
i've cleared & restarted everything, even rebooted. atm, no more error @ cache clear. at least none that I can initiate/repeat ...
the watchdog error _is_ repeatable at every visit to the varnish status page in drupal admin.
> too bad I don't have a way of reproducing this =/
that would make things far too easy ...
Comment #11
geekgirlweb commentedSilly me, I tried to apply this patch to the D7 version. Out of curiosity, does this apply to D7 or are these changes already committed/need to be committed to the D7 version?
Thanks!
Comment #12
fabsor commentedThis patch is for the D6 version, but it could be ported to D7 easily enough. It won't apply cleanly to the D7 branch right now though. My plan was to get this into stable D6 first and then port it do D7.
Comment #13
_-. commentedjust fyi, not that i expected it to make any difference, i switched to a build of official Varnish 3.0-RELEASE.
still no errors on cache clear -- good; but, stats page is still empty.
Comment #14
cedarm commentedDo we use the CLI interface? The stats command has been removed from the CLI interface (see Changes from 3.0 beta 1 to 3.0 beta 2).
Comment #15
_-. commentedi'd wrongly presumed that 'varnishstat' was being used -- that's what i'd compared output to @ cmd line above.
i suspect you may be have found a (the?) issue -- perhaps this, in 'varnish.admin.inc',
?
but then, fabsor says WORKSFORHIM ... ?
Comment #16
fabsor commentedHi!
I totally missed the fact that they removed the stats message, and I thought I updated my varnish install. Sorry about that, I have puppet scripts for a varnish 2.0, 2.1, and a 3, and it's hard to keep everything on track. I should have checked this.
I guess we have to remove the stats message for people that running Varnish 3. Using the varnishstats message directly from the module would require that the web user can run the varnishstat command, and I don't think we can support this for all environment, at least not in the stable 1.x release.
I will come back with a patch that simply removes the stats page for users with Varnish 3. Sorry again for missing out on the updated varnish version!
Comment #17
fabsor commentedSetting status.
Comment #18
_-. commented> Using the varnishstats message directly from the module would require that the web user can run the varnishstat command, and I don't think we can support this for all environment, at least not in the stable 1.x release.
fwiw, an out-of-the-box src build of varnish3,
ls -al /usr/local/bin/varnish*
-rwxr-xr-x 1 root root 25401 Jun 18 20:08 /usr/local/bin/varnishadm
-rwxr-xr-x 1 root root 20236 Jun 18 20:08 /usr/local/bin/varnishhist
-rwxr-xr-x 1 root root 30486 Jun 18 20:08 /usr/local/bin/varnishlog
-rwxr-xr-x 1 root root 29437 Jun 18 20:08 /usr/local/bin/varnishncsa
-rwxr-xr-x 1 root root 30706 Jun 18 20:08 /usr/local/bin/varnishreplay
-rwxr-xr-x 1 root root 20237 Jun 18 20:08 /usr/local/bin/varnishsizes
-rwxr-xr-x 1 root root 20381 Jun 18 20:08 /usr/local/bin/varnishstat
-rwxr-xr-x 1 root root 97812 Jun 18 20:08 /usr/local/bin/varnishtest
-rwxr-xr-x 1 root root 20408 Jun 18 20:08 /usr/local/bin/varnishtop
and,
sudo -u wwwrun varnishstat -1
where 'wwwrun' is the web user, works fine.
perhaps, rather than removing for all varnish3 cases, adding on the varnish 'admin'/stats page, an admin-option to ID the path to varnishstat, AND ensure that it has the perms to exec as the web user?
additionally, CLI access can already be secured by 'secret file' specification.
Comment #19
cedarm commentedIMHO trying to preserve the stats page is probably not worth the effort*. Don't forget that varnish is often on a different machine, so you can't just run varnishstat from a web server. (*we run a dedicated varnish box)
Comment #20
_-. commentedi'll disagree.
to the extent possible, providing the tools within Drupal & its modules to monitor what's going on in/with Drupal is a good idea. not all Drupal 'mgrs' will be given shell access @ the server ...
'stats' was a valued part of this module for v6 -- why would it be LESS so for D7?
as for bits-n-pieces running on other boxes -- that's true of, and possible for, just about everything. THAT config is in the vast minority, and IMHO, hardly a guideline for deciding mainstream applicability/value (inasmuch anyone using Varnish is in the mainstream in the 1st place ...)
Comment #21
fabsor commentedI don't want to hold back on the actual support for Varnish 3 because of the discussion about the logging issue, so I have created a separate issue where we could discuss how to implement logging for Varnish 3.
That way we can get a patch in that makes this module support Varnish 3 without logging for now, but the module will still do what actually is it's core purpose for Varnish 3 users, which is cache invalidation.
The issue about logging is here: #1195678: Varnish 3 and statistics. Feel free to start disussing this over there!
Comment #22
fabsor commentedHere is a patch that works with Varnish 3, but removes logging for Varnish 3 users for now.
Comment #23
_-. commentedthat's just D6-only for now, right?
Comment #24
cedarm commentedDo we care to add an update_N function to preserve the value of 'varnish_legacy' in the new 'varnish_version' variable?
Comment #25
fabsor commentedYes, we should have an update hook. I had it but forgot to add the file to the repository =) Here is a patch that includes and update hook.
@x746554 yes, this is just for D6 now. As soon as we get this in, we can create a port.
Comment #26
bleen commentedsub
Comment #27
rickvug commentedsub.
Comment #28
leenx commentedsub.
Comment #29
bleen commentedFYI: been using #25 on a dev site for about a week now with no problems to report :)
Comment #30
cyberwolf commentedSubscribing.
Comment #31
SeanBannister commentedsub
Comment #32
fabsor commentedTo all subscribers: If you are using this patch and it's working for you, please report back and tell us. Once we get a RTBC status, we can commit this!
Comment #33
mdorman commentedPatch #25 seems to be working fine for me, I had to manually apply the varnish.admin.inc changes so I'm attaching my patch as well. I was using the full 6.x.1.0 release, so may the one in #25 was applied to the dev version?
Comment #34
carlos8f commentedDefinitely works, I actually made the mistake of coding up virtually the same patch upon learning of the ban vs. purge API change. The CLI banner still says "Varnish Cache CLI 1.0" which is silly, otherwise we could detect the varnish version from the banner. Hooray for meaningless API changes!
BTW: I used #25 which applied to master, #33 did not apply.
Comment #35
fabsor commentedCommitted to 6.x. Thanks everyone! Now it's Drupal 7 time.
Comment #36
coolestdude1 commentedsub.
Comment #37
coolestdude1 commentedsorry about that wow fail
Comment #38
Fidelix commentedSubscribing...
Comment #39
joshk commentedHere's a patch for the D7 branch. Straight port of the existing patch at #25.
Comment #40
Fidelix commented@joshk, this patch is empty.... There was some error with your upload, I guess...
Comment #41
joshk commentedWhoops! Blank Patch!
Comment #42
joshk commentedHmm... that patch also looks wrong. Maybe I shouldn't try and chat with people while making patches.
Comment #43
fabsor commentedWe are definitely not going to have to include the README file in this patch, we should have a different issue for that. Also, it seems like this is a complete diff between the D6 and the D7 version.
Comment #44
joshk commentedYes, my drupal-git-fu is weak. issue branches and pull requests would be so much easier. Here's a corrected patch.
Comment #45
joshk commentedFixed my patch. README issue is here:
http://drupal.org/node/1260888
Comment #46
joshk commented#44 is missing a line in the status check. Corrected here.
Comment #47
joshk commentedUm and also #46 is missing a comma and mis-labeled a variable.
This one passes test. Next time I'll test before patching. :P
Comment #48
fabsor commentedI tested this across multipe varnish setups and it worked well. Commited to 7.x!
Comment #50
Anonymous (not verified) commentedFor Drupal 6, is 6.x-1.0 or 6.x-1.x-dev supporting Varnish 3 already, or do I need to apply the patches in this issue? If I need to apply a patch, which of the patches submitted in this issue should I apply? Any of the below, or another one maybe?
http://drupal.org/files/issues/1179964-support-for-varnish-3-47.patch
http://drupal.org/files/issues/varnish3-compatibility.patch
Comment #51
boyron commentedI am using drupal 6.x and varnish 3.x. So I have fixed this issue by manually applying those patch in 6.x varnish module.
Comment #52
klonos...please update the project's page. It still says:
Comment #53
theoldrupal commentedWhy isn't this in the stable branch for 6 yet?
Comment #54
fabsor commented@klonos The message is removed
@youdontmeanmuch I rolled a new release today for Drupal 6.
Comment #56
bibo commentedI'm sorry to reopen this, but as the latest stable release doesnt fully support Varnish 3, I decided this was the cleanest way to get your attention to:
http://drupal.org/node/1179672#comment-6754244. Varnish 3 works fine in dev, but not in the latest recommended release. And people wont notice it unless they check varnishlog (which few do).
To fix this I would suggest that you either:
- Create a new recommended release
OR
- State on the module page that Varnish 3 is not fully supported in beta1 (for D7 at least).
Comment #57
deggertsen commentedI'm using the most recent dev release and it would appear that it's not working. I'm not getting any errors and it says that Varnish is running, but when I watch the varnishlog all I see is:
0 CLI - Rd ping
0 CLI - Wr 200 PONG 1273698726 1.0
And when I check varnishtop -i rxurl I just get:
list length 0
Is there another issue to help with this? The documentation seems to be lacking.
Comment #58
mgiffordThe issue that @bibo mentioned was closed in August of this year #1179672: error on 'drush up', "WD varnish: Recieved status code 101 running purge req.http.host ..." but @deggertsen was reporting a problem still in September.
Not sure if this issue can be closed.
Comment #59
deggertsen commentedI still never got Varnish working so I gave up for the time being. Maybe I just need better documentation as I am a total Varnish noob, but I did get drupal saying that varnish was running it just wasn't actually caching anything as I believe it explained with the "list length 0".
Comment #60
guruslot commentedHi deggertsen, I just started with a module and found the following solution (for everyone who has 101 error): To make the module to work with a Varnish daemon you have to teach Daemon what to do. But that's simple. :)
https://www.varnish-cache.org/docs/3.0/tutorial/purging.html
Comment #61
deggertsen commented@guruslot, simple for you maybe ;). Could you paste an example of what you actually did? That documentation doesn't make much sense to me either.
Comment #62
guruslot commentedWell deggertsen, it wasn't easy at all as I had spent a few hours.
Ok. Works Varnish v. 3.04 with following configuration:
This is not a 'clean' code so any ideas on how to improve it are welcome.
Comment #63
klonos@guruslot: could you remove the code from your comment and upload a text file instead? That helps keeping the issue queues clean and pages load faster in slow/mobile devices. Thanx in advance.
Comment #64
guruslot commentedConfig file works out of a box. Tested with Varnish v. 3.04.
Feel free to improve the code.
Comment #65
JeremyFrench commentedI think current versions of the D7 branch work with varnish 3 I'll close this again, please check for other open issues if you can't get it working. So we can fix specific bugs rather than have a general support ticket.
Comment #66
JeremyFrench commentedComment #67
mgiffordThis isn't standard, don't know if 405 is valid or not
error 405 "Your ip banned via NSA"@guruslot thanks for contributing your default.vcl.
I do think we need a wiki or something in:
https://groups.drupal.org/high-performance
Would be good to consolidate some of these issues.
Comment #68
guruslot commentedmgifford, no problem.
405 designed for a bad guys only. Actually two different options are useful to look into in conjunction with varnish:
1. Fail2ban. Add firewall rule to block remote hosts/bots (i.e. 24hrs) according rules in varnish and drupal logs.
2. Memcache + C++ + Captcha to prevent scraping.
But I suggest to use these tools only when you experience related problems and the 2nd for dedicated varnish servers.