运维实战 CDN内容分发网络

本文介绍了通过Varnish实现CDN内容分发的过程,包括安装Varnish、编辑主配置文件以增加缓存设置和负载均衡。详细讲解了如何进行健康检查,根据域名将流量分发到不同后端主机,并设置了负载均衡策略。同时,还讨论了如何自定义缓存时长以及确保服务端能获取客户端原始IP。
摘要由CSDN通过智能技术生成

常见的业务流程

Client -> DNS -> CDN -> Proxy -> Webserver

安装Varnish

yum install -y varnish-4.0.5-1.el7.x86_64.rpm varnish-libs-4.0.5-1.el7.x86_64.rpm jemalloc-3.6.0-1.el7.x86_64.rpm jemalloc-devel-3.6.0-1.el7.x86_64.rpm

curl 172.25.5.1
vim default.vcl 
systemctl reload varnish.service 
curl 172.25.5.1
curl -I 172.25.5.1

编辑主配置文件

##添加默认后端服务器
##Server2上有安装好的Nginx
cd /etc/varnish/
vim default.vcl

backend default {
   
    .host = "172.25.5.2";
    .port = "80";
}

##修改程序环境中的监听端口为80方便测试
vim varnish.params

VARNISH_LISTEN_PORT=80

使用宿主机进行测试

[root@Server1 varnish]# curl 172.25.5.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
   
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值