linux中编译安装Varnish3.03及配置

这是关于Varnish3.03编译安装配置的笔记

安装

 代码如下 复制代码

yum -y install gcc gcc-c++ file bison patch unzip mlocate flex wget diffutils automake autoconf kernel-devel gd cpp readline-devel openssl openssl-devel vim-minimal nano libjpeg libjpeg       -devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel        e2fsprogs e2fsprogs-devel libidn libidn-devel openldap openldap-devel openldap-clients openldap-servers nss_ldap gettext gettext-devel expat-devel libcap libcap-devel libtool libtool-     ltdl-devel pam-devel pcre-devel ncurses-devel subversion bind-utils rsync libxslt groff pkgconfig

    # compile Varnish-Cache
    cd /usr/local/src
    wget -c http://repo.varnish-cache.org/source/varnish-3.0.3.tar.gz
    tar -zxf varnish-3.0.3.tar.gz
    cd varnish*
    ./autogen.sh
    ./configure --prefix=/usr/local/varnish
    make
    make install

    /usr/sbin/groupadd -g 1000 -o -r varnish
    /usr/sbin/useradd -M -g varnish -o -r -d /dev/zero -s /bin/false -c "Varnish-Cache Server" -u 1000 varnish
    mkdir -p {/etc/varnish,/var/log/varnish,/var/lib/varnish}
    /usr/bin/uuidgen > /etc/varnish/secret && chmod 0600 /etc/varnish/secret
    /usr/bin/install -m 755 ./redhat/varnish.initrc /etc/rc.d/init.d/varnish
    /usr/bin/install -m 755 ./redhat/varnishncsa.initrc /etc/rc.d/init.d/varnishncsa
    /usr/bin/install -m 644 ./redhat/varnish.sysconfig /etc/sysconfig/varnish
    /usr/bin/install -m 755 ./redhat/varnish_reload_vcl /usr/local/varnish/bin/

    ln -s /usr/local/varnish/bin/varnish_reload_vcl /usr/bin/
    ln -s /usr/local/varnish/bin/varnishncsa /usr/bin/
    ln -s /usr/local/varnish/sbin/varnishd /usr/sbin/
    ln -s /usr/local/varnish/bin/varnishadm /usr/bin/
    ln -s /usr/local/varnish/bin/varnishstat /usr/bin/
    ln -s /usr/local/varnish/bin/varnishhist /usr/bin/
    ln -s /usr/local/varnish/bin/varnishlog /usr/bin/
    ln -s /usr/local/varnish/bin/varnishtop /usr/bin/

    chkconfig --add varnish
    chkconfig varnish on
    chkconfig --add varnishncsa
    chkconfig varnishncsa on

配置

使用下面的代码来替换/etc/sysconfig/varnish中的内容,注意将下面代码中的121.199.13.169替换为你的vps的公网ip

 代码如下 复制代码

 

    # 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

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

    ## Alternative 1, Minimal configuration, no VCL
    #
    # 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
    #
    # 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
    #
    # See varnishd(1) for more information.
    #
    # # 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=121.199.13.169
    VARNISH_LISTEN_PORT=80
    #
    # # Telnet 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 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
    VARNISH_STORAGE_FILE=/dev/shm/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}"
    #
    # # Default TTL used when the backend does not specify one
    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.
    #
    # DAEMON_OPTS=""

使用下面的代码来替换/etc/varnish/default.vcl中的内容,如果/etc/varnish/default.vcl文件不存在,那就创建吧

 代码如下 复制代码

 

    # This is a basic VCL configuration file for varnish.  See the vcl(7)
    # man page for details on VCL syntax and semantics.
    #
    # Default backend definition.  Set this to point to your content
    # server.
    #
    backend default {
    .host = "127.0.0.1";
    .port = "80";
    }sub vcl_recv {
    remove req.http.X-real-ip;
    set req.http.X-real-ip = client.ip;
    set req.http.X-Forwarded-For = client.ip;

    if (req.http.Authorization) {
    return (pass);
    }

    if(req.url ~ ".(php)$" ){
    return (pass);
    }

    if (req.request != "GET" &&
    req.request != "HEAD" &&
    req.request != "PUT" &&
    req.request != "POST" &&
    req.request != "TRACE" &&
    req.request != "OPTIONS" &&
    req.request != "DELETE")
    { return (pipe); }

    if (req.request != "GET" && req.request != "HEAD") {
    return (pass);
    }

    if (req.request == "GET" && req.url ~ "(?i).(js|css|jpg|jpeg|png|gif|ico|rar|gz|bz2|mp3|swf|flv)$") {
    unset req.http.cookie;
    return (lookup);
    }
    }

    sub vcl_fetch {
    if (req.request == "GET" && req.url ~ "(?i).(js|css|jpg|jpeg|png|gif|ico|rar|gz|bz2|mp3|swf|flv)$") {
    set beresp.ttl = 7d;
    #unset beresp.http.set-cookie;
    }
    return (deliver);
    }

    sub vcl_deliver {
    #set resp.http.x-hits = obj.hits;
    remove resp.http.X-Varnish;
    remove resp.http.Via;
    remove resp.http.Age;
    remove resp.http.X-Pingback;
    set     resp.http.Server = "ZhengJie Web Server";
    set    resp.http.X-Via = "Varnish Cache Server V3.03";
    #if (obj.hits > 0) {
    #set resp.http.X-Cache = "Hit From CDN.IYISM.COM"; }
    #else {
    #set resp.http.X-Cache = "Miss From CDN.IYISM.COM"; }
    #set resp.http.Server = "IYISM";
    return (deliver);
    }

最后,将nginx配置文件中所有的listen 80改成listen 127.0.0.1:80,改完之后重启nginx,然后执行如下命令就ok了~

 代码如下 复制代码
    service varnish restart

说明:Varnish编译安装方法仿自诡谲(icodex.org),配置文件参照

时间: 2024-07-30 11:10:48

linux中编译安装Varnish3.03及配置的相关文章

linux中编译安装和配置nginx的教程

最近 @大高个 在折腾nginx,一时性起我就在深夜里写下了这篇博文,以记下了我曾经折腾nginx的那些不悔青春,这里以centos为例: 目录约定 首先约定下一些常用的目录,如: # 根目录挂载 /home/     # 安装包目录,存放一些常用的安装包     ./src/         ./nginx-1.11.1.tar         ./node-6.2.2.tar         ./zlib-1.2.8.tar.gz         ...     # 程序目录,存放一些编译后

Linux中编译安装MemcacheQ的步骤详解

队列(Queue)是一种常用的数据结构.在队列这种数据结构中,最先插入的元素将会最先被取出:反之最后插入的元素将会最后被取出,因此队列又称为"先进先出"(FIFO:First In First Out)的线性表. 加入元素的一端叫"队尾",取出元素的一端叫"队头".利用消息队列可以很好地异步处理数据的传送和存储,当遇到频繁且密集地向后端数据库中插入数据时,就可采用消息队列来异步处理这些数据写入. MemcacheQ是一款基于Memcache协议的

linux中编译安装openresty

nginx tengine openresty之间是什么关系? tengine相当于是nginx的二次开发,做了一些改动,增加了独有的一些功能 openresty是nginx的增强版,扩展了很多模块,特色是引入了lua支持模块,当然还有非常多个其他的模块,nginx核心使用的是原版nginx,并且使用的较新的mainline版本,比如1.9.3.2中包含的nginx版本为nginx-1.9.3 mainline 编译安装openresty wget https://openresty.org/d

linux下编译安装Redis以及主从配置步骤

Redis的安装配置很简单,而且很早之前就装过Redis,可这几天再次安装时居然又遗忘了一些细节,看来好记性不如烂笔头,还是在博客记录一下比较好,至少不用总是抱度娘大腿了. 今天编译安装了几次,发现居然没在prefix指定目录生成文件??看了半天结果发现PREFIX我用了小写字母... 看来还是得记录一次正确的操作步骤,免得再次出现这种窘迫. redis 一.选择版本 前往官方网站:http://www.redis.io/download 选择一个适合的稳定版本,比如最新的redis-3.0稳定

linux中编译安装PHP7并安装Redis扩展Swoole扩展

编译安装PHP7并安装Redis扩展Swoole扩展 在编译php7的机器上已经有编译安装过php5.3以上的版本,从而依赖库都有了 本php7是编译成fpm-php 使用的, 如果是apache那么编译参数应该为 --with-apxs2=/usr/local/apache/bin/apxs 编译安装php7 wget -c http://www.php.net/distributions/php-7.0.0.tar.gz tar zxvf php-7.0.0.tar.gz cd php-7.

linux中编译安装php的参数

php-5.2.14版本  代码如下 复制代码 ./configure –prefix=/usr/local/php-5.2.14 –with-config-file-path=/usr/local/php-5.2.14/etc –with-gd –with-iconv –with-zlib –enable-xml –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curlwrappers

linux平台编译安装PHP7并安装Redis扩展与Swoole扩展实例教程_php技巧

本文实例讲述了linux平台编译安装PHP7并安装Redis扩展与Swoole扩展的方法.分享给大家供大家参考,具体如下: 前面<PHP7安装Redis扩展教程[Linux与Windows平台]>一文告诉读者简单的安装Redis的方法,下面我们来实现在linux中编译安装PHP7并安装Redis扩展与Swoole扩展的方法. 编译安装PHP7并安装Redis扩展Swoole扩展: 在编译php7的机器上已经有编译安装过php5.3以上的版本,从而依赖库都有了 本php7是编译成fpm-php

Linux 有问必答:如何在Ubuntu或者Debian中编译安装ixgbe驱动

Linux 有问必答:如何在Ubuntu或者Debian中编译安装ixgbe驱动 提问: 我想为我的Intel 10G网卡下载安装最新的ixgbe驱动.我该如何在Ubuntu(或者Debian)中安装ixgbe驱动? Intel的10G网卡(比如,82598. 82599. x540)由ixgbe驱动支持.现代的Linux发行版已经带有了ixgbe驱动,通过可加载模块的方式使用.然而,有些情况你希望在你机器上的自己编译安装ixgbe驱动,比如,你想要体验ixbge驱动的最新特性时.同样,内核默认

linux qt4-RedHat企业版6.2中编译安装Qt4.8.5后,进入/tools/qvfb中gmake出现以下错误

问题描述 RedHat企业版6.2中编译安装Qt4.8.5后,进入/tools/qvfb中gmake出现以下错误 有懂的人给看看是怎么回事,急求高手解答.错误如下:.obj/release-shared/qanimationwriter.o: In function QAnimationWriter::QAnimationWriter(QString const&, char const*)': qanimationwriter.cpp:(.text+0x9ec): undefined refe