[root@localhost ~]# yum install varnish
After above installation, there are 2 config files to setup. "/etc/varnish/default.vcl" and "/etc/varnish/varnish.params".
If you are installing Varnish with Apache Web Server on the same hardware(localhost). Insert below config to "/etc/varnish/default.vcl".
[root@localhost ~]# vi /etc/varnish/default.vcl
backend default {
.host = "127.0.0.1";
.port = "80";
}
By default, Varnish is installed to listen to port 6081. The admin port is installed on port 6082.
[root@localhost ~]# vi /etc/varnish/varnish.params
Here is my varnish.params:
# Varnish environment configuration description. This was derived from # the old style sysconfig/defaults settings # Set this to 1 to make systemd reload try to switch vcl without restart. RELOAD_VCL=1 # Main configuration file. You probably want to change it. VARNISH_VCL_CONF=/etc/varnish/default.vcl # Default address and port to bind to. Blank address means all IPv4 # and IPv6 interfaces, otherwise specify a host name, an IPv4 dotted # quad, or an IPv6 address in brackets. # VARNISH_LISTEN_ADDRESS=192.168.1.5 VARNISH_LISTEN_PORT=6081 # Admin interface listen address and port #VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1 VARNISH_ADMIN_LISTEN_PORT=6082 # Shared secret file for admin interface VARNISH_SECRET_FILE=/etc/varnish/secret # The minimum and maximum number of worker threads to start VARNISH_MIN_THREADS=5 VARNISH_MAX_THREADS=1000 # Idle timeout for worker threads VARNISH_THREAD_TIMEOUT=120 # Backend storage specification, see Storage Types in the varnishd(5) # man page for details. VARNISH_STORAGE="file,/var/lib/varnish/varnish_storage.bin,1G" # Default TTL used when the backend does not specify one VARNISH_TTL=120 # User and group for the varnishd worker processes VARNISH_USER=varnish VARNISH_GROUP=varnishAfter you have edited the config files, set the machine to start Varnish on reboot. And start the cache service.
[root@localhost ~]# systemctl enable varnish.service [root@localhost ~]# systemctl start varnish.service
To access the cache, you can type the IP address of the server on the web browser. Assume the Varnish and Apache Web server is at 192.168.0.5.
http://192.168.0.5:6081
To bypass varnish cache, you can still reach web server (Apache) at:
http://192.168.0.5
Thanks for this useful post!
ReplyDeleteFor those who are getting this error in Fedora 18
"gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory"
You can install the following package:
yum install redhat-rpm-config
Kind regards, Valentin
Not able to start the varnish, getting this following error, Thanks in advance
ReplyDeletevarnish.service - Varnish a high-perfomance HTTP accelerator
Loaded: loaded (/usr/lib/systemd/system/varnish.service; enabled)
Active: failed (Result: exit-code) since Thu 2013-12-05 11:42:03 IST; 3min 11s ago
Process: 3573 ExecStart=/usr/sbin/varnishd -P /var/run/varnish.pid -f $VARNISH_VCL_CONF -a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} -t $VARNISH_TTL -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} -u $VARNISH_USER -g $VARNISH_GROUP -S $VARNISH_SECRET_FILE -s $VARNISH_STORAGE $DAEMON_OPTS (code=exited, status=2)
Dec 05 11:42:03 ttsys010 varnishd[3573]: Message from C-compiler:
Dec 05 11:42:03 ttsys010 varnishd[3573]: gcc: error: /usr/lib/rpm/redhat/red...y
Dec 05 11:42:03 ttsys010 varnishd[3573]: Running C-compiler failed, exit 1
Dec 05 11:42:03 ttsys010 varnishd[3573]: VCL compilation failed
Dec 05 11:42:03 ttsys010 systemd[1]: varnish.service: control process exite...=2
Dec 05 11:42:03 ttsys010 systemd[1]: Failed to start Varnish a high-perfoma...r.
Dec 05 11:42:03 ttsys010 systemd[1]: Unit varnish.service entered failed state.
got the fix, yum install. redhat-rpm-config.
DeleteSince varnish-3.0.3-5, varnish requires /usr/lib/rpm/redhat/redhat-hardened-cc1 which belongs to redhat-rpm-config. This leads to varnish not being able to start unless you manually install redhat-rpm-config (providing the missing file)
Yes, verified. You need to install "redhat-rpm-config", to be able to start the service.
Delete