varnish服务器的搭建与应用
作者:互联网
varnish 代理软件 反向代理 【web加速服务器】,缓存在内存
varnish 【web加速服务器】,缓存在内存
varnish可以用内存或者硬盘来做缓存
安装Varnish
[root@stu ~]# tar -xf varnish-3.0.6.tar.gz
[root@stu varnish-3.0.6]# cd varnish-3.0.6
[root@stu varnish-3.0.6]# yum -y install readline-devel pcre-devel gcc gcc-c++
[root@stu varnish-3.0.6]# useradd -s /sbin/nologin varnish
[root@stu varnish-3.0.6]# ./configure --prefix=/usr/local/varnish
[root@stu varnish-3.0.6]# make&&make install
[root@stu varnish-3.0.6]# cp redhat/varnish.initrc /etc/init.d/varnish
[root@stu varnish-3.0.6]# cp redhat/varnish.sysconfig /etc/sysconfig/varnish
[root@stu varnish-3.0.6]# cp redhat/varnish_reload_vcl /usr/bin/
[root@stu varnish-3.0.6]# ln -s /usr/local/varnish/sbin/varnishd /usr/sbin/
varnish配置文件
/etc/sysconfig/varnish 定义前段【软件】
VARNISH_VCL_CONF=/etc/varnish/default.vcl //定义后端配置文件位置及名称
VARNISH_LISTEN_PORT=80 //监听端口
VARNISH_SECRET_FILE=/etc/varnish/secret //密钥文件
VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin //硬盘存储时的位置
VARNISH_STORAGE_SIZE=64M //缓存大小
#VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
和下面的配置只能用一个
VARNISH_STORAGE="malloc,${VARNISH_STORAGE_SIZE}"
//使用内存缓冲,缓冲大小为64M
VARNISH_TTL=120 //超时时间为120
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
-f ${VARNISH_VCL_CONF} \
-T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
-t ${VARNISH_TTL} \
-w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \
-u varnish -g varnish \
-S ${VARNISH_SECRET_FILE} \
-s ${VARNISH_STORAGE}"
/etc/sysconfig/default.vcl 【定义后端】
[root@stu varnish-3.0.6]# mkdir /etc/varnish
[root@stu varnish-3.0.6]# cp /usr/local/varnish/etc/varnish/default.vcl /etc/varnish/
[root@stu varnish-3.0.6]# uuidgen > /etc/varnish/secret
[root@stu varnish-3.0.6]# vim /etc/varnish/default.vcl
backend default {
.host = "192.168.2.100";
.port = "80";
}
[root@stu varnish-3.0.6]# service varnish start
[root@client ~]# curl http://192.168.4.5
123
[root@stu varnish-3.0.6]# ln -s /usr/local/varnish/bin/* /usr/bin/
缓存管理
清除缓存内容的命令格式:
varnishadm -T IP:Port -S securefile
ban.url <regexp>
-- varnishadm -s /etc/varnish/secret ban.url/
查看缓存清理列表:
--varnishadm ban.list
[root@proxy ~]# varnishadm -S /etc/varnish/secret
varnish> storage.list
200
Storage devices:
storage.Transient = malloc
storage.s0 = malloc
varnish> ban.list
200
Present bans:
varnish> backend.list
200
Backend name Refs Admin Probe
default(192.168.2.100,,80) 1 probe Healthy (no probe)
Varnish日志
varnishlog [-w file] //共享内存的日志
varnishncsa [-w file] //类Apache日志
标签:varnish,etc,VARNISH,stu,3.0,服务器,root,搭建 来源: https://www.cnblogs.com/liangyd/p/15115110.html