hwl198212 发表于 2018-12-27 06:10:03

squid安装与配置

Squid安装与配置
# yum -y install squid
# rpm -ql squid(释放文件)
/etc/squid/squid.conf
/etc/squid/msntauth.conf.default(配置文件模板)
/var/log/squid(日志目录)
/var/spool/squid(缓存目录)

# vim /etc/squid/squid.conf(常用基本配置)
http_port 3128
cache_mem 64 MB 内存占用量
maximum_object_size 4096 KB(最大缓存)
access_log /var/log/squid/access.log squid
visible_hostname proxy.openlab.com(代理服务器主机名)
dns_testnames www.google.com www.163.com(测试DNS)
cache_dir ufs /var/spool/squid 100 16 256(100M,)

1.squid 服务器实现基本代理
squid服务器
eth0200.200.200.10
eth1192.168.10.8
WEB服务器
eth0 200.200.200.100
# iptables -P INPUT DROP            (-P默认规则)
# iptables -I INPUT -p tcp --dport 22 -j ACCEPT
# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
squid服务器
# service squid restart(启动服务,无需配置)
Stopping squid: ..............                           
Starting squid: .                                          
# vim /etc/squid/squid.conf
cache_dir ufs /var/spool/squid 100 16 256(去掉前面#)
reply_body_max_size 10 MB(不允许下载大于10M附件,此行需添加)
acl RealFile urlpath_regex -i \.mp3$(添加一条acl)
(http_access deny all)

2.透明代理

Squid服务器
Eth0200.200.200.10 eth1192.168.10.8
# vim /etc/squid/squid.conf
http_port 192.168.10.8:3128 transparent
#iptables -t nat -I PREROUTING -i eth1 -s 192.168.10.0/24 -p tcp --dport 80 -j REDIRECT --to-ports 3128
# service iptables save
开启路由转发
# vim /etc/sysctl.conf
net.ipv4.ip_forward = 0
# sysctl -p
配置nat
# iptables -t nat -I POSTROUTING -s 192.168.10.0/24 -o eth1 -j SNAT --to-source 200.200.200.10
WEB服务器
Eth0200.200.200.100
# iptables-L --line-numbers
Chain INPUT (policy DROP)
numtarget   prot opt source               destination         
1    ACCEPT   tcp--anywhere             anywhere            tcp dpt:http
2    ACCEPT   tcp--anywhere             anywhere            tcp dpt:ssh
测试


3.Squid反向代理

# vim /etc/squid/squid.conf
http_port218.29.30.31:80 vhost (vhost虚拟主机,80因为http默认是80,所以代理端口写成80)
cache_peer 192.168.2.11 parent 80 0 originserver weight=5 max-conn=30(originserver代表真实server,weight权重,越大越优先)
cache_peer 192.168.2.12 parent 80 0 originserver weight=5 max-conn=30
cache_peer 192.168.2.13 parent 80 0 originserver weight=5 max-conn=30
cache_peer 192.168.2.14 parent 80 0 originserver weight=1 max-conn=8
http_access allow all(允许外部所有访问)
# service squid restart



页: [1]
查看完整版本: squid安装与配置