RedHat Linux 9 安裝配置Squid

來源:互聯網
上載者:User

軟體環境:RedHat Linux 9
在Squid首頁www.squid-cache.org下載最新的Squid 2.5-STABLE5進行編譯。

步驟:
1.下載最新版本的源檔案 Squid-2.5.STABLE5.src.tar.gz 放置於/usr/local目錄下

2.登入作為root,執行下面的命令:
cd /usr/local


tar -zxvf Squid-2.5.STABLE5.src.tar.gz
產生解壓縮檔案Squid-2.5.STABLE5
進入Squid-2.5.STABLE5目錄進行編譯
#cd /usr/local/squid*
#./configure --prefix=/usr/local/squid 
#make
#make install


3.上面二步執行完畢,Squid整個程式應該被安裝在/usr/local/squid目錄下了,但仍需要做其餘的動作。

4.進入目錄/usr/local ,以root身份執行下面的命令,改變整個Squid目錄的所有者為school:school
#cd /usr/local
#chown -R school:school squid

5.修改squid.conf的配置資訊
#su school
$cd /usr/local/squid
$vi etc/squid.conf
http_port 8080
cache_peer 10.10.2.53 parent 6666 7 login=username:password default no-query
cache_mem 60 MB
cache_mgr zdysgs@zju.edu.cn
dns_nameservers 10.10.0.21
visible_hostname zdysgs.zju.edu.cn
cache_dir ufs /usr/local/squid/var/cache 500 16 256
http_access allow all
never_direct allow all
error_directory /usr/local/squid/share/errors/Simplify_Chinese
cache_swap_low 80
cache_swap_high 97這兩行是設定cache進行替換的閘值。當佔用到97%的cache後,cache中的內容將被清空20%

6.su作為school,進入/usr/local/squid/bin目錄,執行#squid -z 建立cache交換目錄
#su school
$cd /usr/local/squid/sbin
$./squid -z
$./squid
檢查squid是否正常啟動並執行命令
$netstat -ntl
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
以上資訊表示squid已經正常啟動
停止squid啟動並執行命令:
$usr/local/squid/sbin -k shutdown
到現在為止,該Proxy 伺服器已經可以正常使用,但是不具有使用者認證的功能,以下介紹了使用ncsa使用者認證功能的實現7.ncsa使用者認證的實現
ncsa是squid原始碼包內建的認證程式之一,下面我們以squid-2.5.STABLE5版本為例講述ncsa的安裝和配置。
1) 以school身份進入/usr/local/squid-2.5.STABLE5/helpers/basic_auth/NCSA目錄。 //修改檔案夾squid-2.5.STABLE5的所有者為school,chown -R school:school squid-2.5.STABLE5


% make
% make install
編譯成功後,會產生ncsa_auth的可執行檔。
2) 拷貝產生的執行檔案ncsa_auth到/usr/local/squid/bin目錄
cp ncsa_auth /usr/local/squid/bin
3) 修改squid.conf中的相關選項如下所示:
auth_param basic program /usr/local/squid/bin/ncsa_auth /usr/local/squid/etc/passwd
4) 定義相關的使用者類
acl auth_user proxy_auth username1 username2或者acl auth_user proxy_auth REQUIRED
注意,REQUIRED關鍵字指明了接收所有合法使用者的訪問。
5) 設定http_access
http_access allow auth_user
http_access deny all
6) 利用apache攜帶的工具軟體htpasswd在/usr/local/squid/etc下產生密碼檔案並添加相應的使用者資訊。一般說來,該密碼檔案每行包含
一個使用者的使用者資訊,即使用者名稱和密碼。
用htpasswd產生密碼檔案passwd並添加使用者bye。
htpasswd -c /usr/local/squid/etc/passwd bye
然後重新啟動squid,密碼認證已經生效 //再增加使用者的話,使用如下命令htpasswd /usr/local/squid/etc/passwd user(增加使用者參數-c不要了)


8.用戶端設定:ie->工具->internet選項->串連-> 區域網路設定-> Proxy 伺服器地址:10.71.65.110 連接埠:8080

9.備忘
·http_port:設定Squid監聽的連接埠,你最好設一個比較好記的連接埠號碼,以便在進行客戶機配置
時容易記住。我的機器上連接埠號碼設的是8080。預設為3128。
·cache_mem:設定Squid佔用的實體記憶體,根據我的經驗,cache_mem的大小不應超過你的服務
器實體記憶體的三分之一,否則將會影響機器的總體效能。
·maximum_object_size:設定Squid可以接收的最大對象的大小。Squid預設值為4M,我自己入
認為太大,你可以根據自己的需要進行設定。
·cache_dir:設定緩衝的位置、大小。一般看起來形式如下
cache_dir /usr/local/squid/cache 100 16 256
/usr/local/squid/cache代表緩衝的位置;
100代表緩衝最大為100M;16和256代表一級和二級目錄數。
·cache_effective_user:設定使用緩衝的有效使用者。預設為使用者nobody,如果你的系統中沒
有使用者nobody,最好建一個或以非root使用者運行Squid。
·error_directory:設定顯示錯誤資訊網頁目錄資訊。預設為英文/usr/local/squid/share/errors/English
如果想顯示中文的話,修改為/usr/local/squid/share/errors/Simplify_Chinese。
·限制同一使用者同時只在同一IP上使用
acl FOO max_user_ip 1
http_access deny FOO
authenticate_ip_ttl 2 hours //限制保持連線時間,超過該時間才能用其他ip上網
·顯示的是你client的內網IP
forwarded_for on|off
關閉此項將在訪問某些論壇時顯示的IP是unknown
如果開啟則顯示的是你client的內網IP
forwarded_for off
·如何限制使用squid 的同一個ip 的串連數
Q:如何限制使用squid 的同一個ip 的串連數?
A:修改squid.conf,以下兩句限制每ip不得超過10串連:
acl BadUser maxconn 10
http_access deny BadUser
client_db=on
//The maxconn ACL feature relies on Squids client database. This database keeps a small data structure in memory for each client IP address. If you have a lot of clients, this database may consume a significant amount of memory. You can disable the client database in the configuration file with the client_db directive. However, if you disable the client database, the maxconn ACL will no longer work

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.