正反向代理服务

squid


Squid是一个高性能的代理缓存服务器,Squid支持FTP、gopher、HTTPS和HTTP协议。和一般的代理缓存软件不同,Squid用一个单独的、非模块化的、I/O驱动的进程来处理所有的客户端请求。


正向代理

1.服务端配置

yum install squid
已加载插件:langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 squid.x86_64.7.3.3.8-11.el7 将被 安装
--> 正在处理依赖关系 perl(DBI),它被软件包 7:squid-3.3.8-11.el7.x86_64 需要
--> 正在处理依赖关系 perl(Data::Dumper),它被软件包 7:squid-3.3.8-11.el7.x86_64 需要
...

开启squid服务后,查看所用接口

[root@www ~]# systemctl start squid
[root@www ~]# netstat -antlupe | grep squid
tcp6       0      0 :::3128                 :::*                    LISTEN      0          1997181    8529/(squid-1)      
udp        0      0 0.0.0.0:42829           0.0.0.0:*                           23         1997178    8529/(squid-1)      
udp6       0      0 :::46985                :::*                                23         1997177    8529/(squid-1)      

编辑配置文件,配置文件/etc/squid/squid.conf

        55 # And finally deny all other access to this prox
        56 # http_access deny all  ##禁止所有人访问
        57 http_access allow all   ##允许所有人访问
        58 # Squid normally listens to port 3128
        59 http_port 3128
        60
        61 # Uncomment and adjust the following to add a disk cache directory.
        62 cache_dir ufs /var/spool/squid 100 16 256  ##  访问的时候会在/var/spool/squid 建立16个目录。16个目录下分别有256个子目录,缓存上限是100M,超过100M自动覆盖

进去的配置文件内说明的缓存目录,刚建立没用重启服务情况下,不显示缓存目录
重启后显示,

[root@www ~]# cd /var/spool/squid/
[root@www squid]# ls
[root@www squid]# systemctl restart squid.service 
[root@www squid]# ls
00  01  02  03  04  05  06  07  08  09  0A  0B  0C  0D  0E  0F  swap.state
[root@www squid]# ls 00
00  0D  1A  27  34  41  4E  5B  68  75  82  8F  9C  A9  B6  C3  D0  DD  EA   
...

服务端设定
firefox 菜单 - 首选项 - 高级 - 网络 - 配置firefox网络代理(输入代理服务器ip)

反向代理


编辑配置文件,配置文件/etc/squid/squid.conf

[root@www ~]# vim /etc/squid/squid.conf
 55 # And finally deny all other access to this proxy
 56 # http_access deny all
 57 http_access allow all
 58 # Squid normally listens to port 3128  
 59 http_port 80 vhost vport  ## 反向代理服务器所使用接口
 60 cache_peer 172.25.25.108  parent 80 0 proxy-only  ## 反向代理ip
 61 # Uncomment and adjust the following to add a disk cache directory.
 62 cache_dir ufs /var/spool/squid 100 16 256
0

cd /usr/share/doc/squid-3.3.8/ ##说明配置文件目录

[root@www ~]# cd /usr/share/doc/squid-3.3.8/
[root@www squid-3.3.8]# ls
ChangeLog  COPYRIGHT   README    rredir.pl              url-normalizer.pl
COPYING    QUICKSTART  rredir.c  squid.conf.documented  user-agents.pl
[root@www squid-3.3.8]# less squid.conf.documented   ##查看所需配置文件内容

vim /etc/squid/squid.conf ##编辑配置文件
systemctl restart squid ## 重启服务

反向代理轮循


 55 # And finally deny all other access to this proxy
 56 # http_access deny all
 57 http_access allow all
 58 # Squid normally listens to port 3128
 59 http_port 80 vhost vport
 60 cache_peer 172.25.254.108  parent 80 0 proxy-only  round-robin originserver name=web1  ##  设定108为反向轮循部件
 61 cache_peer 172.25.254.166  parent 80 0 proxy-only round-robin originserver name=web2  ##  设定116为反向轮循部件
 62 cache_peer_domain web1 web2 www.westos.com  轮循web1 web2
 63 # Uncomment and adjust the following to add a disk cache directory.
 64 cache_dir ufs /var/spool/squid 100 16 256

systemctl restart squid.service ## 重启服务
客户端firefox输入www.westos.com ## 会轮循108和116的内容

反向轮循设定次数


vim /etc/squid/squid.conf## 修改配置文件在轮循服务设定后加入参数weight=number

[root@www squid-3.3.8]#  vim /etc/squid/squid.conf  
55 And finally deny all other access to this proxy
   56 # http_access deny all
   57 http_access allow all
   58 # Squid normally listens to port 3128
   59 http_port 80 vhost vport
   60 cache_peer 172.25.254.108  parent 80 0 proxy-only  round-robin originserver name=web1  weight=3  ## 加入weight=3参数  #轮循3次后切换
   61 cache_peer 172.25.254.166  parent 80 0 proxy-only  round-robin originserver name=web2  weight=1  ## 加入weight=1参数  #轮循1次
   62 cache_peer_domain web1 web2 www.westos.com
   63 # Uncomment and adjust the following to add a disk cache directory.
   64 cache_dir ufs /var/spool/squid 100 16 256   

systemctl restart squid.service ## 重启服务
客户端firefox输www.westos.com ##会轮循三次118 一次166的内容

猜你喜欢

转载自blog.csdn.net/lx543733371/article/details/80179585