Personal tools
You are here: Home サーバ設定 squid squid2.6基本設定
Document Actions

squid2.6基本設定

by tamohiko last modified 2008-11-04 18:26

squid2.6の基本的な設定方法です。

検証環境
CentOS release 5.2 (Final)
squid-2.6.STABLE6-5.el5_1.3

squidインストール

いつもどおりyumでお手軽にインストールしました。

# yum -y install squid
Loading "fastestmirror" plugin
Determining fastest mirrors
 * base: ftp.jaist.ac.jp
 * updates: ftp.jaist.ac.jp
 * addons: ftp.jaist.ac.jp
 * extras: ftp.jaist.ac.jp
base                      100% |=========================| 1.1 kB    00:00     
updates                   100% |=========================|  951 B    00:00     
primary.xml.gz            100% |=========================| 245 kB    00:00     
updates   : ################################################## 546/546
addons                    100% |=========================|  951 B    00:00     
extras                    100% |=========================| 1.1 kB    00:00     
primary.xml.gz            100% |=========================|  88 kB    00:00     
extras    : ################################################## 291/291
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package squid.i386 7:2.6.STABLE6-5.el5_1.3 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size 
=============================================================================
Installing:
 squid                   i386       7:2.6.STABLE6-5.el5_1.3  base              1.2 M

Transaction Summary
=============================================================================
Install      1 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 1.2 M
Downloading Packages:
(1/1): squid-2.6.STABLE6- 100% |=========================| 1.2 MB    00:03     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: squid                        ######################### [1/1] 

Installed: squid.i386 7:2.6.STABLE6-5.el5_1.3
Complete!

yumを使えば問題なくインストールは完了するはずです。:-)

squid基本設定

無事squidのインストールが完了しましたら、今度は設定ファイルであるsquid.confを編集します。
デフォルトの状態では、squidに接続できるクライアントは自分自身(localhost)のみとなっています。
ですので、他のクライアントからもsquidに接続出来るように設定する必要があります。

設定項目
http_port 3128 (待ち受けポート指定)
デフォルトは3128番ポートを使用
待ち受けポートを変更する場合のみ設定変更
acl (アクセスコントロール)
aclのタイプおよび、クライアントPCが属しているネットワークに名前をつけます。
今回のタイプはsrcを使用します。   
http_access
デフォルトの設定では、squidを使用できるのはlocalhostのみとなっています。 そこで、localhost以外のクライアントからもsquidを使用許可させる設定をする必要があります。   
acl書式
acl [acl名] [aclタイプ] [ネットワークアドレス]

参考までに、aclのタイプを記述しておきます。

タイプ説明
src クライアントIPアドレス
dstターゲットIPアドレス
srcdomainクライアントのドメイン名
dstdomainターゲットのドメイン名
urlURLパターン
urlpathRULパス
time日付と時間
portポート
protoプロトコル
methodHTTPメソッド
browserブラウザ
userユーザ
proxy_auth有効なユーザ
設定ファイル

yumでインストールを行った場合設定ファイルは「/etc/squid/squid.conf」にありますので、 まずはsquid.confのバックアップを行ってから編集を行います。

# cp -p /etc/squid/squid.conf /etc/squid/squid.conf_yyyymmdd
# vi /etc/squid/squid.conf
http_port設定

squid待ち受けポートのデフォルト設定は「3128」となっています。別のポート番号でクライアントに 接続させたい場合等は、設定変更を適宜設定変更を行ってください。

# Squid normally listens to port 3128
http_port 3128
acl追加

acl名「mynetwork」でクライアントPCのIPアドレスが192.168.0.0/24のネットワークであるaclを作成する例

#Recommended minimum configuration:
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https

acl mynetwork src 192.168.0.0/24 <--今回追加したacl
http_accessポリシー追加

上記で追加したacl「mynetwork」を使用して、http_accessのポリシーを追加します。

注意点

ポリシーはファーストマッチなのでかならず、squid.conf内のhttp_access deny all ポリシーより前に 記述してください。 そうしないと、先に deny all(全てを拒否)のポリシーがマッチして http_access allow mynetworkのポリシーは意味がなくなってしまいます。

# http_access deny all
#
#Recommended minimum configuration:
#
# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access allow mynetwork  <--今回追加したhttp_accessポリシー
http_access deny manager
# Deny requests to unknown ports
http_access deny !Safe_ports
# Deny CONNECT to other than SSL ports
http_access deny CONNECT !SSL_ports

###  中略  ###

# And finally deny all other access to this proxy
http_access allow localhost
http_access deny all

設定反映

squid.confの設定が完了しましたら、早速squidを起動させます。

/etc/init.d/squid start
squid を起動中:        [  OK  ]
起動出来ない場合・・・

起動出来ない場合は、「/var/log/messages」に何らかの情報が出力されていると思いますので 確認してみてください。

自動起動設定

自動起動設定確認

yumでインストールされたsquidは初期設定では自動起動の設定はされていないはずです。
chkconfig --list squid」 コマンドで設定状況を確認してみてください。

# chkconfig --list squid
squid    0:off   1:off   2:off   3:off   4:off   5:off   6:off
自動起動設定

chkconfigコマンドを使用して自動起動設定を「on」に設定します。
念のため自動起動設定後「chkconfig --list squid」 コマンドで設定状況を確認してみてください。
run level 2 3 4 5 で自動起動の設定が「on」に設定されていることが確認できます。

# chkconfig squid on
# chkconfig --list squid
squid     0:off   1:off   2:on    3:on    4:on    5:on    6:off

動作確認

全ての設定が完了しましたら、squidの動作確認を行います。
一番手っ取り早い方法は、クライアントのブラウザにproxyの設定をし実際にsquid経由で どこか適当なwebサイトにアクセスをしてみるのが簡単です。

ウェブブラウザがすぐに使用出来ない等で確認できない場合は、「squidclient」コマンドを使用することで、動作確認を行うことが出来ます。

squidclient書式
squidclient -h [squidサーバのIP] -p [ポート番号] [確認URL]

localhostのsquidをテストする場合は以下のように入力することで動作確認を行うことが出来ます。

# squidclient -h 127.0.0.1 -p 3128 http://www.yahoo.co.jp/
成功の場合

正常にsquid経由でアクセス出来た場合は、HTTPのレスポンスコードが「HTTP/1.0 200 OK」と表示されて html情報等が表示されます。

# squidclient -h 192.168.77.1 -p3128 http://www.google.co.jp/ 
HTTP/1.0 200 OK
Cache-Control: private, max-age=0
Date: Mon, 27 Oct 2008 07:33:44 GMT
Expires: -1
Content-Type: text/html; charset = Shift_JIS
Set-Cookie: PREF=ID=3f22573020f9b10f:TM=1225092824:LM=1225092824:S=QWrdSmj-UJCjR58-; expires=Wed, 27-Oct-2010 07:33:44 GMT; path=/; domain=.google.co.jp
Server: gws
X-Cache: MISS from www.example.jp
X-Cache-Lookup: MISS from www.example.jp:3128
Via: 1.0 www.example.jp:3128 (squid/2.6.STABLE6)

############# 以下省略 ############# 
失敗の場合

アクセスコントロールにて接続出来なかった場合の例

HTTPのレスポンスコードが「HTTP/1.0 403 Forbidden」と表示されてアクセス出来ない旨の メッセージが表示されます。

# squidclient -h 192.168.77.1 -p 3128 http://www.google.co.jp
HTTP/1.0 403 Forbidden
Server: squid/2.6.STABLE6
Date: Mon, 27 Oct 2008 07:18:40 GMT
Content-Type: text/html
Content-Length: 1050
Expires: Mon, 27 Oct 2008 07:18:40 GMT
X-Squid-Error: ERR_ACCESS_DENIED 0
X-Cache: MISS from www.example.jp
X-Cache-Lookup: NONE from www.example.jp:3128
Via: 1.0 www.example.jp:3128 (squid/2.6.STABLE6)
Proxy-Connection: close

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The requested URL could not be retrieved</TITLE>
<STYLE type="text/css"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE>
</HEAD><BODY>
<H1>ERROR</H1>
<H2>The requested URL could not be retrieved</H2>
<HR noshade size="1px">
<P>
While trying to retrieve the URL:
<A HREF="http://www.google.co.jp">http://www.google.co.jp</A>
<P>
The following error was encountered:
<UL>
<LI>
<STRONG>
Access Denied.
</STRONG>
<P>
Access control configuration prevents your request from
being allowed at this time.  Please contact your service provider if
you feel this is incorrect.
</UL>
<P>Your cache administrator is <A HREF="mailto:root">root</A>. 


<BR clear="all">
<HR noshade size="1px">
<ADDRESS>
Generated Mon, 27 Oct 2008 07:18:40 GMT by www.example.jp (squid/2.6.STABLE6)
</ADDRESS>
</BODY></HTML>

以上で、とりあえずsquidをプロキシサーバとして使用することができるようになります。
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: