| 3.1 ソフトの入手 |
3.1.1 tarボール
2002年5月1日時点での最新安定版である、 "squid-2.4.STABLE6-src.tar.gz"を入手します。例えば以下のサイトから入手できます:http://www.squid-cache.org/
3.1.2 rpmパッケージ

ftp://ftp.riken.go.jp/pub/Linux/redhat/redhat/linux/updates/7.2/en/os/SRPMS/squid-2.4.STABLE3-1.7.2.src.rpm
| 3.2 インストール |
3.2.1 tarボールからのインストール
ファイルを展開するディレクトリ$Workに移動して、バイナリパッケージを展開します。作業ディレクトリ$Workは任意のディレクトリです。 パッケージの展開後、作成されたディレクトリに移動します。

--enable-poll
--enable-snmp
--enable-removal-policies="heap,lru"
--enable-storeio="aufs,coss,diskd,ufs"
--enable-delay-pools
--enable-linux-netfilter
--enable-carp
--with-pthreads
--enable-auth-modules="LDAP,NCSA,PAM,SMB,MSNT"
|
3.2.2 rpmソースコードパッケージのインストール

| 3.3 コンフィギュレーション |
3.3.1 一般的な設定
squidが起動時に参照する"squid.conf"ファイルを設定します。
ここでディレクトリ"/etc/squid"は、configure実行時に"--sysconfdir"で指定したものです。(configure実行時に"--prefix"のみ設定した場合には、prefixで指定したディレクトリ下のサブディレクトリ"etc"以下にあります。)
ここではRedHatに準拠した設定を採用することにします。
| オプション | 設定値 | 備考 |
| cache_dir | ufs /var/spool/squid 100 16 256 | キャッシュを置くディレクトリ |
| cache_access_log | /var/log/squid/access.log | _ |
| cache_log | /var/log/squid/cache.log | _ |
| cache_store_log | /var/log/squid/store.log | _ |
| pid_filename | /var/run/squid.pid | _ |
| authenticate_program | /usr/bin/ncsa_auth /usr/etc/passwd | _ |
| http_access | allow localhost | _ |
| cache_effective_user | squid | _ |
| cache_effective_group | squid | _ |
| icon_directory | /usr/lib/squid/icons | _ |
| ftp_user | squid@mydomain.mynet | 各自の環境に合わせて設定 |
3.3.2 Cacheの階層化
squidの特徴として、cacheを階層化して一種の分散Cacheを構築できることが挙げられます。
簡単な例: 親となるsquidサーバと数台の子squidサーバがあり、 ユーザのクライアントマシンから子サーバにアクセスするように設定します。 子サーバはまず自分のCache領域を調べて要求されたデータが存在すればCache領域のデータを返し、 無ければ親サーバにアクセスします。
いくつかの子サーバがある場合、親サーバが子サーバ同士のキャッシングを行なうことができるので、 サイトのヒット率が向上します。
注意: "http_port"で設定されているポートは、クライアントや他のsquidサーバがアクセスするために使います。
"icp_port"で設定されているポートは、squid同士がCache情報を交換する時に使います。
タイプ: タイプには、
・parent
・sibling
・multcast
があります。今回は親子関係を結ぶので"parent"を指定します。
cache_host 192.168.1.1 parent 3128 3130 |
| 3.4 運用 |
3.4.1 tarボールによるインストールを行った場合
インストール後、起動する前にキャッシュを準備しなければなりません。
以下の手順でキャッシュ領域を確保して下さい。
この操作はインストール後、一度だけ行ないます。
SqServ="/usr/sbin/squid"
SqPid="/var/run/squid.pid"
SqConf="/etc/squid/squid.conf"
if [ -x $SqServ ] ; then
echo "Running proxy server..."
$SqServ -f $SqConf -D
fi
|

#!/bin/bash
# squid This shell script takes care of starting and stopping
# Squid Internet Object Cache
#
# chkconfig: - 90 25
# description: Squid - Internet Object Cache. Internet object caching is \
# a way to store requested Internet objects (i.e., data available \
# via the HTTP, FTP, and gopher protocols) on a system closer to the \
# requesting site than to the source. Web browsers can then use the \
# local Squid cache as a proxy HTTP server, reducing access time as \
# well as bandwidth consumption.
# pidfile: /var/run/squid.pid
# config: /etc/squid/squid.conf
PATH=/usr/bin:/sbin:/bin:/usr/sbin
export PATH
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
# check if the squid conf file is present
[ -f /etc/squid/squid.conf ] || exit 0
if [ -f /etc/sysconfig/squid ]; then
. /etc/sysconfig/squid
else
SQUID_OPTS="-D"
SQUID_SHUTDOWN_TIMEOUT=100
fi
# determine the name of the squid binary
[ -f /usr/sbin/squid ] && SQUID=squid
[ -z "$SQUID" ] && exit 0
prog="$SQUID"
# determine which one is the cache_swap directory
CACHE_SWAP=`sed -e 's/#.*//g' /etc/squid/squid.conf | \
grep cache_dir | awk '{ print $3 }'`
[ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/spool/squid
RETVAL=0
start() {
for adir in $CACHE_SWAP; do
if [ ! -d $adir/00 ]; then
echo -n "init_cache_dir $adir... "
$SQUID -z -F 2>/dev/null
fi
done
echo -n $"Starting $prog: "
$SQUID $SQUID_OPTS 2> /dev/null &
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SQUID
[ $RETVAL -eq 0 ] && echo_success
[ $RETVAL -ne 0 ] && echo_failure
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
$SQUID -k check >/dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
$SQUID -k shutdown &
rm -f /var/lock/subsys/$SQUID
timeout=0
while : ; do
[ -f /var/run/squid.pid ] || break
if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
echo
return 1
fi
sleep 2 && echo -n "."
timeout=$((timeout+2))
done
echo_success
echo
else
echo_failure
echo
fi
return $RETVAL
}
reload() {
$SQUID $SQUID_OPTS -k reconfigure
}
restart() {
stop
start
}
condrestart() {
[ -e /var/lock/subsys/squid ] && restart || :
}
rhstatus() {
status $SQUID
$SQUID -k check
}
probe() {
return 0
}
case "$1" in
start)
start
stop)
stop
reload)
reload
restart)
restart
condrestart)
condrestart
status)
rhstatus
probe)
exit 0
*)
echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
exit 1
esac
exit $?
|
SqServ="/usr/sbin/squid"
SqPid="/var/run/squid.pid"
if [ -n $SqPid ] ; then
kill `cat $SqPid`
echo "Stoped proxy server..."
fi
|

3.4.2 rpmのソースパッケージによるインストールを行った場合

他のアプリケーションと同様、以下のコマンドを実行することで、squidを起動することができます。
他のアプリケーションと同様、以下のコマンドを実行することで、squidを停止することができます。
| 3.5 クライアント側の設定 |
home |index |previous |next |contents