client->cdn(squid->HA+F5/LVS(4)->HA+nginx/haproxy(7)->web(apache/nginx)
->app(php/jsp)->DB(mysql&redis)
zabbix openstack kvm/docker/k8s|swarm hadoop
nginx可以反向代理
HA高可用
nginx(异步非阻塞)
apache(同步非阻塞)
LVS(linux virtual server)
搭建过程
一 设置母盘
最小化安装rhel6.5
1关闭selinux
2搭建yum源
真机搭建http源
mkdir -p /var/www/html/rhel6.5
mount /root/rhel-server-6.5-x86_64-dvd.iso /var/www/html/rhel6.5/
yum install openssh lftp -y
3关闭ip6 iptables
/etc/init.d/iptables stop
/etc/init.d/ip6tables stop
chkconfig iptables off
chkconfig ip6tables off
4删掉绑定的网卡MAC地址
rm -fr /etc/udev/rules.d/70-persistent-net.rules
创建快照
qemu-img create -f qcow2 -b /var/lib/libvirt/images/rhel6.5母盘.qcow2 /var/lib/libvirt/images/server1.qcow2
server2
server3
修改主机名
vi /etc/sysconfig/network
server1
server2
server3
server1虚拟机作为使用varnish服务器
下载varnish包
mget varnish-*
库文件也要安装
在安装包目录下
yum install varnish-* -y
查看配置文件
rpm -qc varnish-.0
首先查看一下启动的要求,不需要修改这个文件
vim /etc/sysconfig/varnish
NFILES 最大打开文件个数
MEMLOCK=82000 默认是运行varnish需要82M内存
VARNISH_LISTEN_PORT=80 端口改为80端口
sysctl -a |grep file
查看自己系统最大打开文件数
free -m 查看内存大小
改系统参数
vi /etc/security/limits.conf
末尾增加
varnish – nofile 131072
varnish – memlock 82000
varnish – nproc unlimited
vi /etc/varnish/default.vcl
backend default {
.host = "172.25.11.2";
.port = "80";
}
然后启动 /etc/init.d/varnish start
效果是 curl访问server1时候自动加载server2
现在写入判断
backend default {
.host = "172.25.11.2";
.port = "80";
}
sub vcl_deliver{
if(obj.hits>0){
set resp.http.X-Cache = "HIT from HZP cache";
}
else{
set resp.http.X-Cache="MISS from HZP cache";
}
return (deliver);
}
}
清全部缓存 varnishadm ban.url .*$
清某个页面 varnishadm ban.url /index.html
其中sub vcl_deliver函数的意思是
如果缓存中有,就返回HIT 不然就返回MISS 然后再去服务器中缓存
再次编辑
backend web1 {
.host = "172.25.11.2";
.port = "80";
}
backend web2 {
.host = "172.25.11.3";
.port = "80";
}
sub vcl_recv {
if (req.http.host ~ "^(www.)?westos.org") {
set req.http.host = "www.westos.org";
set req.backend = web1;
} elsif (req.http.host ~ "^bbs.westos.org") {
set req.backend = web2;
} else {
error 404 "hzp cache else";
}
}
sub vcl_deliver{
if(obj.hits>0){
set resp.http.X-Cache = "HIT from HZP cache";
}
else{
set resp.http.X-Cache="MISS from HZP cache";
}
return (deliver);
}
###其中sub vcl_recv函数意思 :
如果 输入www.westos.com 就返回web1的地址的http内容
bbs则返回web2的内容
/etc/init.d/varnish reload
curl 172.25.11.1 -I
负载均衡
backend web1 {
.host = "172.25.11.2";
.port = "80";
}
backend web2 {
.host = "172.25.11.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 = lb;
return (pass); #为了测试加入的,实际上删掉
} elsif (req.http.host ~ "^bbs.westos.org") {
set req.backend = web2;
} else{
error 404 "westos cache";}
}
sub vcl_deliver{
if(obj.hits>0){
set resp.http.X-Cache = "HIT from HZP cache";
}
else{
set resp.http.X-Cache="MISS from HZP cache";
}
return (deliver);
}
server1中 varnishadm ban.url .*$
真机访问bbs.westos.com 几次就会均衡
原文链接:https://blog.csdn.net/m493096871/article/details/86624222?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165934461816780366579231%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165934461816780366579231&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-12-86624222-null-null.nonecase&utm_term=%E6%90%AD%E5%BB%BAcdn
原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/6434