缓存服务器Varnish实践篇

一、实验环境

服务器   IP地址   系统版本  
varnish服务器   172.16.8.1   CentOS6.5  
web1服务器   172.16.8.5:81   Centos6.5  
web2服务器   172.16.8.5:82   Centos6.5  
img1服务器   172.16.8.5:83   Centos6.5  
img2服务器   172.16.8.5:84   Centos6.5  
php1服务器   172.16.8.5:85   Centos6.5  
php2服务器   172.16.8.5:86   Centos6.5  

缓存服务器Varnish概念篇 

=========================分割线=========================

相关阅读

Varnish Cache 的架构笔记

CentOS 5.8下Varnish-2.1.5的安装配置

RedHat脚本改用CentOS源更新安装Nginx、PHP 5.3、Varnish

利用Varnish构建Cache服务器笔记

缓存服务Varnish安装配置

Varnish 编译安装所需准备

Linux下Varnish缓存的配置优化

=========================分割线=========================

二、安装varnish

1、下载地址:

varnish-libs-3.0.4-1.el6.x86_64.rpm


varnish-3.0.4-1.el6.x86_64.rpm


varnish-docs-3.0.4-1.el6.x86_64.rpm

2、安装varnish

[root@localhost ~]# rpm -ivh varnish-docs-3.0.4-1.el6.x86_64.rpm varnish-3.0.4-1.el6.x86_64.rpm varnish-libs-3.0.4-1.el6.x86_64.rpm

3、配置文件详解

# cat /etc/sysconfig/varnish

/////////////

# Configuration file for varnish

#

# /etc/init.d/varnish expects the variable $DAEMON_OPTS to be set from this

# shell script fragment.

#

# Maximum number of open files (for ulimit -n)

NFILES=131072 //打开最大文件数

# Locked shared memory (for ulimit -l)

# Default log size is 82MB + header

MEMLOCK=82000 //默认日志大小

# Maximum number of threads (for ulimit -u)

NPROCS="unlimited" //最大线程数

# Maximum size of corefile (for ulimit -c). Default in Fedora is 0

# DAEMON_COREFILE_LIMIT="unlimited" //最大内核打开的文件数

# Set this to 1 to make init script reload try to switch vcl without restart.

# To make this work, you need to set the following variables

# explicit: VARNISH_VCL_CONF, VARNISH_ADMIN_LISTEN_ADDRESS,

# VARNISH_ADMIN_LISTEN_PORT, VARNISH_SECRET_FILE, or in short,

# use Alternative 3, Advanced configuration, below

RELOAD_VCL=1 //是否自动加载VCL

# This file contains 4 alternatives, please use only one.

## Alternative 1, Minimal configuration, no VCL //方案1,最小配置,不方便

#

# Listen on port 6081, administration on localhost:6082, and forward to

# content server on localhost:8080. Use a fixed-size cache file.

#

#DAEMON_OPTS="-a :6081 \

#      -T localhost:6082 \

#      -b localhost:8080 \

#      -u varnish -g varnish \

#      -s file,/var/lib/varnish/varnish_storage.bin,1G"

## Alternative 2, Configuration with VCL //方案2,配置组件

#

# Listen on port 6081, administration on localhost:6082, and forward to

# one content server selected by the vcl file, based on the request. Use a

# fixed-size cache file.

#

#DAEMON_OPTS="-a :6081 \

#      -T localhost:6082 \

#      -f /etc/varnish/default.vcl \

#      -u varnish -g varnish \

#      -S /etc/varnish/secret \

#      -s file,/var/lib/varnish/varnish_storage.bin,1G"

## Alternative 3, Advanced configuration //方案3,高级配置

#

# See varnishd(1) for more information.

#

# # Main configuration file. You probably want to change it :)

VARNISH_VCL_CONF=/etc/varnish/default.vcl //默认的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=

VARNISH_LISTEN_PORT=6081 //服务监听端口

#

# # Telnet admin interface listen address and port

VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1 //管理IP

VARNISH_ADMIN_LISTEN_PORT=6082 //管理端口

#

# # Shared secret file for admin interface

VARNISH_SECRET_FILE=/etc/varnish/secret //默认的加密文件

#

# # The minimum number of worker threads to start

VARNISH_MIN_THREADS=50 //最小线程数

#

# # The Maximum number of worker threads to start

VARNISH_MAX_THREADS=1000 //最大线程数

#

# # Idle timeout for worker threads

VARNISH_THREAD_TIMEOUT=120 //线程超时时间

#

# # Cache file location

VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin //缓存文件的位置

#

# # Cache file size: in bytes, optionally using k / M / G / T suffix,

# # or in percentage of available disk space using the % suffix.

VARNISH_STORAGE_SIZE=1G //设置存储的大小

#

# # Backend storage specification //后端存储规范,这里是我们主要配置的地方

VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}" //默认存储在文件里,我们这里修改为malloc

#

# # Default TTL used when the backend does not specify one //默认TTL时使用的后端不指定一个

VARNISH_TTL=120

#

# # DAEMON_OPTS is used by the init script. If you add or remove options, make

# # sure you update this section, too. //所有的启动选项

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}"

#

## Alternative 4, Do It Yourself. See varnishd(1) for more information. //方案4,设置你自己的配置。看到varnishd(1)更多的信息。

#

# DAEMON_OPTS=""

4、修改启动脚本

# vim /etc/sysconfig/varnish

VARNISH_LISTEN_PORT=8080 #这里设置的监听端口设置为8080

VARNISH_STORAGE="malloc,64M" 设置的缓存内存为64M

5、启动varnish

# service varnish start

6、查看端口

缓存服务器varnish实践篇

7、连接管理端口

[root@localhost ~]# varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/58246c0fc4fbc3f6a3f98e30cb5cdb5c.html