Install and configure Varnish 4 and Munin plugin for WordPress on cPanel/WHM CentOS 6 servers

So you have a VPS with cPanel/WHM (11.48) and want to run Varnish 4 reverse proxy to accelerate the server for your WordPress installations while monitoring Varnish 4 with Munin.

1. Install Varnish 4 – just follow these instructions https://www.varnish-cache.org/installation/redhat

2. Configure Varnish listening port to 80 by editing /etc/sysconfig/varnish file. In same file decide where to store the cache (on disk – default option, or on memory).

3. Configure vcl files by following these instructions: http://www.jaritimonen.com/make-wordpress-faster-with-varnish-cache/ Please note that you should use the backend server public IP and a chosen port such as 8080 in the <pre>backend default {}</pre> section. In default.vcl file just delete the websites filter (his wife’s websites) or modify them as necessary.

4. Tweak settings for Apache in WHM and set non-SSL port to 8080 (or another port you chosen at step 3)

5. Restart Apache and start varnish with

service varnish start

. If the varnish service does not start you need to debug your vcl files, most probably you introduced a typo. At this time you should be able to access all websites via varnish proxy. You can check it by accessing the WordPress websites and inspecting elements headers, you should be able to see Age and X-Varnish headers. Please do not login into backend of WordPress, the logged in users are not receiving cached files and Age header will always be 0.

6. Download varnish4_ plugin for Munin from here: https://github.com/munin-monitoring/contrib/tree/master/plugins/varnish4

7. Edit the plugin file and change first line with:

#!/usr/local/cpanel/3rdparty/perl/514/bin/perl

8. Upload the file to munin plugins folder at /usr/local/cpanel/3rdparty/share/munin/plugins and make it executable (change permissions to 755)

9. Create symlinks for all necessary aspects with these commands:

ln -s /usr/local/cpanel/3rdparty/share/munin/plugins/varnish4_ /etc/munin/plugins/varnish4_request_rate
ln -s /usr/local/cpanel/3rdparty/share/munin/plugins/varnish4_ /etc/munin/plugins/varnish4_hit_rate
ln -s /usr/local/cpanel/3rdparty/share/munin/plugins/varnish4_ /etc/munin/plugins/varnish4_backend_traffic
ln -s /usr/local/cpanel/3rdparty/share/munin/plugins/varnish4_ /etc/munin/plugins/varnish4_objects
ln -s /usr/local/cpanel/3rdparty/share/munin/plugins/varnish4_ /etc/munin/plugins/varnish4_transfer_rates
ln -s /usr/local/cpanel/3rdparty/share/munin/plugins/varnish4_ /etc/munin/plugins/varnish4_threads
ln -s /usr/local/cpanel/3rdparty/share/munin/plugins/varnish4_ /etc/munin/plugins/varnish4_memory_usage
ln -s /usr/local/cpanel/3rdparty/share/munin/plugins/varnish4_ /etc/munin/plugins/varnish4_uptime
ln -s /usr/local/cpanel/3rdparty/share/munin/plugins/varnish4_ /etc/munin/plugins/varnish4_session
ln -s /usr/local/cpanel/3rdparty/share/munin/plugins/varnish4_ /etc/munin/plugins/varnish4_expunge
ln -s /usr/local/cpanel/3rdparty/share/munin/plugins/varnish4_ /etc/munin/plugins/varnish4_ban

10. Edit /etc/munin/plugin-conf.d/cpanel.conf file and add this section:

[varnish4_*]
user root
group wheel
env.varnishstat varnishstat

11. restart munin by

service munin-node restart

12. After few minutes varnish graphs will appear in WHM under Munin plugin.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *