Varnish 实现Web站点加速
Varnish 是一款高性能的开源HTTP加速器。
编译安装Varnish
1.安装依赖包
#yum install -y libtool ncurses-devel pcre-devel libxslt libedit python-imaging python-docutils
yum install -y pcre-devel python-docutils libedit-dev*
2.编译安装Varnish
wget http://varnish-cache.org/_downloads/varnish-6.0.0.tgz
tar -xzvf varnish-6.0.0.tgz
cd varnish-6.0.0/
./configure --prefix=/usr/local/varnish6
make && make install
ln -s /usr/local/varnish6/sbin/* /usr/sbin/
ln -s /usr/local/varnish6/bin/* /usr/local/bin/
cp -a /usr/local/varnish6/share/doc/varnish/example.vcl /usr/local/varnish6/default.vcl
Varnish实现负载均衡并实现页面缓存
1.编辑Varnish主配置文件,在相应的区域追加写入以下标★语句
vim /usr/local/varnish/default.vcl
15 # Default backend definition. Set this to point to your content server.
16 backend default {
17 .host = "127.0.0.1";
18 .port = "8080";
19 }
20
★ backend web1 { #均衡web主机1
★ .host="192.168.1.13";
★ .port="80"; #指定端口
★ .probe = { #开启健康检查
★ .url = "/"; #请求的URL路径
★ .interval = 5s; #查询间隔时间
★ .timeout = 1s; #超时时间
★ .window = 5; #滑动窗
★ .threshold = 3; #上次检查.window数量的多少
★ }
★ }
★ backend web2 {
★ .host="192.168.1.14"; #均衡web主机2
★ .port="80"; #指定端口
★ .probe = { #开启健康检查
★ .url = "/"; #请求的URL路径
★ .interval = 5s; #查询间隔时间
★ .timeout = 1s; #超时时间
★ .window = 5; #滑动窗
★ .threshold = 3; #上次检查.window数量的多少,
★ }
★ }
★
★ import directors; #加载directors模块
★
★ sub vcl_init { #缓存及加速-03单-高性能缓存服务器
★
★ new bar = directors.round_robin();
★ bar.add_backend(web1);
★ bar.add_backend(web2);
★
★ }
★
★ sub vcl_recv {
★
★ set req.backend_hint = bar.backend(); #指定backend
★
★ }
2.检查配置文件,并启动Varnish
varnishd -C -f /usr/local/varnish6/default.vcl #检查语法
varnishd -f /usr/local/varnish6/default.vcl #启动
pkill varnishd #关闭Varnish
varnishlog #查看Varnish日志
netstat -anpt | grep varnishd #检查是否启动
3.验证环节
elinks http://127.0.0.1/ #varnish服务器会根据算法分配流量
文章出处:https://www.cnblogs.com/LyShark/p/10229675.html
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
分类:
《Linux 系统运维技术实践》
标签:
Linux 系统运维技术实践
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?