よくわからないエンジニア

よく分からないエンジニア(無音鈴鹿)の日々の記録

よくわからないエンジニア

CentOS7 Squidのソースインストール

上半期に取得する予定だったLPIC level2がまだ取得出来ていない。これは問題である。
なによりもver4.0の期限が8月12日までである。
折角勉強した試験範囲が微妙に変わるのは、微妙に悔しい。無駄だらけの人生を過ごしてきたのに、自分に不利益な無駄が絡むと異様に気になるのは何故だろう。
そんなこんなで202の勉強を再開したのだが、プロキシサーバ Squidを全く触った事が無かったので、一ミリも頭に入ってこない。練習問題でもさっぱりだったので、とりあえず環境を用意して設定してみた。

目次

Squidの導入

とりあえず最新版を突っ込んでみます。

# cd /usr/local/src/
# wget ftp://ftp.meisei-u.ac.jp/mirror/www/squid/squid-3.5.26.tar.gz
# tar xvfz squid-3.5.26.tar.gz
# cd squid-3.5.26/
# ./configure --prefix=/usr/local/squid-3.5.26
# make
# make install
# cd /usr/local/
# ln -s squid-3.5.26 squid

起動スクリプトを置いておきます。CentOS7のyumで作られたsquid.serviceをソース用に変更します。

[Unit]
Description=Squid caching proxy
After=syslog.target network.target nss-lookup.target

[Service]
Type=forking
LimitNOFILE=16384
EnvironmentFile=/usr/local/squid/etc/squid
ExecStartPre=/usr/local/squid/libexec/cache_swap.sh
ExecStart=/usr/local/squid/sbin/squid $SQUID_OPTS -f $SQUID_CONF
ExecReload=/usr/local/squid/sbin/squid $SQUID_OPTS -k reconfigure -f $SQUID_CONF
ExecStop=/usr/local/squid/sbin/squid -k shutdown -f $SQUID_CONF
TimeoutSec=0

[Install]
WantedBy=multi-user.target

環境変数用のファイルも/usr/local/squid/etc/squidという名前で作っておきます。

# default squid options
SQUID_OPTS=""

# Time to wait for Squid to shut down when asked. Should not be necessary
# most of the time.
SQUID_SHUTDOWN_TIMEOUT=100

# default squid conf file
SQUID_CONF="/usr/local/squid/etc/squid.conf"

cache_dirをconfで定義している場合のシェルスクリプトも用意しておきます。

#!/bin/bash
if [ -f /usr/local/squid/etc/squid ]; then
        . /usr/local/squid/etc/squid
fi

SQUID_CONF=${SQUID_CONF:-"/usr/local/squid/etc/squid.conf"}

CACHE_SWAP=`sed -e 's/#.*//g' $SQUID_CONF | \
        grep cache_dir | awk '{ print $3 }'`

for adir in $CACHE_SWAP; do
        if [ ! -d $adir/00 ]; then
                echo -n "init_cache_dir $adir... "
                /usr/local/squid/sbin/squid -N -z -F -f $SQUID_CONF >> /var/log/squid/squid.out 2>&1
        fi
done

シェルスクリプトに実行権限を付与します。

# chmod u+x /usr/local/squid/libexec/cache_swap.sh

とりあえずconfすら見てませんが起動してみます。

#systemctl start squid

なんか起動しました。次回覚えていれば設定編をやっていきます。