linux 中varnish服务
在server1中安装两个包
varnish-3.0.5-1.el6.x86_64.rpm
varnish-libs-3.0.5-1.el6.x86_64.rpm
1.在server1中(varnish)配置varnish服务
vim /etc/sysconfig/varnish
VARNISH_LISTEN_PORT=80 ##varnish监听端口
backend default {
.host = "172.25.8.2";
.port = "80";
}
然后开启服务
/etc/init.d/varnish start
yum install httpd
vim /var/www/html/index.html
<h1>www.westos.org-sever2</h1>
会出现server2index.html内容
二、缓存命中
vim default.vcl
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT from westos cache";
}
else {
set resp.http.X-Cache = "MISS from westos cache";
}
return (deliver);
}
www.westos.org-sever2
vim /etc/hosts
172.25.8.1 server1 www.westos.org www.linux.org westos.org ##加入本地解析

varnishadm ban.url .*$ 清除所有
varnishadm ban.url /index.html 清除 index.html 页面缓存
varnishadm ban.url /admin/$ 清除 admin 目录缓存
再开启一台虚拟机(server3)
yum install httpd
vim /var/www/html/index.html
<h1>www.linux.org</h1>
vim default.vcl
.host = "172.25.8.2";
.port = "80";
}
.host = "172.25.8.3";
.port = "80";
}
if (req.http.host ~ "^(www.)?westos.org") {
set req.http.host = "www.westos.org";
set req.backend = lb;
} elsif (req.http.host ~ "^www.linux.org") {
set req.backend = web2;
} else {error 404 "westos cache";
}
}
/etc/init.d/varnish reload 重载
curl www.westos.org
www.westos.org-sever2
curl westos.org
www.westos.org-sever2
curl www.linux.org
www.linux.org
vim /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName www.linux.org
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www1
ServerName www.westos.org
</VirtualHost>
mkdir /www1
vim /www1/index.html
<h1>www.westos.org-server3</h1>
[root@server3 ~]# curl www.linux.org
<h1>www.linux.org</h1>
<h1>www.westos.org-server3</h1>
vim default.vcl
backend web1 {
.host = "172.25.8.2";
.port = "80";
}
.host = "172.25.8.3";
.port = "80";
}
{ .backend = web1; }
{ .backend = web2; }
}
if (req.http.host ~ "^(www.)?westos.org") {
set req.http.host = "www.westos.org";
set req.backend = lb;
#return (pass) 加入此行可以更加直观看到实验效果,正常情况下不加
} elsif (req.http.host ~ "^www.linux.org") {
set req.backend = web2;
} else {error 404 "westos cache";
}
}
/etc/init.d/varnish reload
<h1>www.westos.org-server3</h1>
[root@foundation8 ~]# curl westos.org/index.html
<h1>www.westos.org-server3</h1>
当server3的httpd闭
[root@foundation8 ~]# curl westos.org/index.html
<h1>www.westos.org-sever2</h1>
[root@foundation8 ~]# curl westos.org/index.html
<h1>www.westos.org-sever2</h1>

当server2和server3的http都开启
<h1>www.westos.org-server3</h1>
[root@foundation8 ~]# curl westos.org
<h1>www.westos.org-sever2</h1>
[root@foundation8 ~]# curl westos.org
<h1>www.westos.org-server3</h1>
vim /etc/httpd/conf/http.conf
将监听端口改为8080,防止和varnish主机80端口冲突
/etc/init.d/httpd restart
yum install unzip
unzip bansys.zip -d /var/www/html
cd /var/www/html/bansys
mv * ..
cd ..
vim config.php
/etc/init.d/httpd start
<?php
//可定义多个主机列表
$var_group1 = array(
'host' => array('172.25.8.1'),
'port' => '80',
);
//对主机列表进行绑定
$VAR_CLUSTER = array(
'www.westos.org' => $var_group1,
);
"127.0.0.1";
"172.25.8.0"/24;
}
sub vcl_recv {
if (!client.ip ~ westos){
error 405 "Not allowed.";
}
ban ("req.url ~ " + req.url);
error 200 "ban added";
}

linux 中varnish服务的更多相关文章
- Linux中Sshd服务配置文件优化版本(/etc/ssh/sshd_config)
Linux中Sshd服务配置文件优化版本(/etc/ssh/sshd_config) # $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Ex ...
- Spring Boot 如何部署到 Linux 中的服务
打包完成后的 Spring Boot 程序如何部署到 Linux 上的服务? 你可以参考官方的有关部署 Spring Boot 为 Linux 服务的文档. 文档链接如下: https://docs. ...
- 转:Linux中tomcat服务成功发布但局域网浏览器无法访问
转自:http://blog.csdn.net/mooncom/article/details/53168143 昨天,我在搭建Linux中服务器环境时,碰见一个问题,这里和大家分享一下. 问题描述: ...
- Linux中设置服务自启动的三种方式
有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务 主要用三种方式进行这一操作: ln -s 在/etc/rc.d/rc*.d目录中建立/e ...
- [转]Linux中设置服务自启动的三种方式
from:http://www.cnblogs.com/nerxious/archive/2013/01/18/2866548.html 有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统 ...
- Linux中crond服务与crontab用法
需要写个在Linux下定时更新系统的脚本,man crondtab 不甚详细,现将网络上的介绍列举如下: crontab是一个很方便的在unix/linux系统上定时(循环)执行某个任务的程序使用cr ...
- Linux中设置服务自启动的三种方式,ln -s 建立启动软连接
有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务(http://www.0830120.com) 主要用三种方式进行这一操作: ln -s 在/etc/rc.d/rc*.d目录中建立 ...
- (转)Linux中设置服务自启动的三种方式
有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务 主要用三种方式进行这一操作: ln -s 在/etc/rc.d/rc*.d目录中建立/e ...
- 【转发】Linux中设置服务自启动的三种方式
有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务 主要用三种方式进行这一操作: ln -s 在/etc/rc.d/rc*.d目录中建立/e ...
随机推荐
- springmvc 初始化参数绑定(使用属性编辑器) 来处理类型转换问题
处理一种日期格式 处理器中的写法: index.jsp中的写法: 处理多种日期格式: 处理器的写法: 自定义的属性编辑器: index.jsp的写法:
- android viewpage解决嵌套
子viewpage 自定义 写法一: public class ChildViewPager extends ViewPager{ /** 触摸时按下的点 **/ PointF downP = new ...
- Border Layout
------------------siwuxie095 根面板 contentPane 的默认布局就是 Border Layout B ...
- C++——override
override关键字作用: 如果派生类在虚函数声明时使用了override描述符,那么该函数必须重载其基类中的同名函数,否则代码将无法通过编译.举例子说明 struct Base { virtual ...
- ruby 访问权限
##################### # 访问权限 ##################### class HeidSoft ##默认方法 def method1 ##### end prote ...
- QT中显示图像数据
博客转载自:https://blog.csdn.net/lg1259156776/article/details/52325091 一般图像数据都是以RGBRGBRGB……字节流的方式(解码完成后的原 ...
- IP地址在mysql的存储
因为int比varchar(15)更高效,且php和mysql都有ip和int互转的函数,所以在ip地址在mysql中用int存储最优. mysql存储这个值是字段需要用int UNSIGNED.不用 ...
- 39、count_rpkm_fpkm_TPM
参考:https://f1000research.com/articles/4-1521/v1 https://www.biostars.org/p/171766/ http://www.rna-se ...
- $this->autoRender = false
动作执行完之后禁止调用render()方法
- Entity Framework Tutorial Basics(13):Database First
Database First development with Entity Framework: We have seen this approach in Create Entity Data M ...