Varnish
1.定义
Varnish是一款高性能的开源http加速器。
2.安装
Yum install varnish-3.0.5-1.el6.x86_64.rpm varnish-libs-3.0.5-1.el6.x86_64.rpm
3.配置文件
(server1 172.25.30.1)
##配置varnish服务端口
Vim /etc/sysconfig/varnish
66 VARNISH_LISTEN_PORT=80
##配置后端服务
Cd /etc/varnish/
Vim default.vcl
backend web1 {
.host = "172.25.30.2";
.port = "80";
}
backend web2 {
.host = "172.25.30.3";
.port = "80";
}
director lb round-robin {
{.backend = web1;}
{.backend = web2;}
}
sub vcl_recv {
if (req.http.host ~ "^(www.)?westos.org") {
set req.http.host = "www.westos.org";
set req.backend = web1;
return (pass); #为了测试方便,不进行缓存。
} elsif (req.http.host ~ "^bbs.westos.org") {
set req.backend = lb;
} else {
error 404 "westos cache";
}
}
/etc/init.d/varnish reload
4.
(server2 172.25.30.2)
/etc/init.d/httpd start
Vim /etc/httpd/conf/httpd.conf
990: NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName server2
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/bbs
ServerName bbs.westos.org
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/westos
ServerName www.westos.org
</VirtualHost>
Cd /var/www/html
Vim index.html
<h1>server2-www.westos.org</h1>
Madir /www/bbs -p
Madir /www/westos
Vim /www/bbs/index.html
<h1>server2-bbs.westos.org</h1>
Vim /www/westos/index.html
<h1>server2-westos.org</h1>
/etc/init.d/httpd restart
(server3 172.25.30.3)
/etc/init.d/httpd start
vim /var/www/html/index.html
<h1>server3-www.westos.org</h1>
5.物理机作解析
172.25.30.1 server1.example.com www.westos.org westos.org bbs.westos.org
6.完成效果