歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> 如何在linux上用squid搭建代理服務器_足夠詳細

如何在linux上用squid搭建代理服務器_足夠詳細

日期:2017/3/1 14:05:27   编辑:關於Linux
如何在linux上用squid搭建代理服務器_足夠詳細 在linux上用squid搭建代理服務器,這個東東全世界都是,但是有一些細節問題在網上說的不明不白的,折騰了半天搞好了,如鲠在喉不吐不快。 一台電腦linux系統,上不了網,於是在另外一台可以上網的linux上面搭建一個代理服務器,步驟如下: 下載:squid-3.2.9.tar.bz2 上傳到服務器後解壓: 解壓: tar -vxjf squid-3.2.9.tar.bz2 解壓後生成目錄:squid-3.2.9 進入目錄翻看文檔INSTALL: xxxx> more INSTALL To build and install the Squid Cache, type: % ./configure --prefix=/usr/local/squid % make all % make install To run a Cache, you will need to: 1. customize the squid.conf configuration file: % vi /usr/local/squid/etc/squid.conf 2. Initalise the cache: % /usr/local/squid/sbin/squid -z 3. start the cache: % /usr/local/squid/sbin/squid If you want to use the WWW interface to the Cache Manager, copy the cachemgr.cgi program into your httpd server's cgi-bin directory. 安裝步驟: ./configure --prefix=/usr/local/squid make all sudo make install(因為要拷貝到系統目錄,需要root權限,所以sudo了,你也可以root登錄執行,我是ubuntu的系統,所以用sudo,有root權限就行) 檢查配置文件: sudo vi /usr/local/squid/etc/squid.conf 配置項1: # Squid normally listens to port 3128 http_port 3128 配置項2: acl localnet src 192.168.0.0/16 http_access allow localnet 配置項3: # Uncomment and adjust the following to add a disk cache directory. cache_dir ufs /usr/local/squid/var/cache/squid 100 16 128 cache_mem 32 MB (這一條必須配置) 否則你就會遭遇報錯: 2013/10/12 16:16:55 kid1| WARNING cache_mem is larger than total disk cache space! 安裝好了以後,系統中新建了一個用戶squid,在組中一查,發現屬於nobody組的: cat /etc/passwd|grep squid cat /etc/group|grep 65534 安裝squid的所在目錄是:/usr/local/squid 我閒得沒事干,直接改了所屬用戶為squid:nobody sudo chown -Rf squid:nobody /usr/local/squid 建立cache的時候,對下面目錄需要nobody用戶權限,這個是網上沒有說的很清楚的地方,折騰了我半天: sudo chown -Rf nobody /usr/local/squid/var/cache/ sudo chown -Rf nobody /usr/local/squid/var/logs/ 否則你會遭遇: WARNING: Cannot write log file: /usr/local/squid/var/logs/cache.log FATAL: Failed to make swap directory /usr/local/squid/var/cache/squid/00: (13) Permission denied 初始化squid.conf裡配置的cache目錄,就是建立了一堆的目錄: sudo /usr/local/squid/sbin/squid -z 在前台啟動squid,並輸出啟動過程 sudo /usr/local/squid/sbin/squid -N -d1 顯示ready to server reques,則啟動成功。可以鍵入ctrl+c,停止squid,並以後台運行的方式啟動。 我沒有在配置文件中配置DNS,而是在 /etc/resolv.conf 中配置: domain site nameserver x.x.x.x 所以打印出來的日志中就這樣的: 2013/10/12 16:42:13| Adding nameserver x.x.x.x from /etc/resolv.conf squid從這個配置文件中讀取了dns配置來用。 啟動squid後台運行 sudo /usr/local/squid/sbin/squid -s 檢查一下進程是否存在:ps -ef|grep squid 通過squid客戶端查看squid運行狀態 /usr/local/squid/bin/squidclient -h 127.0.0.1 -p 3128 mgr:info 那台不能上網的機器配置如下: export http_proxy=http://192.168.199.235:3128/ 可以把這句寫到你的啟動文件中,比如什麼.profile或者.bashrc,或者/etc/profile等等。 取消:unset http_proxy 測試一下能不能上網了: wget www.163.com 能down下來文件就大功告成了!
Copyright © Linux教程網 All Rights Reserved