Nginx+Squid+Apache2
--enable-storeio=ufs,null //使用的文件系统通常是默认的ufs,不过如果想要做一个不缓存任何文件的代理服务器,就需要加上null文件系统。
--enable-underscore //允许解析的URL中出现下划先,因为默认squid会认为带下划线的URL地址是非法的,并拒绝访问该地址。
#make && make install
# /usr/local/squid/sbin/squid -z //测试Squid运行状况
# chown -R squid.squid /usr/local/squid/var/
修改squid配置文件
#vim /usr/local/squid/etc/squid.conf
#########一些访问控制的设置##############
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
http_access allow all
http_access allow localnet
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
icp_access allow localnet
icp_access deny all
htcp_access allow localnet
htcp_access deny all
##### 配置 squid2、squid3 为其邻居,当 squid1 在其缓存中没有找到请求的资源时,通过 ICP 查询去其邻居中取得缓存############
cache_peer s2.test.com sibling 80 3130
cache_peer s3.test.com sibling 80 3130
#### 将pic.test.com 域的请求通过 RR 轮询方式转发到apache节点############
squid1 的父节点,originserver 参数指明是源服务器, round-robin 参数指明 squid 通过轮询方式将请求分发到其中一台父节点; squid 同时会对这些父节点的健康状态进行检查,如果父节点 down 了,那么 squid 会从剩余的 origin 服务器中抓取数据.我们这里只有一个节点.
cache_peer 192.168.128.136 parent 80 0 no-query originserver round-robin name=web1
cache_peer_domain web1 pic.test.com
hierarchy_stoplist cgi-bin
####### 对 squid 的一些优化 ###############
maximum_object_size_in_memory 1024 KB //内存中缓存的最大对象 1024KB
maximum_object_size 10240 KB // 能缓存的最大对象为 10M
cache_mem 64 MB //squid 用于缓存的内存量
#####日志和缓存目录的设置###########
access_log /usr/local/squid/var/logs/access.log squid
cache_log /usr/local/squid/var/logs/cache.log
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern (cgi-bin|\?) 0 0% 0
refresh_pattern . 0 20% 4320
cache_effective_user squid
cache_effective_group squid
######### 设定 squid 的主机名 , 如无此项 squid 将无法启动
visible_hostname s1.test.com
############# 配置 squid 为加速模式 #################
http_port 80 accel vhost vport
icp_port 3130
coredump_dir /usr/local/squid/var/cache
在hosts添加如下行.让squid能找到其邻居.
#cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.128.137 s2.test.com
192.168.128.139 s3.test.com
其他两台squid配置跟其一致.只要修改上面标明颜色的地方和/etc/hosts文件即可.
Squid开机自动启动的实现:
# vim /etc/init.d/squid
#!/bin/sh
#chkconfig: 35 85 15
#deion: squid
#function: use this
#author:hsf
squid_BIN=/usr/local/squid/sbin/squid
squid_CONF=/usr/local/squid/etc/squid.conf
squid_PID=/usr/local/squid/var/logs/squid.pid
squid_PORT=`/bin/netstat -ntpl |grep squid |grep 80 |wc -l`
case $1 in
start)
if [ $squid_PORT = 0 ];then
echo "staring squid..."
$squid_BIN
else echo "starting squid failed,Address already in use..."
exit 2
fi
;;
stop)
echo "stoping squid..."
if [ -f $squid_PID ];then
kill -QUIT `cat $squid_PID`
else echo "squid is no running...."
fi
;;
status)
if [ -f $squid_PID ];then
echo "squid is running..."
else echo "squid is stop..."
fi
;;
restart)
if [ -f $squid_PID ];then
kill -HUP `cat $squid_PID`
else echo "squid is no running...."
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
Apache安装(192.168.128.136)
见apache安装配置文档.
关键字:关键字:Nginx Squid Apache
新文章:
- CentOS7下图形配置网络的方法
- CentOS 7如何添加删除用户
- 如何解决centos7双系统后丢失windows启动项
- CentOS单网卡如何批量添加不同IP段
- CentOS下iconv命令的介绍
- Centos7 SSH密钥登陆及密码密钥双重验证详解
- CentOS 7.1添加删除用户的方法
- CentOS查找/扫描局域网打印机IP讲解
- CentOS7使用hostapd实现无AP模式的详解
- su命令不能切换root的解决方法
- 解决VMware下CentOS7网络重启出错
- 解决Centos7双系统后丢失windows启动项
- CentOS下如何避免文件覆盖
- CentOS7和CentOS6系统有什么不同呢
- Centos 6.6默认iptable规则详解