负载均衡varnish

  1. 下载安装varnish

[[email protected] ~]# rpm --nosignature -i https://repo.varnish-cache.org/redhat/varnish-4.0.el6.rpm

[[email protected] ~]# yum install varnish.x86_64

[[email protected] ~]# egrep -v  "^$|^#"  /etc/sysconfig/varnish
NFILES=131072
MEMLOCK=82000
NPROCS="unlimited"
RELOAD_VCL=1
VARNISH_VCL_CONF=/etc/varnish/default.vcl
VARNISH_LISTEN_PORT=88          -远程访问端口
VARNISH_ADMIN_LISTEN_ADDRESS=192.168.2.112
VARNISH_ADMIN_LISTEN_PORT=6082         --监控管理地址
VARNISH_SECRET_FILE=/etc/varnish/secret
VARNISH_MIN_THREADS=50
VARNISH_MAX_THREADS=1000
VARNISH_THREAD_TIMEOUT=120
VARNISH_STORAGE_SIZE=256M
VARNISH_STORAGE="malloc,${VARNISH_STORAGE_SIZE}"
VARNISH_TTL=120
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
             -f ${VARNISH_VCL_CONF} \
             -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
             -t ${VARNISH_TTL} \
             -p thread_pool_min=${VARNISH_MIN_THREADS} \
             -p thread_pool_max=${VARNISH_MAX_THREADS} \
             -p thread_pool_timeout=${VARNISH_THREAD_TIMEOUT} \
             -u varnish -g varnish \
             -S ${VARNISH_SECRET_FILE} \
             -s ${VARNISH_STORAGE}"

[[email protected] varnish]# netstat -antulp | grep varnish
tcp        0      0 0.0.0.0:88                  0.0.0.0:*                   LISTEN      5107/varnishd       
tcp        0      0 192.168.2.112:6082          0.0.0.0:*                   LISTEN      5105/varnishd       
tcp        0      0 :::88                       :::*                        LISTEN      5107/varnishd      
[[email protected] ~]# cd /etc/varnish/

2.简单的反向代理

[[email protected] varnish]# vim default.vcl

vcl 4.0;
backend node1 {
    .host = "192.168.2.112";
    .port = "8082";
}
sub vcl_recv {
}

sub vcl_backend_response {
}

sub vcl_deliver {
}

2.根据文件对服务器分发

[[email protected] varnish]# vim default.vcl
vcl 4.0;

backend node1 {
    .host = "192.168.2.112";
    .port = "8082";
}

backend node2 {
    .host = "192.168.2.114";
    .port = "8082";
}

sub vcl_recv {

if (req.url ~ "^/index.html") {
       set req.backend_hint = node1;
    }else {
       set req.backend_hint = node2;
    }
}
sub vcl_backend_response {
}

sub vcl_deliver {
}

3.权限主机分配服务器

[[email protected] varnish]# vim default.vcl

vcl 4.0;

backend node1 {

.host = "192.168.2.112";

.port = "8082";

}

backend node2 {

.host = "192.168.2.114";

.port = "8082";

}

backend node3 {

.host = "192.168.2.115";

.port = "8082";

}

sub vcl_recv {

if (req.http.host  ~ "www.tong.com" || req.http.host ~ "tong.com") {

set req.backend_hint = node1;

}elif (req.http.host  ~ "www.cheng.com" || req.http.host ~ "cheng.com") {

set req.backend_hint = node2;

}

else {

set req.backend_hint = node3;

}

}

sub vcl_backend_response {

}

sub vcl_deliver {

}

时间: 2024-08-29 12:36:26

负载均衡varnish的相关文章

Apache+varnish(高性能开源HTTP加速器)搭建负载均衡集群

实验环境:RHEL6.5 实验环境4台 真机进行访问测试     willis.example.com         172.25.254.6 虚拟机1(缓存端)   varnish.example.com       172.25.254.8 虚拟机2(服务器端1) web1.example.com     172.25.254.10 虚拟机3(服务器端2) web2.example.com     172.25.254.20 两台服务器主要用于负载均衡实验. 实验内容:1.服务器端安装Ap

varnish的缓存加速,以及动静分离,负载均衡

一个简单的拓扑如上,varnish1 上还同时开了nginx,用来做静态的http,app1和app2 是nginx+fastcgi,这个拓扑主要做的是Discuz!论坛的动静分离,以及app的负载均衡,varnish起到个反向代理和缓存加速的功能. varnish1:192.168.1.151,172.16.0.51 app1:172.16.0.52 app3:172.16.0.54 varnish 简介 varnish的缓存方式: 1.malloc,通过malloc获取内存,简单,速度. 2

nginx在varnish后端做负载均衡,后端tomca获取客户端真实IP

nginx在varnish后端做负载均衡,后端tomca获取客户端真实IP 1.设置nginx配置文件    首先要确定nginx做负载均衡,在安装时把http_realip_module 安装上了.    查看方法: /usr/local/nginx/sbin/nginx -V   配置nginx.conf    vim /usr/local/nginx/conf/nginx.conf   加入 set_real_ip_from 192.168.88.131;      重新加载nginx:

Varnish的负载均衡、动静分离

一.Varish的简介 Varnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸 Verdens Gang 使用3台Varnish代替了原来的12台Squid,性能比以前更好. 在当前主流的Web架构中,Cache担任着越来越重要的作用.常见的基于浏览器的C/S架构,Web Cache更是节约服务器资源的关键.而最近几年由FreeBSD创始人之一Kamp开发的varnish更是一个不可多得的Web Cache Server.严格意义上说,Varnish是一个高性能的反向代理软件,只不过

varnish(1)缓存、代理、负载均衡

varnish是web服务器的缓存(加速器).反向代理服务器.它的特点是轻量级,可以承载较多并发连接. 如挪威的一家电子新闻用三台varnish替换了10多台squid. varnish的进程大致分为两类: 1.master进程(读入配置文件.调用合适的存储类型.创建或读入相应大小的缓存文件.管理子进程.初始化管理该结构空间的结构体(通常指的是用来当做存储的内存片段)) 主要功能fork并监控各child进程. 2.child进程(线程)它的功能将各缓存文件映射到内存中,用mmap的方式(mma

HAProxy+Varnish+LNMP实现高可用负载均衡动静分离集群部署

HAProxy高可用负载均衡集群部署 基本信息: 系统平台:VMware WorkStation 系统版本: CentOS Linux release 7.2.1511 (Core) 内核版本: 3.10.0-327.el7.x86_64 集群架构: 前端:HAProxy 1.虚拟FQDN:www.simpletime.net 2.VIP:192.168.39.1:DIP:172.16.39.50 3.调度服务器:Varnish1.Varnish2 4.调度算法:URL_Hash_Consist

基于HAProxy+Varnish实现动静分离、负载均衡的高可用集群

拓扑结构介绍 在实际的生产使用过程中,一个基本的能够应对日均百万PV的网络,一般会具有以下几种结构. 这其中每种结构担负了不同的角色. 代理服务器,负责进行请求调度,实现了负载均衡. KeepAlived配置代理服务器实现了高可用. 缓存服务器,实现了资源的缓存,提高了请求的命中率,加快了访问速度. 动静分离,减轻后端服务器压力,提高资源访问速度. 数据库主从复制,读写分离,降低了数据库的压力 运维监控系统,实时监控系统运行状态. 自动化运维控制系统,批量管理大量服务器. 版本控制系统,在应用的

Varnish缓存负载均衡backend的实现

简介: varnish:是一款高性能并且开源的反向代理服务器和http加速器,据官方称可有300-1000倍的速度提升,它采用了全新的软件体系结构,和现在的硬件体系紧密结合,和传统的squid相比,varnish具有性能更高.速度更快.管理更加方便等诸多优点,很多大型的网站都开始尝试使用varnish来替代squid,这些促进了varnish的快速发展. varnish在架构中扮演的结构角色拓扑图: Varnish的负载均衡实验步骤: 环境准备: 在虚拟机上准备3台centos7,一台做varn

varnish 的安装,配置及负载均衡

系统环境:rhel6.5 server8.9安装http服务server7 172.25.35.7server8 172.25.35.8server9 172.25.35.9[[email protected] ~]# cd varnish/[[email protected] varnish]# lsbansys.zip varnish-libs-3.0.4-1.el6.x86_64.rpmrhel6 varnish.pdf varnish-libs-3.0.5-1.el6.x86_64.rp