服务器: centos 6.3
squid版本 squid-2.7.STABLE9
bind版本 bind-9.9.2-P2.tar.gz
先安装squid 所需的组件 , 关闭iptables, selinux
yum -y install gcc perl make
1. 在根目录创建maichuang目录, 并解压squid包
[root@localhost /]# mkdir maichuang
[root@localhost /]# cd /data
[root@localhost data]# tar xzvf squid-2.7.STABLE9.tar.gz
[root@localhost data]# cd squid-2.7.STABLE9
2. 编译安装squid
[root@localhost squid-2.7.STABLE9]# ./configure --enable-kill-parent-hack --enable-large-cache-files --with-large-files --with-maxfd=344800 --enable-snmp --disable-ident-lookups --enable-carp --enable-async-io=160 --enable-storeio=ufs,aufs,diskd,null,coss --enable-epoll --enable-linux-netfilter --enable-stacktraces --enable-forward-log --enable-referer-log --enable-useragent-log --enable-delay-pools --enable-follow-x-forwarded-for --enable-forw-via-db --enable-default-err-language=Simplify_Chinese --enable-err-languages="Simplify_Chinese English" --without-system-md5 --disable-internal-dns --prefix=/maichuang/squid
[root@localhost squid-2.7.STABLE9]# make
[root@localhost squid-2.7.STABLE9]# make install
5. 将centos自带的python 2.6 升级到 2.7 (不属于squid配置范畴,服务器代码需要才装2.7)
[root@localhost data]# wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz #如果没有wget 安装一个 yum install wget
[root@localhost data]# tar xzvf Python-2.7.3.tgz
[root@localhost data]# cd Python-2.7.3
[root@localhost Python-2.7.3]# ./configure --prefix=/home/mc-ops/python2.7
[root@localhost Python-2.7.3]# make && make install
[root@localhost Python-2.7.3]# cd /usr/local/bin/
[root@localhost mc-ops]#ln -s /maichuang/python2.7/bin/python2.7 #(我的python程序代码头是#!/usr/bin/env python2.7)
#(一般是
./configure --prefix=/usr/local/bin/python2.7
mv/usr/bin/python/usr/bin/python2.6
ln-s /usr/local/bin/python2.7 /usr/bin/python
因为yum依赖python2.6,所以要修改一下yum
vi/usr/bin/yum
将文件开始的
#!/usr/bin/python
改成
#!/usr/bin/python2.6
)
6. 运行squid
1. 初始化你在squid.conf里配置的cache目录
[root@localhost squid]# /maichuang/squid/sbin/squid -z //初始化缓存空间
如果有错误提示,请检查你的cache目录的权限。
2. 对你的squid.conf排错,即验证squid.conf的语法和配置。
[root@localhost squid]# /maichuang/squid/sbin/squid -k parse
如果squid.conf有语法或配置错误,这里会返回提示你,如果没有返回,恭喜,可以尝试启动squid。
3. 启动squid在后台运行。
[root@localhost squid]# /maichuang/squid/sbin/squid -s
4. 重新加载配置文件
[root@localhost squid]# /maichuang/squid/sbin/squid –k reconfigure
5. 结束squid进程
[root@localhost squid]# /maichuang/squid/sbin/squid –k shutdown
到此 结束
6. 跳过DNS 检测 ("DNS name lookup tests failed")
默认情况下,squid在启动前执行一些DNS查询。这点确保你的DNS服务器可到达,并且运行正确。假如测试失败,可在cache.log或syslog里见到如下消息:FATAL: ipcache_init: DNS name lookup tests failed
假如你在内网里使用squid,squid可能不能查询到它的标准主机名列表。可使用dns_testnames指令来指定你自己的主机名。只要接受到响应,squid就会认为DNS测试成功。
假如你想完全跳过DNS测试,简单的在启动squid时,使用-D命令行选项:
% squid -D ...
7. 安自己需求配置squid
[root@localhost utils]# cd /data/utils
[root@localhost utils]# ./SquidConfGen.py
/maichuang/squid/etc/common.conf
/maichuang/squid/etc/device.conf
/maichuang/squid/etc/squid1.conf
/maichuang/squid/etc/squid2.conf
/maichuang/squid/etc/squid3.conf
/maichuang/squid/etc/squid4.conf
8. 编译安装bind
进入bind-9.9.2-P2目录
[root@localhost data]# cd bind-9.9.2-P2
[root@localhost bind-9.9.2-P2]#
[root@localhost bind-9.9.2-P2]# ./configure --prefix=/maichuang/bind --enable-threads --without-openssl
[root@localhost bind-9.9.2-P2]# make && make install
http://dns-learning.twnic.net.tw/bind/toc.html bind 安装 参考
http://www.cnblogs.com/shineshqw/articles/1807031.html
a.先删除本地默认的dns解析
vim /etc/resolv.conf
把nameserver 指向本机即 nameserver 127.0.0.1
b.将squid配置的默认DNS指向本机127.0.0.1
c. vim /maichuang/bind/var/anyhosts
portal.*****.** IN A 223.4.233.***
d.重新加载bind
/maichuang/bind/sbin/rndc reload
e. 检测anyhost是否正确
[root@EACNCTCSHHSHH01C001 var]# /maichuang/bind/sbin/named-checkzone . /maichuang/bind/var/anyhosts
zone ./IN: loaded serial 20051213
OK
9. 初始化并运行squid
[root@localhost squid]# /maichuang/squid/sbin/squid -z -f /maichuang/squid/etc/squid1.conf
2013/04/18 17:08:12| Creating Swap Directories
[root@localhost squid]# /maichuang/squid/sbin/squid -z -f /maichuang/squid/etc/squid2.conf
2013/04/18 17:08:43| Creating Swap Directories
[root@localhost squid]# /maichuang/squid/sbin/squid -s -f /maichuang/squid/etc/squid1.conf
[root@localhost squid]# /maichuang/squid/sbin/squid -s -f /maichuang/squid/etc/squid2.conf
运行成功
一下是简单的测试命令
curl http://**.pinla.com/do_not_delete/200.png -x 127.0.0.1:8081 -o /dev/null -v
/maichuang/squid/bin/squidclient -p 8081 -U manager -W xxx mgr:config
/maichuang/squid/sbin/squid -f /maichuang/squid/etc/squid1.conf -d 1
/maichuang/bind/bin/dig @10.0.0.10 **.pinla.com
curl -vo /dev/null -w time_total:%{time_total}\\ntime_dns:%{time_namelookup}\\ntime_connect:%{time_connect}\\nfirst_byte:%{time_pretransfer}\\ntime_download:%{time_starttransfer}\\n http://uri.xdcdn.net/sxd/tree/0f4272df1637f596a92db6588b7b8a5d1a1aa853/TianMingSheng.swf -x 211.9*.10.*:80