CentOS 6.5下Squid代理服務器的安裝與配置

一、系統環境

操作系統:CentOS release 6.5 

Squid版本:squid-3.1.10-20.el6_5.3.x86_64

SELINUX=disabled

HTTP Service: stoped

二、安裝Squid服務

2.1 檢查squid軟件是否安裝

# rpm -qa|grep squid

2.2 如果未安裝,則使用yum 方式安裝

# yum -y install squid

2.3 設置開機自啓動

# chkconfig --level 35 squid on             //在3、5級別上自動運行squid服務

三、squid服務器的配置文件說明

squid 的主配置文件是 /etc/squid/squid.conf,所有squid的設定都是在這個文件裏配置

http_port 3128      //設置監聽的IP與端口號
cache_mem 64 MB      //額外提供給squid使用的內存,squid的內存總佔用爲 X * 10+15+“cache_mem”,其中X爲squid的cache佔用的容量(以GB爲單位),
               //比如下面的cache大小是100M,即0.1GB,則內存總佔用爲0.1*10+15+64=80M,推薦大小爲物理內存的1/3-1/2或更多。              
maximum_object_size 4 MB   //設置squid磁盤緩存最大文件,超過4M的文件不保存到硬盤
minimum_object_size 0 KB   //設置squid磁盤緩存最小文件
maximum_object_size_in_memory 4096 KB   //設置squid內存緩存最大文件,超過4M的文件不保存到內存
cache_dir ufs /var/spool/squid 100 16 256   //定義squid的cache存放路徑 、cache目錄容量(單位M)、一級緩存目錄數量、二級緩存目錄數量
logformat combined %&gt;a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}&gt;h" %Ss:%Sh        //log文件日誌格式
access_log /var/log/squid/access.log combined  //log文件存放路徑和日誌格式
cache_log /var/log/squid/cache.log   //設置緩存日誌
logfile_rotate 60   //log輪循 60天
cache_swap_high 95  //cache目錄使用量大於95%時,開始清理舊的
cache
cache_swap_low 90   //cache目錄清理到90%時停止。
acl localnet src 192.168.1.0/24  //定義本地網段
http_access allow localnet  //允許本地網段使用
http_access deny all  //拒絕所有
visible_hostname squid.david.dev  //主機名
cache_mgr [email protected]  //管理員郵箱


四、普通代理服務

4.1 編輯squid 主配置文件/etc/squid/squid.conf


#

# Recommended minimum configuration:

#

acl manager proto cache_object

acl localhost src 127.0.0.1/32 ::1

acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1

# Example rule allowing access from your local networks.

# Adapt to list your (internal) IP networks from where browsing

# should be allowed

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 localnet src fc00::/7       # RFC 4193 local private network range

acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines

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

#

# Recommended minimum Access Permission configuration:

#

# Only allow cachemgr access from localhost

http_access allow manager localhost

http_access deny manager

# Deny requests to certain unsafe ports

http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports

http_access deny CONNECT !SSL_ports

# We strongly recommend the following be uncommented to protect innocent

# web applications running on the proxy server who think the only

# one who can access services on "localhost" is a local user

#http_access deny to_localhost

#

# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS

#

# Example rule allowing access from your local networks.

# Adapt localnet in the ACL section to list your (internal) IP networks

# from where browsing should be allowed

http_access allow localnet

http_access allow localhost

# And finally deny all other access to this proxy

http_access allow all

# Squid normally listens to port 3128

http_port 3128

# We recommend you to use at least the following line.

hierarchy_stoplist cgi-bin ?

cache_mem 512 MB

# Uncomment and adjust the following to add a disk cache directory.

cache_dir ufs /var/spool/squid 20480 16 256

cache_log /var/log/squid/cache.log

cache_access_log /var/log/squid/access.log

cache_store_log /var/log/squid/store.log

visible_hostname 192.168.3.34

cache_mgr [email protected]

# Leave coredumps in the first cache dir

coredump_dir /var/spool/squid

# Add any of your own refresh_pattern entries above these.

refresh_pattern ^ftp:           1440    20%     10080

refresh_pattern ^gopher:        1440    0%      1440

refresh_pattern -i (/cgi-bin/|\?) 0     0%      0

refresh_pattern .               0       20%     4320

4.2 初始化

# squid –z

4.3 防火牆配置

用編輯器打開/etc/sysconfig/iptables ,添加開放端口

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3128 -j ACCEPT

[root@localhost ~]# service iptables restart

4.4 啓動Squid

# /etc/init.d/squid start


五、在路由器中映射本機IP至端口的固定IP,測試代理服務



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章