欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

squid安装与配置

程序员文章站 2022-05-10 09:27:01
...

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 (缓存目录)

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 256100M,)

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=30originserver代表真实serverweight权重,越大越优先)

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

无心