Linux平台部署varnish 高性能缓存服务器(1)
2016-01-04 16:02
369 查看
【本文档所介绍的内容适用于公司测试/生产常见的varnish环境部署】
一:varnish部署前准备:1.1相关软件以及系统,web服务系统要求:Centos 6(以上) (64位)相关中间件:varnish-4.0.21.2相关系统依赖包安装检查准备1.2.1 检查系统自带nginx是否安装
2.1 下载varnish安装包
如有所示为varnish的官网:https://www.varnish-cache.org/releases,选择对应的varnish版本,本文档用的版本是varnish4.0.2
一:varnish部署前准备:1.1相关软件以及系统,web服务系统要求:Centos 6(以上) (64位)相关中间件:varnish-4.0.21.2相关系统依赖包安装检查准备1.2.1 检查系统自带nginx是否安装
rpm -qa | grep varnish如有安装,请使用以下命令卸载相关程序
yum remove varnish -y1.2.2 安装编译nginx需要的依赖包
yum install libtool ncurses-devel pcre-devel ibedit-devel pkgconfig python-docutils python-sphinx automake autoconf -y1.2.3 安装好相关web服务
安装Apache,nginx,tomcat等都行,本文档的web安装在本地,使用的nginx web 端口为:8080[b][b]二:varnish 部署安装[/b][/b]
2.1 下载varnish安装包
如有所示为varnish的官网:https://www.varnish-cache.org/releases,选择对应的varnish版本,本文档用的版本是varnish4.0.2
cd /usr/local/src wget https://repo.varnish-cache.org/source/varnish-4.0.2.tar.gz[/code]2.2 编译安装varnishcd /usr/local/src tar zxvf varnish-4.0.2.tar.gz ./configure CPPFLAGS="-I$PATH_TO_LIBEDIT/include" LDFLAGS="-L$PATH_TO_LIBEDIT/lib" \ --prefix=/usr/local/varnish4.0.2 make && make install2.3 配置varnish的启动脚本
echo "/usr/local/varnish4.0.2/sbin/varnishd -P /var/run/varnish.pid -f /usr/local/varnish4.0.2/etc/default.vcl -s malloc,1G -T 127.0.0.1:2000 -a 0.0.0.0:80" > /usr/local/varnish4.0.2/sbin/varnishd.sh
2.4 将varnish以开机服务的形式启动,并加入系统服务
2.4.1 编辑/etc/init.d/varnishdvim /etc/init.d/varnishd2.4.2 在/etc/init.d/varnishd添加以下内容#!/bin/sh #chkconfig:345 85 15 #description: varnish cache server # varnish # Copyright (C) 2001-2014 varnish cache # SERVICE="varnish server" DAEMON=/usr/local/varnish4.0.2/sbin/varnishd.sh PIDFILE=/var/run/varnish.pid case $1 in 'start') if [ -x ${DAEMON} ] then $DAEMON # Error checking here would be good... echo "${SERVICE} started success ! " else echo "Can't find file ${DAEMON}." echo "${SERVICE} NOT started." fi ;; 'stop') if [ -s ${PIDFILE} ] then if kill `cat ${PIDFILE}` >/dev/null 2>&1 then echo "${SERVICE} shutdown success !" rm -f ${PIDFILE} fi fi ;; 'restart') $0 stop sleep 10 $0 start ;; *) echo "Usage: $0 start|stop|restart" ;; esac2.4.3 编辑/usr/local/varnish4.0.2/etc/default.vcl添加以下内容vcl 4.0; backend webserver { .host = "127.0.0.1"; .port = "8080"; //等同于后端web server .connect_timeout = 4s; .first_byte_timeout = 5s; .between_bytes_timeout = 20s; }2.4.4启动varnishd 服务service varnishd start[b][b]三:varnish验证测试[/b][/b]
启动web服务service nginx start使用系统自带的命令curl -I localhost 如下所示:HTTP/1.1 200 OK Server: nginx/1.8.0 Date: Mon, 04 Jan 2016 07:50:09 GMT Content-Type: text/html Last-Modified: Mon, 31 Aug 2015 03:55:55 GMT ETag: "55e3d04b-264" X-Varnish: 112 131182 Age: 80 Via: 1.1 varnish-v4 Content-Length: 612 Connection: keep-alive本文如上红色部分,当X-varnish 后面出现两组数据的时候,说明缓存成功,这时我们在关掉web服务,数据会从varnish缓存里读取,如下
关闭web服务service nginx stop重新curl -I localhost 如果命中缓存,则如下所示:HTTP/1.1 200 OK Server: nginx/1.8.0 Date: Mon, 04 Jan 2016 07:53:47 GMT Content-Type: text/html Last-Modified: Mon, 31 Aug 2015 03:55:55 GMT ETag: "55e3d04b-264" X-Varnish: 110 131182 Age: 8 Via: 1.1 varnish-v4 Content-Length: 612 Connection: keep-alive当没有从缓存里命中时,会出现以下提示(没有命中缓存,则X-varnish后面数字为单组数字):HTTP/1.1 503 Backend fetch failed Date: Mon, 04 Jan 2016 07:55:59 GMT Server: Varnish Content-Type: text/html; charset=utf-8 Retry-After: 5 X-Varnish: 98457 Age: 0 Via: 1.1 varnish-v4 Content-Length: 282 Connection: keep-alive至此整个varnish的部署安装基本就OK了
本文出自 “菜鸟的成长记” 博客,请务必保留此出处http://blief.blog.51cto.com/6170059/1731390
相关文章推荐
- Linux使用ODBC方式还是DBI方式安装R语言扩展包好
- linux启动_grub
- 每天一个Linux之chown命令
- Centos系统下Lamp环境的快速搭建(超详细)
- Linux内核驱动 GPIO子系统 GPIO的使用
- linux mysql大小写敏感问题
- linux下iptables命令
- LINUX 部署 WEB.PY 验证码服务的 配置说明书
- PHP 7.0 For Linux的安装使用与性能监测
- linux 批量删除目录下的文件夹,包含子文件
- windows 向linux服务器上传文件命令
- How to Record your Voice from the Microphone on Ubuntu/Linux Mint
- linux中vi/vim显示行号设置
- centos彻底删除文件夹、文件命令
- centos6.5 安装Python-mysqldb
- linux操作系统基础
- centos用户权限修改
- 安装linux系统
- linux下bin的相关知识
- Linux I/O重定向以及正则表达式