使用squid作为方向代理服务器可以像nginx一样起到缓存功能,并且可以将缓存内容保存在内存中,nginx是将缓存内容保存在硬盘上,配置原理与nginx一样,squid自己以web服务器方式工作,方向代理后端的web服务器给用户。
1、安装squid
tar -zxvf squid-3.4.10.tar.gz
cd squid-3.4.10
./configure --prefix=/usr/local/squid
--enable-gnuregex
--enable-icmp
--enable-linux-netfilter
--enable-default-err-language="Simplify_Chinese"
--enable-kill-parent-hack
--enable-cache-digests
--enable-dlmalloc
--enable-poll
--enable-async-io=240
--enable-delay-pools
--with-filedescriptors=65536
--enable-snmp
--enable-arp-acl
--with-large-files
make && make install
创建squid服务用户,并设置缓存目录权限
useradd -s /bin/nolog -M squid
chown -R squid:squid /usr/local/squid/var
2、配置squid
?
vim /usr/local/squid/etc/squid.conf
#配置squid服务的用户和组
cache_effective_user squid
cache_effective_group squid
#配置squid监听在80端口,accel是使用加速模式,vhost是使用虚拟主机
http_port 80 accel vhost vport
#定义后端web服务器,如果有多台可以写多个
cache_peer 127.0.0.1 parent 8080 0 no-query originserver round-robin name=node1
http_access allow all
#定义缓存所使用的最大内存
cache_mem 128 MB
#定义最大缓存对象为10MB
maximum_object_size 10240 KB
#定义日志
cache_log /usr/local/squid/var/logs/cache.log
cache_dir ufs /usr/local/squid/var/cache 128 16 256
#定义访问控制元素
#定义名为manage的元素,类型为proto(url访问协议),cache_object机制是squid的特性它用于访问squid的缓存管理接口
acl manager proto cache_object
#定义名为localhost的元素,类型为src(源地址),定义源地址为127.0.0.1/32
acl localhost src 127.0.0.1/32
#定义名称为Safe_ports的元素,类型为port,指定的port值为8080、80
acl Safe_ports port 8080 # proxy
acl Safe_ports port 80 # Web
#定义名为SSL_port的元素,类型为port,值为443
acl SSL_ports port 443 #https
#定义名为Purge,类型为method(http的请求方法),PURGE是squid的特殊方法,能强制删除缓存对象
acl Purge method PURGE
#定义名为CONNECT的元素,类型为method,CONNECT指定的方法
acl CONNECT method CONNECT
#根据定义好的元素创建访问控制列表
#运行任意的http访问
http_access allow all
#只允许本地访问manager元素,用于管理squid
http_access allow manager localhost
#拒绝其他客户端访问manager
http_access deny manager
#拒绝在Safe_ports定义之外的端口的访问
http_access deny !Safe_ports
#拒绝非443端口的connect方法
http_access deny CONNECT !SSL_ports
#只允许本地使用purge元素中定义的地址清除缓存
http_access allow Purge localhost
http_access deny Purge
http_access deny all
icp_access allow all
3、创建squid启动脚本
?
#!/bin/bash
# chkconfig: 2345 85 15
# description: squid is a proxy server
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
[ "$NETWORKING" = "no" ] && exit 0
#
SCREEN=`stty -F /dev/console size 2>/dev/null`
#获取列数,如果 /dev/console 这个文件不存在则设置默认值80
COLUMNS=${SCREEN#* }
[ -z $COLUMNS ] && COLUMNS=80
#定义颜色
RED=' 33[31m'
BLUE=' 33[34m'
GREEN=' 33[32m'
YELLOW=' 33[33m'
#还原为正常
NORMAL=' 33[0m'
SPA_COL=$[$COLUMNS-14]
success() {
string=$1
RT_SPA=$[$SPA_COL-${#string}]
echo -n "$string"
for I in `seq 1 $RT_SPA`;do
echo -n " "
done
echo -e " [ ${GREEN}OK${NORMAL} ]"
}
failure(){
string=$1
RT_SPA=$[$SPA_COL-${#string}]
echo -n "$string"
for I in `seq 1 $RT_SPA`;do
echo -n " "
done
echo -e "[ ${RED}FAILED${NORMAL} ]"
}
squid="/usr/local/squid/sbin/squid"
prog=$(basename $squid)
squid_conf="/usr/local/squid/etc/squid.conf"
rh_status() {
status $prog
}
start() {
rh_status
retval=$?
[ $retval -ne 0 ] && $squid -f $squid_conf && success "Starting squid"
}
stop() {
rh_status
retval=$?
[ $retval -eq 0 ] && $squid -k shutdown && success "Stopping squid"
}
restart() {
$squid -k restart
}
reload() {
$squid -k reconfigure
}
check() {
$squid -f $squid_conf -k check
retval=$?
[ $retval -eq 0 ] && echo "syntax is ok"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
check)
check
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|check}"
esac
荒野乱斗国际版 (BrawlStars)最新版本v56.274
下载一波超人内置修改器菜单版 安卓版v1.0.2
下载敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载继承了一座戏园子无限声望铜钱版 内置菜单最新版v1.7
继承了一座戏园子折相思版是游戏的破解版本,在该版本中为玩家提
山河半世橙光清软金手指版 无限鲜花v3.24
山河半世是一款超级好玩的橙光恋爱游戏,在游戏中玩家们需要扮演
蓬莱手游折相思版 安卓版v1.0.0
蓬莱免广告版是游戏的修改版本,在该版本中为玩家去除了广告,玩
当红影后橙光游戏破解版2025 最新版v1.0
当红影后橙光破解版是一款超级好玩的娱乐圈题材的橙光游戏,在这
忽然成了万人迷清软完结版 无限鲜花版v12.15
忽然成了万人迷破解版是一款非常好玩的男性向橙光游戏,在有一天