Varnish proxy server
What Varnish that?
Varnish is a high performance open-source HTTP accelerator, which is mainly used as a reverse proxy cache server in use, varnish design architecture is the use of caching mechanisms to deal with access to the operating system
varnish and squid difference:
Varnish and Squid is a reverse proxy server, can be used as high-performance proxy caching server, and is open source software
is high 1.Varnish stability, squid probability of failure compared to varnish large
2.Varnish faster access, all the data can be read directly from the cache memory, while the Squid cache data read from the hard disk
3.Varnish support more concurrent connections, because of fast Varnish TCP connection release than Squid
4.Varnish regular expressions can clear some cache batch through the management port, use, and Squid can not
Once the process 5.Varnish hang, crash or restart, the cached data will be fully released from memory, then all requests are sent to the back-end server, under high concurrency, this will cause great pressure on the back-end server
6.Varnish Squid configuration compared to simple, rich monitoring interface, good performance, but Squid data, rich functionality, support of access control ACL
Installation configuration varnish reverse proxy server
Client: The machine 192.168.0.100
Proxy server: 192.168.0.105
Web Server: 192.168.0.101
1. Install the relevant support package
yum -y install gcc readline-devel ncurses-devel pcre-devel python-docutils libtoollibxslt groff pkgconfig libedit-devel
2. compile and install varnish
tar zxf varnish-4.0.5.tar.gz
cd varnish-4.0.5
./configure --prefix=/usr/local/varnish --enable-debugging-symbols
make && make install
3. Path Optimization
ln -s /usr/local/varnish/sbin/varnishd /usr/sbin/
ln -s /usr/local/varnish/bin/* /usr/bin/
4. Copy the configuration file templates and uses the modified configuration file
cp /usr/local/varnish/share/doc/varnish/example.vcl /usr/local/varnish/default.vcl
vim /usr/local/varnish/default.vcl
To modify the IP address and port agents
5. Start the service access proxy server test
varnishd -f /usr/local/varnish/default.vcl
varnish load balancing cluster
Client: The machine 192.168.0.100
Proxy server: 192.168.0.105
Web server 1: 192.168.0.101
Web Server 2: 192.168.0.102
1. Modify the configuration file
vim /usr/local/varnish/default.vcl
Version 4.0 was written after the director of the varnish module
import directors; \\加载directors模块
#添加后端真实服务器
backend web1 {
.host = "192.168.0.101";
.port = "80";
}
backend web2 {
.host = "192.168.0.102";
.port = "80";
}
#初始化模块,定义director
sub vcl_init {
new bar = directors.round_robin(); \\定义调度算法, random dns
bar.add_backend(web1);
bar.add_backend(web2);
}
#设置缓存配置
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.
set req.backend_hint = bar.backend(); \\把流量转发给directors
return(pass); \\设置不进行缓存
}
Start Service Access Proxy ip
Click to refresh the page to jump to another server page
Added: Adding configuration health check
Modify the configuration file: vim /usr/local/varnish/default.vcl
backend web1 {
.host = "192.168.0.101";
.port = "80";
.probe = { //开启健康检查
.url = "/"; //请求的URL路径
.interval = 5s; //查询间隔时间
.timeout = 1s; //超时时间
.window = 5; //varnish保持的结果滑动窗口,该滑动窗口是一种流量控制方法,允许发送方在停止并等待确认前可以连续发送多个分组。由于发送方不必每发送一个分组就停下来等待确认,所有此协议可以加速数据传输
.threshold = 3; //上次检查.window数量的多少,才代表后端是健康的
}
}
Restart service test