/images/hugo/avatar.png

28.2 haproxy 配置

haproxy 配置

/images/linux_mt/linux_slb.jpg

本节开始我们来学习 haproxy 的配置。haproxy 有众多的配置选项,我打算将其分为两个部分,第一部分为haproxy 的全局配置,以及常用的代理段配置,第二部分为 haproxy 的访问控制。本节为的一部分,内容包括

28.1 haproxy 入门

haproxy 入门

/images/linux_mt/linux_slb.jpg

本章我们来介绍负载均衡集群的另一种实现 haproxy。与 nginx 类似,haproxy 工作于应用层属于七层代理,但是在其 tcp 模式下也能模拟实现四层代理。本章我们就来学习如何使用 haproxy。在学习配置 haproxy 之前我们先来对其做个简单了解,看看其程序与配置文件结构。

27.6 varnish 日志查看

varnish 日志查看

/images/linux_mt/linux_cache.jpg

varnish 的日志存放在特定的内存区域中,分为计数器和日志信息两个部分,查看日志需要专门的工具。本节我们来学习这部分命令的使用。

27.4 varnish缓存策略配置

varnish缓存策略配置

/images/linux_mt/linux_cache.jpg

前面我们讲解了 VCL 的语法,并通过示例讲解了一部分 varnish 缓存的配置。本节我们来看看 varnish 内置的缓存策略,然后着重来看看如何对缓存进行修剪。

27.3 VCL 语法基础

VCL 语法基础

/images/linux_mt/linux_cache.jpg

varnish 的缓存配置,使用的是 VCL,一种与 C 类似的域专有类型的配置语言。本节我们先来对 VCL 做一个介绍。

1. VCL 组成与处理流程

1.1 VCL 组成

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
vcl 4.0;

# Default backend definition. Set this to point to your content server.
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

sub vcl_recv {
    # Happens before we check if we have this in cache already.
    #
    # Typically you clean up the request here, removing cookies you don't need,
    # rewriting the request, etc.
}

sub vcl_backend_response {
    # Happens after we have read the response headers from the backend.
    #
    # Here you clean the response headers, removing silly Set-Cookie headers
    # and other mistakes your backend does.

VCL 可以看作是在 C 语言基础上二次开发的子语言,保留了 C 语言基本的语法,并额外附加了特性: