Nginx+Squid+Apache2
--enable-storeio=ufs,null //使用的文件系統(tǒng)通常是默認(rèn)的ufs,不過如果想要做一個(gè)不緩存任何文件的代理服務(wù)器,就需要加上null文件系統(tǒng)。
--enable-underscore //允許解析的URL中出現(xiàn)下劃先,因?yàn)槟J(rèn)squid會(huì)認(rèn)為帶下劃線的URL地址是非法的,并拒絕訪問該地址。
#make && make install
# /usr/local/squid/sbin/squid -z //測試Squid運(yùn)行狀況
# chown -R squid.squid /usr/local/squid/var/
修改squid配置文件
#vim /usr/local/squid/etc/squid.conf
#########一些訪問控制的設(shè)置##############
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 為其鄰居,當(dāng) squid1 在其緩存中沒有找到請(qǐng)求的資源時(shí),通過 ICP 查詢?nèi)テ溧従又腥〉镁彺?###########
cache_peer s2.test.com sibling 80 3130
cache_peer s3.test.com sibling 80 3130
#### 將pic.test.com 域的請(qǐng)求通過 RR 輪詢方式轉(zhuǎn)發(fā)到apache節(jié)點(diǎn)############
squid1 的父節(jié)點(diǎn),originserver 參數(shù)指明是源服務(wù)器, round-robin 參數(shù)指明 squid 通過輪詢方式將請(qǐng)求分發(fā)到其中一臺(tái)父節(jié)點(diǎn); squid 同時(shí)會(huì)對(duì)這些父節(jié)點(diǎn)的健康狀態(tài)進(jìn)行檢查,如果父節(jié)點(diǎn) down 了,那么 squid 會(huì)從剩余的 origin 服務(wù)器中抓取數(shù)據(jù).我們這里只有一個(gè)節(jié)點(diǎn).
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
####### 對(duì) squid 的一些優(yōu)化 ###############
maximum_object_size_in_memory 1024 KB //內(nèi)存中緩存的最大對(duì)象 1024KB
maximum_object_size 10240 KB // 能緩存的最大對(duì)象為 10M
cache_mem 64 MB //squid 用于緩存的內(nèi)存量
#####日志和緩存目錄的設(shè)置###########
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
######### 設(shè)定 squid 的主機(jī)名 , 如無此項(xiàng) squid 將無法啟動(dòng)
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
其他兩臺(tái)squid配置跟其一致.只要修改上面標(biāo)明顏色的地方和/etc/hosts文件即可.
Squid開機(jī)自動(dòng)啟動(dòng)的實(shí)現(xiàn):
# 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安裝配置文檔.
關(guān)鍵字:關(guān)鍵字:Nginx Squid Apache
新文章:
- CentOS7下圖形配置網(wǎng)絡(luò)的方法
- CentOS 7如何添加刪除用戶
- 如何解決centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS單網(wǎng)卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗(yàn)證詳解
- CentOS 7.1添加刪除用戶的方法
- CentOS查找/掃描局域網(wǎng)打印機(jī)IP講解
- CentOS7使用hostapd實(shí)現(xiàn)無AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網(wǎng)絡(luò)重啟出錯(cuò)
- 解決Centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統(tǒng)有什么不同呢
- Centos 6.6默認(rèn)iptable規(guī)則詳解