


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規則詳解