centos下簡單配置安裝Squid 3.0反向 Proxy_Linux

來源:互聯網
上載者:User

安裝篇:

本教程應用環境為乾淨centos 5.5 ,預先分好並載入/data分區,並且關閉selinux及iptables

首先修改檔案描述符並設定臨時連接埠範圍,這些設定重啟後生效

複製代碼 代碼如下:

cat >> /etc/security/limits.conf <<DDD
* soft nofile 8192
* hard nofile 20480
DDD

cat >> /etc/sysctl.conf <<DDD
#set temp port range
net.ipv4.ip_local_port_range = 32768 61000
DDD

init 6

確認修改是否正確
複製代碼 代碼如下:

[root@sudutest ~]# ulimit -n
8192
[root@suduotest ~]# sysctl -n net.ipv4.ip_local_port_range
net.ipv4.ip_local_port_range = 32768 61000

添加squid專用賬戶
複製代碼 代碼如下:

groupadd squid
useradd -g squid -s /bin/false -M squid

添加日誌目錄、設定緩衝和日誌目錄的許可權
複製代碼 代碼如下:

mkdir /data/squidlog/
chown -R squid.squid /data

然後上傳或者wget squid3.0軟體tar包,tar zxvf解壓,並且進入解壓後的目錄安裝編譯
複製代碼 代碼如下:

./configure –prefix=/usr/local/squid3 –enable-async-io=100 –with-pthreads –enable-storeio="aufs,diskd,ufs" –enable-removal-policies="heap,lru" –enable-icmp –enable-delay-pools –enable-useragent-log –enable-referer-log –enable-kill-parent-hack –enable-arp-acl –enable-default-err-language=Simplify_Chinese –enable-err-languages="Simplify_Chinese English" –disable-poll –disable-wccp –disable-wccpv2 –disable-ident-lookups –disable-internal-dns –enable-basic-auth-helpers="NCSA" –enable-stacktrace –with-large-files –disable-mempools –with-filedescriptors=65535 –enable-ssl –enable-x-accelerator-var
make
make install
make install-pinger

至此squid已經成功安裝了,然後大家自己所需的/usr/local/squid3/etc/squid.conf 設定檔,我這邊的設定檔將會在本文末尾貼出來供大家研究。

寫好設定檔後執行下面的命令初始化cache目錄
/usr/local/squid3/sbin/squid -z
然後運行squid,註:-D參數用來跳過DNS檢測
/usr/local/squid3/sbin/squid -D
最後設定squid開機自動啟動
echo "/usr/local/squid3/sbin/squid -D " >>/etc/rc.local
維護篇:

以下是squid常用的命令
如果修改過設定檔,則用下面的命令重讀設定檔(即時生效)
/usr/local/squid3/sbin/squid -k reconfigure
檢查設定檔配置的文法是否正確
註:只有像這樣的“cache_cf.cc(346) squid.conf:14 unrecognized: 'http1_port'”才是語法錯誤,
“WARNING: use of 'reload-into-ims'……”這類提示屬於意見建議,可以忽略。
/usr/local/squid3/sbin/squid -k parse
查看squid的日誌和進程,看squid運行是否正常
複製代碼 代碼如下:

ps -ef |awk '/^squid/'
cat /data/squidlog/cache.log
/usr/local/squid3/sbin/squid -k check ;echo $?

關閉squid
發出關閉訊號,等會話結束後徹底關閉
/usr/local/squid3/sbin/squid -k shutdown
關閉squid(更高優先順序,直接關閉squid)
/usr/local/squid3/sbin/squid -k interrupt

關閉squid(最高優先順序,直接殺死squid進程)
/usr/local/squid3/sbin/squid -k kill
滾動記錄檔
/usr/local/squid3/sbin/squid -k rotate
設定每周二淩晨四點30分自動滾動日誌


echo "30 4 * * 2 root /usr/local/squid3/sbin/squid -k rotate " >>/etc/crontab

目前應用中的squid.conf檔案,由於記錄檔增長很快,所以直接輸出到/dev/null丟棄掉了
複製代碼 代碼如下:

#basic
cache_effective_user squid
cache_effective_group squid
pid_filename /usr/local/squid3/var/logs/squid.pid
visible_hostname squid.678114.com
cache_mgr sudu@sudu.us
error_directory /usr/local/squid3/share/errors/Simplify_Chinese
icon_directory /usr/local/squid3/share/icons
mime_table /usr/local/squid3/etc/mime.conf
hosts_file /etc/hosts

acl DEIpadd dstdom_regex [0-9]$
http_access deny DEIpadd

cache_replacement_policy lru
memory_replacement_policy lru

http_port 80 vhost vport

cache_mem 4024 MB
maximum_object_size_in_memory 5120 KB

icp_port 0

#.cache_dir
cache_dir aufs /data/cache 50000 64 128

max_open_disk_fds 0
maximum_object_size 20 MB

#.cache_peer
cache_peer 125.76.225.44 parent 80 0 no-query originserver no-digest name=all
cache_peer_domain all .678114.com

#acl
acl Safe_ports port 80
acl SSL_ports port 443
acl LanSrc src 192.168.100.0/24
acl webdomain dstdomain .678114.com
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow LanSrc
http_access allow webdomain
http_access deny all

#refresh_pattern
refresh_pattern -i /$ 15 90% 600 reload-into-ims
refresh_pattern -i .html$ 15 90% 600 reload-into-ims
refresh_pattern -i .htm$ 15 90% 600 reload-into-ims
refresh_pattern -i .shtml$ 15 90% 600 reload-into-ims
refresh_pattern -i .hml$ 15 90% 600 reload-into-ims
refresh_pattern -i .gif$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .swf$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .jpg$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .png$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .bmp$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .js$ 120 90% 129600 reload-into-ims
refresh_pattern -i .css$ 120 90% 129600 reload-into-ims
refresh_pattern -i .wma$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .zip$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .mp3$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .rar$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .rm$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .flv$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .rar$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .rm$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .avi$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .3gp$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .mp4$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .wmv$ 1440 90% 21600 reload-into-ims

#keepalived
client_persistent_connections off
server_persistent_connections on

#log
emulate_httpd_log on
logformat web1 %{X-Forwarded-For}>h %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
cache_log /data/squidlog/cache.log
cache_access_log /dev/null web1
cache_store_log /dev/null
strip_query_terms off
logfile_rotate 10

#other
forwarded_for on
log_icp_queries off
via off
httpd_suppress_version_string off
ie_refresh off
tcp_recv_bufsize 32 KB
ipcache_size 1024
ipcache_low 90
ipcache_high 95
cache_swap_low 80
cache_swap_high 90
request_header_max_size 128 KB

quick_abort_min 20 KB
quick_abort_max 20 KB
quick_abort_pct 95

connect_timeout 1 minute
negative_ttl 0 minutes

read_timeout 30 seconds
pconn_timeout 120 seconds
half_closed_clients off
client_lifetime 10 minutes
shutdown_lifetime 5 seconds

hierarchy_stoplist cgi-bin ?
access_log /dev/null squid

本文首發於http://www.sudu.us/simple-to-install-squid-3-0-reverse-proxy-configuration/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.