squidの最新版の入手は以下のサイトから可能。
ftp://squid.nlanr.net/pub/
また、各ミラーサイトも以下の通り。
http://squid.nlanr.net/mirrors.html
これらのうちどこからか、squidのソースをダウンロードする。
また、ここでは、/usr/src 配下に展開する。
tar zxfv squid-2.2.STABLE5-src.tar.gz
とすると、解凍と同時に./squid-2.2.STABLE5 というディレクトリが作成される。
その後以下のコマンドを実行。
./configure --prefix=/usr/loca/squid
make all
make install
一行目で、--prefix を使ってインストール先を指定しているが、
実はデフォルトで、/usr/local/squid にインストールされるようになっているので、
特に変更の必要がないときは、./configureとするだけで構わない。
これで、/usr/local/squid にsquidがインストールされる。
基本的に設定ファイルは /usr/local/squid/etc/squid.conf だけ。
実際に設定を変更した(或いは環境によって変更すべき) 項目は以下の通り。
------------------------------------------------------------------
# TAG: http_port
# The port number where Squid will listen for HTTP client
# requests. Default is 3128, for httpd-accel mode use port 80.
# May be overridden with -a on the command line.
#
# You may specify multiple ports here, but they MUST all be on
# a single line.
#
http_port 3128
# TAG: icp_port
# The port number where Squid sends and receives ICP requests to
# and from neighbor caches. Default is 3130. To disable use
# "0". May be overridden with -u on the command line.
#
icp_port 3130
# TAG: cache_mem (bytes)
#
cache_mem 8 MB
# TAG: cache_swap_low (percent, 0-100)
# TAG: cache_swap_high (percent, 0-100)
#
cache_swap_low 90
cache_swap_high 95
# TAG: maximum_object_size (bytes)
#
maximum_object_size 4096 KB
# TAG: cache_dir
#
cache_dir /usr/local/squid/cache 100 16 256
# TAG: cache_access_log
#
cache_access_log /usr/local/squid/logs/access.log
# TAG: cache_log
#
cache_log /usr/local/squid/logs/cache.log
# TAG: cache_store_log
#
cache_store_log /usr/local/squid/logs/store.log
# TAG: cache_swap_log
#
cache_swap_log /usr/local/squid/cache/cache_swap_log
# TAG: acl
#
acl all src 0.0.0.0/0.0.0.0
acl taka src 192.168.x.x
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl SSL_ports port 443 563
acl Safe_ports port 80 21 443 563 70 210 1025-65535
acl CONNECT method CONNECT
http_access deny all
http_access allow taka
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
icp_access allow all
miss_access allow all
# TAG: cache_effective_user
# TAG: cache_effective_group
#
cache_effective_user nobody
cache_effective_group nogroup
------------------------------------------------------------------
・・・じつは、デフォルトのままあまりいじってなかったりする。
squidの仕組みを深く理解しているのならともかく、
あまり下手に設定を変更するよりはそのままの方が安定するケースが多い。
- http_port 3128
- HTTPクライアントからの要求を受けるTCPポートの番号を指定する。
一般的に用いられるものには、80、8080、3128等がある。
- icp_port 3130
- 隣接するPROXYサーバーからICPを受け付けるUDPポートを指定する。
- cache_mem 8 MB
- 見たまま。キャッシュメモリの容量を指定。(MB単位)
- cache_swap_low 90
- cache_swap_high 95
- メモリ上にキャッシュされるデータの下限(上限)をパーセンテージで指定。
上限を越えると、chace_dir で指定されたディレクトリにキャッシュの書き出しを行い、
下限を下回るとディレクトリへの書き出しを止める。
- maximum_object_size 4096 KB
- これも見たまま。オブジェクトの最大サイズを指定する。
これ以上のオブジェクトはキャッシュされない。
- cache_dir /usr/local/squid/cache 100 16 256
- キャッシュディレクトリの指定。
それぞれの数値は左から、キャッシュディレクトリ(top)の容量、
./cache 配下に作るキャッシュディレクトリ(L1)の数、
更にその下に作成するディレクトリ(L2)の数を指定。
- cache_access_log /usr/local/squid/logs/access.log
- squidが受けた接続要求記録を保存するファイルの指定
- cache_log /usr/local/squid/logs/cache.log
- squidの状態を記録するファイルの指定
- cache_store_log /usr/local/squid/logs/store.log
- キャッシュの書き込み、削除を記録するファイルの指定
- cache_swap_log /usr/local/squid/cache/cache_swap_log
- キャッシュの状態を記録するファイルの指定
どこにどんなオブジェクトがキャッシュされているかを記録するファイル。
- acl all src 0.0.0.0/0.0.0.0
acl taka src 192.168.x.x
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl SSL_ports port 443 563
acl Safe_ports port 80 21 443 563 70 210 1025-65535
acl CONNECT method CONNECT
http_access deny all
http_access allow taka
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
icp_access allow all
miss_access allow all
- acl <acl_name> src <IPアドレス>/<ネットマスク>という書式では、
<acl_name> で指定された名前に、<IPアドレス>/<ネットマスク> で指定されたIPアドレスを送信元として割り当てる。
acl <acl_name> dst <IPアドレス>/<ネットマスク>
という書式では逆に送信先として割り当てる。
これら acl で設定した内容は http(icp、miss 等)_access allow(deny) で許可するか否かを指定する。
私の場合、ほぼデフォルトで使用している。
- cache_effective_user nobody
cache_effective_group nogroup- ここの設定はセキュリティ上重要な部分で、
squidをrootで起動した場合、UserIDとGroupIDをどの所有者・所有グループに変更するかを指定する。
デフォルトでは変更しないので、nobody、nogroupにしておくのがよいだろう。
これに伴い、logsやcacheディレクトリも所有者を変更する。
squidをインストールした時点ではキャッシュディレクトリというのが作成されていない。
squid.confでキャッシュディレクトリの設定を行うので当然といえば当然か。
squid.conf の編集が済んだら、
/usr/local/squid/bin/squid -z
として、キャッシュディレクトリを作る。
同時に、キャッシュディレクトリとログディレクトリの所有者も
cache_effective_user 及び、cache_effective_groupで指定したものに変更する。
/usr/local/squid/bin/squid &
とすることで、squidが起動する。
また、何らかの理由でDNSのテストを行いたくない場合などがあるときは、「-D」オプションを付加する。
/usr/local/squid/bin/squid -D &
といった具合に。
また、Linux起動と同時にサービスを開始したい場合は、rc.local に
/usr/local/squid/bin/squid &
という一行を追加する。
また、/usr/local/squid/bin/RunCache とすることでも同様のことができる。