01 . Squid原理配置和使用

Squid简介

Squid是一个支持HTTP,HTTPS,FTP等服务的Web缓存代理软件,它可以通过缓存页面来提高服务器的相应速度并降低带宽占用。并且,Squid还具有强大的访问控制功能。Squid可以运行在各种操作系统平台上。

Squid会将访问页面的结果缓存在硬盘和内存上。所以Squid对硬盘和内存的空间大小具有较高的要求。内存和硬盘越大,缓存的命中率就越高。但是真实服务器数据是实时更新的,因此,我们就需要不定期的清空缓存数据以保证用户访问结果的准确性。

Squid 将数据元缓存在内存和硬盘中,同时也缓存 DNS 查询的结果。Squid 支持 SSL,支持访问控制。由于使用了 ICP(轻量 Internet 缓存协议),Squid 能够实现层叠的代理阵列,从而最大限度的节约带宽。

Squid Cache(简称 Squid)是一个流行的代理服务器和 Web 缓存服务器软件。Squid 可以做正向代理,也可以做反向代理。官方网站地址为:http://www.squid-cache.org/

Web代理功能
# 1. 将区域网中的主机保护起来
# 2. 对网站的内容缓存,加快客户端的访问速度,减少网络流量
# 3. 静态页面的站点越来越少,可缓存的内容也变少,因为数据库中的信息是不能被缓存.

常用代理服务器类型

代理服务器有多种类型,一般意义上常分为标准正向代理服务器,透明代理服务器,反向代理服务器.

正向代理服务器主要应用于内部网络希望访问外部网络时缓存页面数据, 由于公网IP地址稀缺,企业内部成百上千台计算机不可能同时大欧连接到Internet上,目前的解决方案就是通过一个统一的网络接口连接Internet。Squid就可以提供这样的接口。所有的客户端通过设置代理服务器连接值Squid,通过代理上网。此模型下,Squid主要负责提供缓存加速服务和访问控制的功能。正向代理是对用户的一种操作。

透明代理与传统的正向代理相似,区别在于传统的正向代理需要每个客户端都进行代理服务器的设置。而透明代理通过网关进行部署。即,所有的设置都是由管理员在网关服务器以及代理服务器进行的。因此,透明代理对于用户是透明的,不需要用户进行任何设置。

反向代理结合智能DNS可以实现基本的CDN框架。通过DNS的分离解析功能,可以为不同地区的DNS请求解析不同的结果返回给客户端。用户访问时,感觉不到是在访问代理服务器。由于使用到了缓存技术,当大的并发量到达时,Squid也可以更快的给用户返回响应结果。反向代理结构如下图所示。

Squid代理服务器原理

Squid原理:客户端访问Squid代理服务器,由代理服务器代表客户访问后端真实服务器,真实服务器将响应的数据返回给Squid代理服务器。最后,Squid代理服务器将响应结果返回给客户端,同时将结果缓存在硬盘上及内存中,当客户端再次访问相同的网页时,代理服务器直接将响应结果返回给客户端。

正向代理

当 Squid 做正向代理时,Squid 后面是客户端,客户端想访问外部网络资源,必须经过 Squid。正向代理按其客户端配置方式不同,又可以分为标准(普通)代理模式和透明代理模式。

标准(普通)代理模式,是代理内部网络用户访问 internet 上服务器的连接请求,客户端必须指定代理服务器,并将本来要直接发送到 internet 上服务器的连接请求发送给代理服务器处理。用户在上网时必须在浏览器等软件中填写代理服务器的 IP 地址与端口号信息,否则默认不使用代理。

透明代理模式,是相对于代理服务器而言,客户端不需要做任何和代理服务器相关的设置和操作,对用户而言,感觉不到代理服务器的存在,所以称之为透明代理。即把代理服务器部署在核心的上网出口,当用户上网浏览页面时,会交给代理服务器向外请求,如果结合iptables,可以实现代理+网关+内容过滤+流量安全控制等完整的上网解决方案。

部署Squid服务
yum -y install squid
systemctl restart squid
配置squid

可以使用squid默认的配置文件,因为默认的配置文件其实就已经设置了正向代理,也可以修改默认的配置文件,如下:

[root@squid ~]# cat /etc/squid/squid.conf
# 默认对外端口为3128
http_port 3128

cache_effective_user squid
cache_effective_group squid

# 内网控制,按需修改
acl manager proto cache_object
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network

# 配置可访问的端口
acl SSL_ports port 443
acl Safe_ports port 80 8080     # http
acl Safe_ports port 21  # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70  # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT


# 允许本机访问
http_access allow manager localhost
http_access deny manager

http_access deny !Safe_ports

# 拒绝443以外的端口访问
http_access deny CONNECT !SSL_ports

# 允许内网
http_access allow localnet
http_access allow localhost

http_access allow all

# 设置缓存文件位置、cache目录容量(单位M)、一级缓存目录数量、二级缓存目录数量
cache_dir ufs /var/spool/squid 128 16 256
cache_mem 128 MB
coredump_dir /var/spool/squid

refresh_pattern ^ftp:   1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .       0       20%     4320


# 重启squid服务
systemctl restart squid
验证代理

可以使用浏览器设置代理的方式,也可以直接使用 curl 命令来测试,其中 -x 选项即 --proxy,添加代理服务器地址和端口,如下:

[root@squid ~]# curl  -xlocalhost:3128 www.baidu.com -I
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Content-Length: 277
Content-Type: text/html
Date: Fri, 29 May 2020 12:40:45 GMT
ETag: "575e1f60-115"
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
X-Cache: MISS from squid
X-Cache-Lookup: MISS from squid:3128
Via: 1.1 squid (squid/3.5.20)
Connection: keep-alive
ACL访问控制

只允许 IP 地址为 39.108.140.0 的客户端使用服务器上的 squid 服务程序提供的代理服务,禁止其余所有的主机代理请求

编辑 /etc/squid/squid.conf,添加如下设置:

acl client src 39.108.140.0
http_access allow client
http_access deny all

[root@blog ~]# curl -x49.233.69.195:3128 -I www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Content-Length: 277
Content-Type: text/html
Date: Fri, 29 May 2020 12:35:27 GMT
ETag: "575e1f60-115"
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
X-Cache: MISS from squid
X-Cache-Lookup: MISS from squid:3128
Via: 1.1 squid (squid/3.5.20)
Connection: keep-alive

    
# 我们试一下其他IP服务器
[root@jd ~]# curl -x49.233.69.195:3128 www.baidu.com -I
HTTP/1.1 403 Forbidden
Server: squid/3.5.20
Mime-Version: 1.0
Date: Fri, 29 May 2020 12:45:44 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 3513
X-Squid-Error: ERR_ACCESS_DENIED 0
Vary: Accept-Language
Content-Language: en
X-Cache: MISS from squid
X-Cache-Lookup: NONE from squid:3128
Via: 1.1 squid (squid/3.5.20)
Connection: keep-alive
禁止所有客户端访问网址包含baidu关键词网站

编辑 /etc/squid/squid.conf,添加如下设置

acl deny_keyword url_regex -i baidu
http_access deny deny_keyword

systemctl restart squid

curl -x49.233.69.195:3128 -I www.baidu.com
HTTP/1.1 403 Forbidden
Server: squid/3.5.20
Mime-Version: 1.0
Date: Fri, 29 May 2020 12:50:39 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 3511
X-Squid-Error: ERR_ACCESS_DENIED 0
Vary: Accept-Language
Content-Language: en
X-Cache: MISS from squid
X-Cache-Lookup: NONE from squid:3128
Via: 1.1 squid (squid/3.5.20)
Connection: keep-alive


curl -x49.233.69.195:3128 -I https://www.cnblogs.com/you-men/
HTTP/1.1 200 Connection established

HTTP/1.1 200 OK
Date: Fri, 29 May 2020 12:50:06 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Vary: Accept-Encoding
禁止下载带有某些后缀的文件,比如.rar和.avi
acl badfile urlpath_regex -i \.rar$ \.avi$
http_access deny badfile

systemctl restart squid
# 此处就不测试了

反向代理

反向代理(Reverse Proxy)方式是指以代理服务器来接受 internet 上的连接请求,然后将请求转发给内部网络上的服务器,并将从内部服务器上得到的结果返回给 internet 上请求连接的客户端,此时代理服务器对外就表现为一个服务器。

网站页面是由静态资源和动态资源一起组成的,其中静态资源包括网站架构 CSS/js 文件、大量的图片、视频等数据,这些数据相对于动态资源来说更加稳定,一般不会经常发生改变。但是随着建站技术的更新换代,外加人们不断提升的审美能力,这些静态资源占据的网站空间也越来越多。如果能够把这些静态资源从网站页面中抽离出去,然后在全国各地部署静态资源的缓存节点,这样不仅可以提升用户访问网站的速度,而且网站源服务器也会因为这些缓存节点的存在而降低负载。

反向代理是 Squid 服务程序的一种重要模式,其原理是把一部分原本向网站源服务器发起的用户请求交给 Squid 服务器缓存节点来处理。但是这种技术的弊端也很明显,如果有心怀不轨的人将自己的域名和服务器反向代理到某个知名的网站上面,从理论上来讲,当用户访问到这个域名时,也会看到与那个知名网站一样的内容(有些诈骗网站就是这样骗取用户信任的)。因此,当前许多网站都默认禁止了反向代理功能。开启了 CDN(内容分发网络)服务的网站也可以避免这种窃取行为。如果访问开启了防护功能的网站,一般会提示 500 错误。

将端口号 "http_port 3128" 修改为 "http_port 80 accel vhost vport",此时正向解析会被暂停,它不能与反向代理服务同时使用,然后再增加你要代理的后端真实服务器的信息。

编辑 /etc/squid/squid.conf,添加如下设置:

配置squid
# 监听端口
# 修改端口80 accel vhost vport 为反向代理
http_port 80  accel vhost vport
# cache_peer 代理IP 端口 0 originserver  name=a "a"代表一个域名
cache_peer 39.108.140.0 parent 80 0 originserver name=a
cache_peer 116.196.83.113  parent 80 0 originserver name=b
# 设置a的域名为 www.qq.com
#cache_peer_domain a www.qq.com
#cache_peer_domain b www.baidu.com
# acl权限控制
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl SSL_ports port 443
acl Safe_ports port 80 8080         # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost
http_access allow all

# 设置缓存文件位置、cache目录容量(单位M)、一级缓存目录数量、二级缓存目录数量
cache_dir ufs /var/spool/squid 128 16 256
cache_mem 128 MB
coredump_dir /var/spool/squid

refresh_pattern ^ftp:   1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .       0       20%     4320

systemctl restart squid
# 我们访问squid,可以看到代理我另一台博客服务器去了

Squid常用命令选项

# 常用的选项就是上面提到的 squid -k check,squid -k reconfigure 和 squid -k parse,这些命令均可以简写成:

# squid -kche(或 squid -k che),表示检查 squid.conf 配置文件是否有语法或配置错误。

# squid -krec(或 squid -k rec),表示当 squid.conf 进行过配置更改后,可以使用该命令进行 squid 配置重载,而不用重启 squid 服务,相当于热加载。

# squid -kpar(或 squid -k par),表示如果 squid.conf 有语法或配置错误,这里会返回提示你,如果没有返回,尝试启动 squid。

Squid安全配置

// 配置文件ACL后添加
header_access X-Cache deny all
header_access X-Squid-Error deny all
header_access Via deny all
header_access Server deny all
header_access X-Cache deny all
header_access X-Cache-Lookup deny all

// 其他header也可隐藏
Accept         HTTP_ACCEPT
Accept-Charset         HTTP_ACCEPT-CHARSET
Accept-Encoding         HTTP_ACCEPT-ENCODING
Accept-Language         HTTP_ACCEPT-LANGUAGE
Accept-Ranges         HTTP_ACCEPT-RANGES
Age         HTTP_AGE
Allow         HTTP_ALLOW
Authorization         HTTP_AUTHORIZATION
Cache-Control         HTTP_CACHE-CONTROL
Connection         HTTP_CONNECTION
Content-Base         HTTP_CONTENT-BASE
Content-Disposition         HTTP_CONTENT-DISPOSITION
Content-Encoding         HTTP_CONTENT-ENCODING
Content-Language         HTTP_CONTENT-LANGUAGE
Content-Length         HTTP_CONTENT-LENGTH
Content-Location         HTTP_CONTENT-LOCATION
Content-MD5         HTTP_CONTENT-MD5
Content-Range         HTTP_CONTENT-RANGE
Content-Type         HTTP_CONTENT-TYPE
Cookie         HTTP_COOKIE
Date         HTTP_DATE
ETag         HTTP_ETAG
Expires         HTTP_EXPIRES
From         HTTP_FROM
Host         HTTP_HOST
If-Match         HTTP_IF-MATCH
If-Modified-Since         HTTP_IF-MODIFIED-SINCE
If-None-Match         HTTP_IF-NONE-MATCH
If-Range         HTTP_IF-RANGE
Last-Modified         HTTP_LAST-MODIFIED
Link         HTTP_LINK
Location         HTTP_LOCATION
Max-Forwards         HTTP_MAX-FORWARDS
Mime-Version         HTTP_MIME-VERSION
Pragma         HTTP_PRAGMA
Proxy-Authenticate         HTTP_PROXY-AUTHENTICATE
Proxy-Authentication-Info         HTTP_PROXY-AUTHENTICATION-INFO
Proxy-Authorization         HTTP_PROXY-AUTHORIZATION
Proxy-Connection         HTTP_PROXY-CONNECTION
Public         HTTP_PUBLIC
Range         HTTP_RANGE
Referer         HTTP_REFERER
Request-Range         HTTP_REQUEST-RANGE
Retry-After         HTTP_RETRY-AFTER
Server         HTTP_SERVER
Set-Cookie         HTTP_SET-COOKIE
Title         HTTP_TITLE
Transfer-Encoding         HTTP_TRANSFER-ENCODING
Upgrade         HTTP_UPGRADE
User-Agent         HTTP_USER-AGENT
Vary         HTTP_VARY
Via         HTTP_VIA
Warning         HTTP_WARNING
WWW-Authenticate         HTTP_WWW-AUTHENTICATE
Authentication-Info         HTTP_AUTHENTICATION-INFO
X-Cache         HTTP_X-CACHE
X-Cache-Lookup         HTTP_X-CACHE-LOOKUP
X-Forwarded-For         HTTP_X-FORWARDED-FOR
X-Request-URI         HTTP_X-REQUEST-URI
X-Squid-Error         HTTP_X-SQUID-ERROR
Negotiate         HTTP_NEGOTIATE
X-Accelerator-Vary         HTTP_X-ACCELERATOR-VARY
Other:         HTTP_OTHER:

// squiid3.0版本使用参数
reply_header_access Server deny all
reply_header_access X-Cache deny all
reply_header_access Warning deny all
reply_header_access Expires deny all
reply_header_access Cache-Control deny all
reply_header_access age deny all

// 隐藏版本
httpd_suppress_version_string on 

Squid+HAProxy+Keepalived

使用HAProxy的目的

haproxy是负载均衡器,它可以将网络请求按一定算法均匀分布到各个代理服务器(这里指正向代理)上,防止压力都集中在某一个节点上,提高整体的服务的负载能力。

假设有103台主机需要出外网,其中只有2台能直接访问外网,那么我们接着假设这两台主机的IP分别是192.168.29.210, 192.168.29.211,且已经在上面安装好squid代理服务。 还有一台主机我们将其选做负载均衡所在的机器,假设其IP为192.168.29.212。

按上述做法,在其余100台主机上可以设置代理(IE “Internet选项->连接->局域网设置->代理服务器” )为192.168.29.212,haproxy负载均衡器会将网络请求按一定算法均匀打到192.168.29.210, 192.168.29.211两台代理服务器上。

安装配置Squid
yum -y install squid
cat /etc/squid/squid.conf
cat /etc/squid/squid.conf
acl localnet src 10.0.0.0/8	
acl localnet src 172.16.0.0/12
acl localnet src 192.168.0.0/16
acl localnet src fc00::/7     
acl localnet src fe80::/10   
acl SSL_ports port 443
acl Safe_ports port 80	
acl Safe_ports port 21
acl Safe_ports port 443
acl Safe_ports port 70
acl Safe_ports port 210
acl Safe_ports port 1025-65535
acl Safe_ports port 280
acl Safe_ports port 488
acl Safe_ports port 591
acl Safe_ports port 777
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localnet
http_access allow localhost
http_access deny all
http_port 80 
coredump_dir /var/spool/squid
refresh_pattern ^ftp:		1440	20%	10080
refresh_pattern ^gopher:	1440	0%	1440
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0
refresh_pattern .		0	20%	4320

systemctl restart squid
curl -x192.168.0.103:80 www.baidu.com -I
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Content-Length: 277
Content-Type: text/html
Date: Sat, 30 May 2020 06:24:34 GMT
ETag: "575e1f59-115"
Last-Modified: Mon, 13 Jun 2016 02:50:01 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
X-Cache: MISS from squid-1
X-Cache-Lookup: MISS from squid-1:80
Via: 1.1 squid-1 (squid/3.5.20)
Connection: keep-alive
安装配置HAProxy
yum -y install haproxy
cat /etc/haproxy/haproxy.cfg 
global
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    stats socket /var/lib/haproxy/stats
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000
frontend http-in 
    bind *:8000
    default_backend servers
backend servers
    balance leastconn 
    server server1 192.168.171.134:80
    server server2 192.168.171.141:80

systemctl restart haproxy


curl -x192.168.171.141:8000 -I www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Content-Length: 277
Content-Type: text/html
Date: Sat, 30 May 2020 07:53:13 GMT
ETag: "575e1f5d-115"
Last-Modified: Mon, 13 Jun 2016 02:50:05 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
X-Cache: MISS from squid-1
X-Cache-Lookup: MISS from squid-1:80
Via: 1.1 squid-1 (squid/3.5.20)
安装配置Keepalived
yum -y install keepalived

cat /etc/keepalived/keepalived.conf 
global_defs {
     router_id node103
}

vrrp_script chk_squid_port {
     script "/etc/keepalived/scripts/check_squid.sh"
     interval 2
     weight 2
}

vrrp_instance chk_squid {
     state BACKUP 
     interface ens32
     virtual_router_id 20
     priority 99
     advert_int 1
     authentication {
        auth_type PASS
        auth_pass squid123
     }

     track_script {
        chk_squid_port
     }

     virtual_ipaddress {
        192.168.171.250
     }
}

mkdir -p /etc/keepalived/scripts/
mkdir -p /etc/keepalived/log/

cat /etc/keepalived/scripts/check_squid.sh 
#!/bin/bash

START_SQUID="systemctl start squid.service"
STOP_KEEPALIVED="systemctl stop keepalived.service"
LOGFILE="/etc/keepalived/log/keepalived-squid-state.log"

HAPS=`ps -C squid --no-header |wc -l`

if [ $HAPS -eq 0 ];then
   echo $(date "+%Y-%m-%d %H:%M:%S") >> $LOGFILE
   echo "start squid failed, killall keepalived" >> $LOGFILE
   $STOP_KEEPALIVED

fi
chmod a+x /etc/keepalived/scripts/check_squid.sh
systemctl restart keepalived

curl -x192.168.171.250:80 -I www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Content-Length: 277
Content-Type: text/html
Date: Sat, 30 May 2020 07:48:47 GMT
ETag: "575e1f5d-115"
Last-Modified: Mon, 13 Jun 2016 02:50:05 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
X-Cache: MISS from squid-1
X-Cache-Lookup: MISS from squid-1:80
Via: 1.1 squid-1 (squid/3.5.20)
Connection: keep-alive

# 我们模拟其中一台squid宕机, 虚拟IP会漂移到另一台机器,依然能提供服务支持    
systemctl stopo squid    

还有一种是如果正向代理服务器多, 可以用haproxy反代一下, 将正向代理的请求分发到不同的squid, 在haproxy的基础上做高可用

cat /etc/keepalived/keepalived.conf 
global_defs {
     router_id node104
}

vrrp_script chk_http_port {
     script "/etc/keepalived/scripts/check_haproxy.sh"
     interval 2
     weight 2
}

vrrp_script chk_squid_port {
     script "/etc/keepalived/scripts/check_squid.sh"
     interval 2
     weight 2
}

vrrp_instance chk_squid {
     state MASTER
     interface ens32
     virtual_router_id 20
     priority 100
     advert_int 1
     authentication {
        auth_type PASS
        auth_pass squid123
     }

     track_script {
        chk_squid_port
     }

     virtual_ipaddress {
        192.168.171.250
     }
}


cat /etc/keepalived/scripts/check_haproxy.sh 
#!/bin/bash

START_HAPROXY="systemctl start haproxy"
STOP_KEEPALIVED="systemctl stop keepalived.service"
LOGFILE="/etc/keepalived/log/keepalived-haproxy-state.log"

HAPS=`ps -C haproxy --no-header |wc -l`

#如果没有haproxy进程存在,就启动haproxy,停止keepalived,并写入日志
#if [ $HAPS -eq 0 ];then
#   echo $(date "+%Y-%m-%d %H:%M:%S") >> $LOGFILE
#   echo $START_HAPROXY >> $LOGFILE
#   $START_HAPROXY >> $LOGFILE 2>&1
#   sleep 3
#fi

if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then
   echo $(date "+%Y-%m-%d %H:%M:%S") >> $LOGFILE
   echo "start haproxy failed, killall keepalived" >> $LOGFILE
   $STOP_KEEPALIVED
fi
chmod a+x /etc/keepalived/scripts/check_haproxy.sh
systemctl restart keepalived

curl -x192.168.171.250:8000 -I www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Content-Length: 277
Content-Type: text/html
Date: Sat, 30 May 2020 08:08:33 GMT
ETag: "575e1f5c-115"
Last-Modified: Mon, 13 Jun 2016 02:50:04 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
X-Cache: MISS from squid-1
X-Cache-Lookup: MISS from squid-1:80
Via: 1.1 squid-1 (squid/3.5.20)

posted @ 2020-05-31 22:30  常见-youmen  阅读(1852)  评论(0编辑  收藏  举报