squid安装与配置
[root@localhost ~]# yum -y install squid
[root@localhost ~]# rpm -ql squid(释放文件)
/etc/squid/squid.conf
/etc/squid/msntauth.conf.default(配置文件模板)
/var/log/squid(日志目录)
/var/spool/squid(缓存目录)
[root@localhost ~]# 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服务器
eth0 200.200.200.10
eth1 192.168.10.8
web服务器
eth0 200.200.200.100
[root@www ~]# iptables -p input drop (-p默认规则)
[root@localhost ~]# iptables -i input -p tcp --dport 22 -j accept
[root@localhost ~]# iptables -i input -p tcp --dport 80 -j accept
squid服务器
[root@localhost ~]# service squid restart(启动服务,无需配置)
stopping squid: .............. [ ok ]
starting squid: . [ ok ]
[root@localhost ~]# 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服务器
eth0 200.200.200.10 eth1 192.168.10.8
[root@localhost ~]# vim /etc/squid/squid.conf
http_port 192.168.10.8:3128 transparent
[root@localhost ~]#iptables -t nat -i prerouting -i eth1 -s 192.168.10.0/24 -p tcp --dport 80 -j redirect --to-ports 3128
[root@localhost ~]# service iptables save
开启路由转发
[root@localhost ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 0
[root@localhost ~]# sysctl -p
配置nat
[root@localhost ~]# iptables -t nat -i postrouting -s 192.168.10.0/24 -o eth1 -j snat --to-source 200.200.200.10
web服务器
eth0 200.200.200.100
[root@localhost ~]# iptables -l --line-numbers
chain input (policy drop)
num target prot opt source destination
1 accept tcp -- anywhere anywhere tcp dpt:http
2 accept tcp -- anywhere anywhere tcp dpt:ssh
测试
3.squid反向代理
[root@localhost ~]# vim /etc/squid/squid.conf
http_port 218.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(允许外部所有访问)
[root@localhost ~]# service squid restart
无心
