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 ...
随机推荐
- css知多少(5)——选择器(转)
css知多少(5)——选择器 1. 引言 从本节开始,就进入本系列的第二个部分——css和html的结合——说白了就是选择器. CSS中定义了样式,如何将这些样式设置到相应的html节点上?就不得 ...
- 数字图像处理实验(3):PROJECT 02-03, Zooming and Shrinking Images by Pixel Replication 标签: 图像处理matlab 20
实验要求: Zooming and Shrinking Images by Pixel Replication Objective To manipulate a technique of zoomi ...
- python3-字典中包含字典
# Auther: Aaron Fan #定义字典及内容av_catalog = { "欧美":{ "www.youporn.com": ["很多免费 ...
- java反射中,Class.forName和classloader的区别
http://blog.csdn.net/qq_27093465/article/details/52262340
- TinkerPop中的遍历:图的遍历步骤(3/3)
48 Project Step project() 步骤(map)将当前对象投射到由提供的标签键入的Map<String,Object>中. gremlin> g.V().out(' ...
- [学习笔记]父进程wait和waitpid
1.wait和waitpid出现的原因 SIGCHLD q 当子进程退出的时候,内核会向父进程发送SIGCHLD信号,子进程的退出是个异步事件(子进程可以在父进程运行的任何时刻终止) q 子进程退 ...
- symbol访问法及symbor注册表
symbol主要作用是防止对象属性名冲突 在ES6之前,对象的属性名只能是字符串,这样很容易造成字符串的冲突. 例:假设person对象是从外部库引入的一个对象 let person = { name ...
- 对MySQL性能影响较大的五类配置参数
以下主要是对MySQL 性能影响关系紧密的五大配置参数的介绍. 一. 连接 连接通常来自Web 服务器,下面列出了一些与连接有关的参数,以及该如何设置它们. (一). ...
- pandas-如何得到某一个值所在的行
df[df['列名'].isin([相应的值])]
- git 增量打包
git diff f506693 ccc253c3 --name-only | xargs tar -czvf update.tar.gz