Varnish部署(一)

实验环境(Centos7)

主机名            IP                版本
varnish        192.168.14.210    4.0.5
web1(nginx)    192.168.14.211    nginx/1.12.2
client         192.168.14.212

一、varnish

官网地址:http://varnish-cache.org/trac/wiki/VCLExamples

1、关闭防火墙和selinux

[root@varnish ~]# systemctl stop firewalld
[root@varnish ~]# systemctl disable  firewalld
[root@varnish ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

2、配置阿里epel源

[root@varnish ~]# vim /etc/yum.repos.d/epel.repo
[epel]
name=aliyun epel
baseurl=http://mirrors.aliyun.com/epel/7Server/x86_64/
gpgcheck=0

3、安装varnish

[root@varnish ~]# yum install -y varnish

修改前备份配置文件(可选)

[root@varnish ~]# cp /etc/varnish/varnish.params{,.bak}
[root@varnish ~]# cp /etc/varnish/default.vcl{,.bak}

4、更改默认端口

更改前:
[root@varnish ~]# cat /etc/varnish/varnish.params|grep VARNISH_LISTEN_PORT
VARNISH_LISTEN_PORT=6081
[root@varnish ~]# vim /etc/varnish/varnish.params

更改后:
[root@varnish ~]# cat /etc/varnish/varnish.params|grep VARNISH_LISTEN_PORT
VARNISH_LISTEN_PORT=80

5、修改配置文件(简单配置只需修改两个地方)

backend default {
    .host = "192.168.14.211";
    .port = "80";
}

sub vcl_deliver {
    if (obj.hits>0) {
    set resp.http.X-Cache = "Hit via "+ server.ip;
    }else {
    set resp.http.X-Cache = "Miss via "+ server.ip;
    }
}

6、启动varnish服务并开机启动

[root@varnish ~]# systemctl start   varnish
[root@varnish ~]# systemctl enable  varnish

二、web

1、同上,关闭防火墙和selinux

2、同上,配置阿里epel源

3、安装nginx

[root@web1 ~]# yum install -y nginx

4、修改自定义主页

[root@web1 ~]# echo "nginx webserver1" > /usr/share/nginx/html/index.html 
[root@web1 ~]# cat /usr/share/nginx/html/index.html 
nginx webserver1

5、启动服务

[root@web1 ~]# systemctl start   nginx
[root@web1 ~]# systemctl enable  nginx

三、客户端访问

1、centos访问

2、window访问

刷新浏览器,返回304状态码,并且是缓存服务器返回的数据

3、至此,varnish缓存服务器搭建成功

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

友人a笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值