{"id":3696,"date":"2016-10-01T14:34:34","date_gmt":"2016-10-01T18:34:34","guid":{"rendered":"https:\/\/underhost.com\/blog\/?p=3696"},"modified":"2016-10-01T14:34:34","modified_gmt":"2016-10-01T18:34:34","slug":"install-varnish-centos-7","status":"publish","type":"post","link":"https:\/\/underhost.com\/blog\/install-varnish-centos-7\/","title":{"rendered":"How to Install Varnish on CentOS 7"},"content":{"rendered":"<h3>1. Introduction<\/h3>\n<p>Varnish is a proxy and cache, or HTTP accelerator, designed to improve performance for busy, dynamic web sites. By redirecting traffic to static pages, varnish reduces the number of dynamic page calls, thus reducing load. Varnish is designed for content-heavy dynamic web sites as well as heavily consumed APIs. In contrast to other web accelerators, such as Squid, or Apache and nginx, which are primarily origin servers, Varnish was designed as an HTTP accelerator.<\/p>\n<p>&nbsp;<\/p>\n<h3>2. Varnish Cache Performance Parameters<\/h3>\n<p>Once installed, Varnish Cache allows us to use several apps to evaluate the server by means of statistics. These apps are the ones mentioned below.<\/p>\n<ul>\n<li>varnishtop: grouped list with the most usual entries from different logs.<\/li>\n<li>varnishhist: a histogram that shows the time taken for the requests processing.<\/li>\n<li>varnishsizes: it performs the same task as \u201cvarnishhist\u201d but showing the size of the objects.<\/li>\n<li>varnishstat: it shows many contents on cache hits, resource consumption, etc..<\/li>\n<li>varnishlog: it allows us to see all the requests made to the web backend server.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3>3. Requirements<\/h3>\n<p>You may need an operating system RHEL 7 or Centos 7 in your dedicated or vps server. Please make sure to set a hostname for your server and its dns is pointing to the IP address of the server.<\/p>\n<p>&nbsp;<\/p>\n<h3>4. Installation Steps<\/h3>\n<p>Before you begin please install LAMP (Linux Apache Mysql PHP) in your server. To install LAMP, Please refer the documentation from <a href=\"http:\/\/www.tecmint.com\/install-lamp-in-centos-7\/\">here<\/a><\/p>\n<p>Update your server with latest packages.<\/p>\n<blockquote>\n<pre># yum update\r\n\r\n<\/pre>\n<\/blockquote>\n<p>Now install varnish on Centos.<\/p>\n<blockquote><p># yum install varnish<\/p><\/blockquote>\n<h3>\n<p>5.\u00a0How to setup Varnish 4 for Apache<\/h3>\n<blockquote>\n<pre># vi \/etc\/varnish\/varnish.params\r\n<\/pre>\n<\/blockquote>\n<p>Change Listen Port to 80 as we are going to run Varnish in front of Apache:<\/p>\n<blockquote>\n<pre>VARNISH_LISTEN_PORT=80\r\n<\/pre>\n<\/blockquote>\n<p>Now edit Apache configuration file:<\/p>\n<blockquote>\n<pre># vi \/etc\/httpd\/conf\/httpd.conf\r\n<\/pre>\n<\/blockquote>\n<p>Then look for the line that says \u201cListen 80\u201d and change it to \u201cListen 8080\u201d<\/p>\n<p>Now restart Apache at first so the webserver run on port 8080 leaving port 80 being usable by Varnish:<\/p>\n<blockquote>\n<pre># systemctl restart httpd.service\r\n<\/pre>\n<pre># systemctl restart varnish.service\r\n<\/pre>\n<pre># systemctl enable varnish.service\r\n<\/pre>\n<\/blockquote>\n<p>You can see varnish running on port 80 using the following command:<\/p>\n<blockquote><p># netstat -tunlp | grep :80 tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 22368\/httpd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 22145\/varnishd<\/p><\/blockquote>\n<h3>\n6. Testing varnish<\/h3>\n<blockquote>\n<pre># varnishd -V\r\n<\/pre>\n<\/blockquote>\n<p>Gives you an output something like this:<\/p>\n<blockquote>\n<pre>varnishd (varnish-3.0.7 revision f544cd8)\r\nCopyright (c) 2006 Verdens Gang AS\r\nCopyright (c) 2006-2014 Varnish Software AS\r\n<\/pre>\n<\/blockquote>\n<p>You can check it like this<\/p>\n<blockquote>\n<pre># curl -I \r\n# curl -I 192.168.3.18\r\nHTTP\/1.1 403 Forbidden\r\nDate: Sun, 17 Jan 2016 10:42:54 GMT\r\nServer: Apache\/2.4.6 (CentOS) PHP\/7\r\nLast-Modified: Thu, 1 Oct 2016 15:20:58 GMT\r\nETag: \"1321-5058a1e728280\"\r\nAccept-Ranges: bytes\r\nContent-Length: 4897\r\nContent-Type: text\/html; charset=UTF-8\r\nX-Varnish: 13\r\nAge: 0\r\nVia: 1.1 varnish-v4\r\nConnection: keep-alive<\/pre>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<h4>Get varnish and your site setup within few minutes on one of our <a href=\"https:\/\/underhost.com\/usa-ca-vps.php\">virtual private servers<\/a> or have experts get you online on our <a href=\"https:\/\/underhost.com\/vps-cloud-hosting.php\">managed cloud hosting<\/a>.<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction Varnish is a proxy and cache, or HTTP accelerator, designed to improve performance for busy, dynamic web sites. By redirecting traffic to static pages, varnish reduces the number of dynamic page calls, thus reducing load. Varnish is designed for content-heavy dynamic web sites as well as heavily consumed APIs. In contrast to other [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3665,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,11],"tags":[],"class_list":["post-3696","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-how-to"],"_links":{"self":[{"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts\/3696","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/comments?post=3696"}],"version-history":[{"count":2,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts\/3696\/revisions"}],"predecessor-version":[{"id":3698,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/posts\/3696\/revisions\/3698"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/media\/3665"}],"wp:attachment":[{"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/media?parent=3696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/categories?post=3696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/underhost.com\/blog\/wp-json\/wp\/v2\/tags?post=3696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}