centos6.4安装varnish4.0

1. 安装好CentOS6.4系统后,安装更新

yum update

2. 下载varnish4.0安装包并解压

https://github.com/varnish/Varnish-Cache 放到/usr/local目录下

[[email protected] ~]# cd /usr/local/

[[email protected] local]# ls

bin  etc  games  include  lib  lib64  libexec  sbin  share  src  Varnish-Cache-master.zip  vmtools

[[email protected] local]# chmod 775 Varnish-Cache-master

[[email protected] local]# unzip Varnish-Cache-master

[[email protected] local]# ls

bin  etc  games  include  lib  lib64  libexec  sbin  share  src  Varnish-Cache-master  Varnish-Cache-master.zip  vmtools

3. 开始安装

[[email protected] local]# cd Varnish-Cache-master

[[email protected] Varnish-Cache-master]# ls

autogen.des  ChangeLog     CONTRIBUTING  flint.lnt  lib      Makefile.am       man     varnishapi.pc.in

autogen.sh   config.phk    doc           include    LICENSE  Makefile.inc.phk  README  varnishapi-uninstalled.pc.in

bin          configure.ac  etc           INSTALL    m4       Makefile.phk      redhat  varnish.m4

[[email protected] Varnish-Cache-master]# chmod -R 755 *

[[email protected] Varnish-Cache-master]# ls

autogen.des  ChangeLog     CONTRIBUTING  flint.lnt  lib      Makefile.am       man     varnishapi.pc.in

autogen.sh   config.phk    doc           include    LICENSE  Makefile.inc.phk  README  varnishapi-uninstalled.pc.in

bin          configure.ac  etc           INSTALL    m4       Makefile.phk      redhat  varnish.m4

[[email protected] Varnish-Cache-master]#

[[email protected] Varnish-Cache-master]# ./autogen.sh

./autogen.sh: line 29: automake: command not found

WARNING: unable to determine automake version

+ libtoolize --copy --force

./autogen.sh: line 44: libtoolize: command not found

[[email protected] Varnish-Cache-master]#

报错,那就是依赖包未安装完全,所需依赖包如下:

? autoconf

? automake

? jemalloc-devel

? libedit-devel

? libtool

? ncurses-devel

? pcre-devel

? pkgconfig

? python-docutils

? python-sphinx

参考地址:https://www.varnish-cache.org/docs/4.0/installation/install.html

然后全部用yum install即可

[[email protected] Varnish-Cache-master]# yum install autoconf automake jemalloc-devel libedit-devel libtool ncurses-devel pcre-devel pkgconfig python-docutils python-sphinx

中间可能会提示无可用包,但是没关系,可以尝试继续安装varnish

No package jemalloc-devel available.

[[email protected] Varnish-Cache-master]# ./autogen.sh

+ libtoolize --copy --force

libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `build-aux‘.

libtoolize: copying file `build-aux/ltmain.sh‘

libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4‘.

libtoolize: copying file `m4/libtool.m4‘

libtoolize: copying file `m4/ltoptions.m4‘

libtoolize: copying file `m4/ltsugar.m4‘

libtoolize: copying file `m4/ltversion.m4‘

libtoolize: copying file `m4/lt~obsolete.m4‘

+ aclocal -I m4

configure.ac:25: warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS

../../lib/autoconf/specific.m4:386: AC_USE_SYSTEM_EXTENSIONS is expanded from...

../../lib/autoconf/specific.m4:332: AC_GNU_SOURCE is expanded from...

configure.ac:25: the top level

configure.ac:25: warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS

+ autoheader

configure.ac:25: warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS

../../lib/autoconf/specific.m4:386: AC_USE_SYSTEM_EXTENSIONS is expanded from...

../../lib/autoconf/specific.m4:332: AC_GNU_SOURCE is expanded from...

configure.ac:25: the top level

configure.ac:25: warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS

+ automake --add-missing --copy --foreign

configure.ac:25: warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS

../../lib/autoconf/specific.m4:386: AC_USE_SYSTEM_EXTENSIONS is expanded from...

../../lib/autoconf/specific.m4:332: AC_GNU_SOURCE is expanded from...

configure.ac:25: the top level

configure.ac:25: warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS

configure.ac:15: installing `build-aux/config.guess‘

configure.ac:15: installing `build-aux/config.sub‘

configure.ac:19: installing `build-aux/install-sh‘

configure.ac:19: installing `build-aux/missing‘

bin/varnishadm/Makefile.am: installing `build-aux/depcomp‘

+ autoconf

configure.ac:25: warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS

../../lib/autoconf/specific.m4:386: AC_USE_SYSTEM_EXTENSIONS is expanded from...

../../lib/autoconf/specific.m4:332: AC_GNU_SOURCE is expanded from...

configure.ac:25: the top level

configure.ac:25: warning: AC_RUN_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS

[[email protected] Varnish-Cache-master]#

没报错

[[email protected] Varnish-Cache-master]# ls

aclocal.m4      bin          config.log    CONTRIBUTING  include  m4                Makefile.phk  varnishapi.pc.in

autogen.des     build-aux    config.phk    doc           INSTALL  Makefile.am       man           varnishapi-uninstalled.pc.in

autogen.sh      ChangeLog    configure     etc           lib      Makefile.in       README        varnish.m4

autom4te.cache  config.h.in  configure.ac  flint.lnt     LICENSE  Makefile.inc.phk  redhat

[[email protected] Varnish-Cache-master]#

再configure,没报错,期间如有报错,可以根据报错内容网上搜一下解决办法

[[email protected] Varnish-Cache-master]# ./configure --prefix=/usr/local/varnish PKG_CONFIG_PATH=/usr/lib/pkgconfig

接着就make

[[email protected] Varnish-Cache-master]#make

[[email protected] Varnish-Cache-master]#make install

此时/usr/local目录底下就有了varnish目录

[[email protected] local]# cd varnish/

[[email protected] varnish]# pwd

/usr/local/varnish

[[email protected] varnish]# ls

bin  include  lib  sbin  share  var

[[email protected] varnish]#

到此varnish就安装完成了,但是。。。还要配置

4. 配置varnish

由于varnish3.0与varnish4.0的配置文件有较大改动,且一些变量名,函数等都有改动,所以不采用3.0的配置文件

其实旧的配置文件模版在这里:

/usr/local/Varnish-Cache-master/etc/example.vcl

网上找到4.0的配置模版:

http://loftor.com/archives/varnish-4_0-vcl.html

但这个模版还需要修改,有3个地方要修改

在/usr/local/varnish目录下新建etc目录用来存放配置文件

在/usr/local/varnish/etc目录下创建varnish配置文件web.conf 其实这里配置文件的命名是可以随意的。只不过后面将配置文件与varnish服务关联起来的时候,文件名一定要对应

将模版的内容全部copy到web.conf文件内,然后作修改

修改1:

backend default {

.host = "127.0.0.1";

.port = "81";

.probe = {

.url = "/ping";

.timeout = 1s;

.interval = 10s;

.window = 5;

.threshold = 2;

}

.first_byte_timeout = 300s;   # How long to wait before we receive a first byte from our backend?

.connect_timeout  = 5s;     # How long to wait for a backend connection?

.between_bytes_timeout = 2s;     # How long to wait between bytes received from our backend?

}

backend web1 {

.host = "127.0.0.1";

.port = "81";

}

backend web2 {

.host = "127.0.0.1";

.port = "81";

}

前面的backend default{}、backend web1{}、backend web1{}是需要缓存的源站,命名可随意,也可增删,里面的参数也可根据实际需求修改,这里我修改如下:

backend ddostest1 {

.host = "192.168.6.102"; #源站IP

.port = "80";

.first_byte_timeout     = 300s;   # How long to wait before we receive a first byte from our backend?

.connect_timeout        = 5s;     # How long to wait for a backend connection?

.between_bytes_timeout  = 2s;     # How long to wait between bytes received from our backend?

}

修改2:

import directors;

sub vcl_init {

new cluster1 = directors.round_robin();

cluster1.add_backend(web1);    # Backend web1 defined above

cluster1.add_backend(web2);    # Backend web2 defined above

}

修改后:

import directors;

sub vcl_init {

new test = directors.round_robin();

test.add_backend(ddostest1);    # 这里是加速节点,与上面的ddostest1对应

}

当然这里也是可以new多个的,只要与源站对应即可

修改3:

在sub vcl_recv {}里

将set req.backend_hint = cluster1.backend();注释掉

将set req.http.Host = regsub(req.http.Host, ":[0-9]+", "");

修改为:

if (req.http.host ~ "(?i)^(www.)?ddostest.com$") {

set req.backend_hint = test.backend();

}

这里用到正则表达式,大致意思是从客户端请求的域名,只要是以ddostest.com结尾的域名,都使用test这个节点响应,然后保存。

5. 将varnish服务与配置文件web.conf关联起来,并开机自启动:

在/etc/init.d/目录下新建varnish文件,并给予755权限,内容如下:

# chkconfig: 2345 10 90

# description: varnish ....

#!/bin/sh

start()

{

echo -n $"starting varnish..."

/usr/local/varnish/sbin/varnishd -P /tmp/varnish.pid -a 0.0.0.0:80 -T 127.0.0.1:3500 -f /usr/local/varnish/etc/web.conf -n /var/varnish_cache -s malloc,1G -P client_http11=on

echo

}

stop()

{

echo -n $"stopping varnish..."

pkill varnish

echo

}

restart()

{

stop

sleep 2

start

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

restart

;;

*)

echo $"Usage: $0 {start|stop|restart}"

esac

之后还要创建缓存目录/var/varnish_cache

关闭防火墙,开机自启动varnish服务

[[email protected] var]# service iptables stop

iptables: Flushing firewall rules: [  OK  ]

iptables: Setting chains to policy ACCEPT: filter [  OK  ]

iptables: Unloading modules:                            [  OK  ]

[[email protected] var]# chkconfig

iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off

要将所有终端防火墙关闭

[[email protected] var]# chkconfig iptables --level 2345 off

将varnish加入chkconfig

[[email protected] var]# chkconfig --add varnish

[[email protected] var]# chkconfig

varnish         0:off   1:off   2:on    3:on    4:on    5:on    6:off

[[email protected] var]# chkconfig varnish --level 016 on

启动varnish服务

[[email protected] var]# service varnish start

starting varnish...

6. 测试

源站:192.168.6.102

加速节点:192.168.6.106

客户端:192.168.6.99

在客户端hosts文件里将www.ddostest.com域名与加速节点绑定

127.0.0.1       localhost

192.168.6.106   www.ddostest.com

直接访问源站:

ping站点域名www.ddostest.com

访问站点域名www.ddostest.com:

完毕!如有说错的内容,还请指教!

时间: 2024-11-10 13:36:13

centos6.4安装varnish4.0的相关文章

CentOS6.10安装redis5.0

1.以安装redis5.0.0为例 下载安装包:http://redis.io 安装非常简单! [[email protected] ~]#yum install gcc #需要先安装GCC,如果已安装请忽略 [root@centos6 ~]tar zxvf redis-5.0.0.tar.gz -C /usr/local #解压 [[email protected] ~]cd /usr/local/redis-5.0.0 #进入解压后的文件夹 [[email protected] redis5

CentOS6.5 安装 Mariadb10.0.20

最近在CentOS安装 Mariadb10.0.20,遇到一点小问题,所以把安装过程用博客记录: 1. 文件复制到/usr/lcoal目录下:$cp mariadb-10.0.20-linux-x86_64.tar.gz /usr/local 2.创建用户组及用户,以root操作: 2.1.#groupadd mariadb 2.2.#useradd -g mariadb mariadb 3.解压文件:# tar -zxvf mariadb-10.0.20-linux-x86_64.tar.gz

Centos6.5x64 安装scrapy1.0.4成功

最近在自学爬虫框架scrapy,看了看官网文档,迫不及待动手安装.结果错误百出,惨不忍睹.网上搜了一篇文章,(原文链接 http://www.tuicool.com/articles/URNVV3E). 首先,介绍下环境: 1.Centos6.5 x64 安装在VMware虚拟机中,因为后期需要移植,遂选择了兼容vm10.0. # yum -y update 升级下系统 2.Python2.7.9.系统自带为2.6.6. cd ~/Download 管网下载源码: wget --no-check

CentOS6.8安装mongodb3.0并添加到系统服务

一.系统环境CentOS 6.8_x64官方参考文档https://docs.mongodb.org/manual/reference/glossary/#term-init-script 二.添加官方yum库#cd /etc/yum.repo.d/#vim  mongodb.repo [mongodb-org-3.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-

CentOS6.5安装Tomcat7.0.29

一.描述 在CentOS6.5上使用源代码安装和配置Tomcat7.0.29. 二.安装步骤 1.检查是否已经安装jdk,默认CentOS6.x已经安装了jdk,使用如下命令查看系统是否已经安装jdk [[email protected] tongSoftware]$ rpm -qa|grep jdk java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el6_5.x86_64 java-1.6.0-openjdk-1.6.0.0-11.1.13.4.el6.x86_64 显

CentOS6.5安装MariaDB10.0.15编译安装和多实例管理配置

CentOS6.5 x86_64 系统 [[email protected] ~]# wget https://downloads.mariadb.org/interstitial/mariadb-10.0.15/source/mariadb-10.0.15.tar.gz/from/http%3A//mirrors.neusoft.edu.cn/mariadb groupadd -r mysql useradd -r -g mysql -s /sbin/nologin mysql mkdir /

centos6.5安装zabbix3.0

1:系统环境 操作系统:centos6.5最小化安装+开发包 web环境:lnmp(nginx1.10.mysql5.5.48.PHP5.4.40) 2:zabbix版本及下载 zabbix-3.0.5.tar.gz 下载地址:http://www.zabbix.com/download 3:安装依赖包 yum install net-snmp-devel OpenIPMI-developenssl-devel fping-devel libcurl-devel perl-DBI gcc 4:添

【redis】之centos6.x安装redis3.0.x

centos6.9_x86_64 1.下载redis安装包 http://download.redis.io/releases/redis-3.2.9.tar.gz 2.解压 tar -zxvf redis-3.2.9.tar.gz cd redis-3.2.9 make 如果你make时候出错,redis出现问题zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录 请执行 make MALLOC=libc 新建redis文件在 mkdir -p /

centos6.5安装redis4.0

一.下载redis https://redis.io/download 二.用fileZilla工具将redis的压缩包上传到centos6.5中 三.安装 1.解压 tar -zvxf redis-4.0-rc2.tar.gz 2.cd redis-4.0-rc2 3.make 4.启动redis服务  /usr/soft/redis-4.0-rc2/src/redis-server