Varnish在Centos 7下用yum安装很简单

 

yum install epel-release -y

执行后,会添加源在

more /etc/yum.repos.d/epel.repo

打开上面文件看内容

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
enabled=1
failovermethod=priority
baseurl=http://mirrors.cloud.aliyuncs.com/epel/7/$basearch
gpgcheck=0
gpgkey=http://mirrors.cloud.aliyuncs.com/epel/RPM-GPG-KEY-EPEL-7

我是阿里云的机器,所以源是阿里云的。

[root@zhangjiakou ~]# yum search varnish
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * remi-safe: mirrors.tuna.tsinghua.edu.cn
========================================================================= N/S matched: varnish =========================================================================
collectd-varnish.x86_64 : Varnish plugin for collectd
php-pecl-varnish.x86_64 : Varnish Cache bindings
php54-php-pecl-varnish.x86_64 : Varnish Cache bindings
php55-php-pecl-varnish.x86_64 : Varnish Cache bindings
php56-php-pecl-varnish.x86_64 : Varnish Cache bindings
php70-php-pecl-varnish.x86_64 : Varnish Cache bindings
php71-php-pecl-varnish.x86_64 : Varnish Cache bindings
php72-php-pecl-varnish.x86_64 : Varnish Cache bindings
php73-php-pecl-varnish.x86_64 : Varnish Cache bindings
php74-php-pecl-varnish.x86_64 : Varnish Cache bindings
varnish-docs.x86_64 : Documentation files for varnish
varnish-libs.x86_64 : Libraries for varnish
varnish-libs-devel.x86_64 : Development files for varnish-libs
varnish.x86_64 : High-performance HTTP accelerator

php也直接有支持varnish的官方的函数了。
安装varnish的yum命令

yum install varnish -y

varnish的配置文件

vim /etc/varnish/default.vcl

具体的配置信息,看我另外一篇文章Varnish和WordPress的配置

vim /etc/varnish/varnish.params

varnish.params是varnish的端口和存储配置,默认是缓存到内存的

# 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=80
# 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
# Backend storage specification, see Storage Types in the varnishd(5)
# man page for details.
VARNISH_STORAGE="malloc,2560M"
# User and group for the varnishd worker processes
VARNISH_USER=varnish
VARNISH_GROUP=varnish
# Other options, see the man page varnishd(1)
#DAEMON_OPTS="-p thread_pool_min=5 -p thread_pool_max=500 -p thread_pool_timeout=300"