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 ...
随机推荐
- Windows平台上通过git下载github的开源代码
常见指令整理: (1)检查ssh密钥是否已经存在.GitBash. 查看是否已经有了ssh密钥:cd ~/.ssh.示例中说明已经存在密钥 (2)生成公钥和私钥 $ ssh-keygen -t rsa ...
- MyBatis总结八:缓存介绍(一级缓存,二级缓存)
简介 为数据库的查询进行缓存,是减少数据库压力的主要途径.分为一级缓存和二级缓存. 一级缓存:session级别缓存,作用于当前会话. 二级缓存:SessionFactory级别缓存,作用于整个Ses ...
- var_dump — 打印变量的相关信息
<?php $a = array( 1 , 2 , array( "a" , "b" , "c" )); var_dump ( $a ...
- SQl Server 函数篇 聚合函数
说一下数据库中的聚合函数 函数使用必须加小括号(), 5种聚合函数: 1.max最大值 select max(price) from car where code='c024' --取这一列中 ...
- C++获取电脑上连接的多个摄像头名称与编号
#include<iostream>#include "strmif.h"#include <initguid.h>#include<vector&g ...
- ObjectARX杂碎--(学习指南及书籍)
---------------------------------------------------------------------------------------------------- ...
- .net 索引器
索引器允许类或结构的实例就像数组一样进行索引. 索引器类似于属性,不同之处在于它们的访问器采用参数. 在下面的示例中,定义了一个泛型类,并为其提供了简单的 get 和 set 访问器方法(作为分配和检 ...
- CHNS类
NS类集合介绍 1.常用部分 NSDictionary NSString NSArray 数组 NSTimer 定时器 NSRange 范围 NSNotification 2.网络相关 NSURLCo ...
- Oracle SQL判断字符串是否在目标字符串中的函数
转自:http://dacoolbaby.iteye.com/blog/1772156 根据需求,写了一段方法. 用于识别以下的情况: 判断 字符串A 在用逗号分隔的字符串B中是否存在 如: v_s ...
- 主要介绍JavaEE中Maven Web 项目的结构及其它几个小问题
先说下本篇随笔的目录. 1.介绍windows中环境变量Path与ClassPath的区别. 2.可能导致命令行运行javac编译成功,但 java命令 + 所要执行的类的类名 无效的原因. 3.介绍 ...