安装前准备:

本文不对iptables和selinux做设置,关掉

确保代理主机能上网

下载源码包squid-3.4.6.tar.gz

环境介绍

192.168.100.150为代理服务器,192.168.100.151为内网测试服务器(可以换xp等)


安装squid:

[root@localhost network-scripts]# vi ifcfg-eth0  

DEVICE=eth0

HWADDR=00:0C:29:88:f9:43

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=static

IPADDR=192.168.100.150

NETMASK=255.255.255.0

GATEWAY=192.168.100.150

:wq

cd /etc/sysconfig/network-scripts/

[root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-eth1

[root@localhost network-scripts]# vi ifcfg-eth1

DEVICE=eth1

HWADDR=00:0c:29:88:f9:4d   ##使用ip a查看MAC,务必使MAC地址一致

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=dhcp

:wq

vi /etc/udev/rules.d/70-persistent-net.rules ##根据mac地址来修改相对应的网卡

/etc/init.d/network restart  ##重启网络

ping www.baidu.com  ##确保代理主机能上网

编写安装配置脚本:

编写安装脚本:

vi squit.installconfig.sh

#!/bin/bash

##by linuxfan.cn

SQV='squid-3.4.6'

##############install squid################

if [ -e /root/$SQV.tar.gz ];then

tar zxvf /root/$SQV.tar.gz -C /usr/src/

cd /usr/src/$SQV

./configure --prefix=/usr/local/squid --sysconfdir=/etc --enable-arp-acl --enable-linux-netfilter --enable--linux-tproxy --enable-async-io=100 --enable-err-language="Simplify_Chinese" --enable-underscore --enable-poll --enable-gnuregex

make &&make install

fi

###############config squid#################

if [ -e /usr/local/squid/var ];then

ln -s /usr/local/squid/sbin/* /usr/local/sbin/

useradd -M -s /sbin/nologin squid

chown -R squid:squid /usr/local/squid/var/

fi

:wq

sh -x squid.installconfig.sh ##执行脚本


squid的运行控制: 

squid -k parse  ##检测配置文件语法

sed -i '/^http_port/a cache_effective_user squid\ncache_effective_group squid' /etc/squid.conf  ##添加两行,指定squid进程用户

[root@www ~]# squid -z  ##初始化缓存目录

[root@www ~]# squid  ##启动服务

[root@www ~]# netstat -utpln |grep 3128

tcp        0      0 :::3128                     :::*                        LISTEN      35833/(squid-1)  


为新安装的squid添加man帮助的支持:

[root@www ~]# yum -y install man

[root@www ~]# sed -i '47aMANPATH /usr/local/squid/share/man/' /etc/man.config 

[root@www ~]# man squid


为squid编写服务脚本,并配置:

vi /etc/init.d/squid

#!/bin/bash

# chkconfig: 35 90 25

# config file:/etc/squid.conf

# Description: squid - internet object cache.

PID="/usr/local/squid/var/run/squid.pid"

CONF="/etc/squid.conf"

CMD="/usr/local/squid/sbin/squid"

case "$1" in

start)

netstat -utpln |grep squid &>/dev/null

if [ $? -eq 0 ];then

echo "squid is running."

else

echo "squid is starting."

$CMD

fi

;;

stop)

$CMD -k kill &>/dev/null

rm -rf $PID &>/dev/null

echo "squid is stoped."

;;

status)

[ -f $PID ] &>/dev/null

if [ $? -eq 0 ];then

netstat -anpt |grep squid

else

echo "squid is not running" &&/bin/false

fi

;;

restart)

$0 stop 

$0 start

;;

reload)

$CMD -k reconfigure

;;

check)

$CMD -k parse

;;

*)

echo "Usage:$0 {start|stop|restart|reload|check|status}"

exit 1

;;

esac

:wq

chmod +x /etc/init.d/squid 

chkconfig --add squid

chkconfig squid on

sed -i '55ahttp_access allow all' /etc/squid.conf   ##设置acl策略为允许所有,必须在deny前

sed -i '59areply_body_max_size 10 MB' /etc/squid.conf  ##允许下载最大文件大小为10M

/etc/init.d/squid reload


测试:


添加为linux主机192.168.100.151设置代理:

cat <<END >>/etc/profile

HTTP_PROXY=http://192.168.100.150:3128

NO_PROXY=192.168.100.100

export HTTP_PROXY HTTPS_PROXY FTP_PROXY NO_PROXY

END

source /etc/profile

yum -y install elinks

elinks http://192.168.100.150:3128


windows添加代理:

运行--》inetcpl.cpl--》链接--》局域网--》代理:192.168.100.150 --》3128

启动IE访问.


代理服务器验证:

[root@www ~]# tail /usr/local/squid/var/logs/access.log