人気ブログランキング | 話題のタグを見る

Metaphorical Dream

Squid その2

先日のBlogに書いたことを簡易的に試してみたw
SquidはSiblingで分散処理できるように設定してみる。

PC→DHCP→PC→www(pac取得)→PC→Squid→RT57i(予備機)→Internet上のwww

あとは、PC→Squid→RT57iにNS VPXを咬ませれば概ねOKかなと。

以下、備忘録。

[apache]
yum -y install httpd

vi /etc/httpd/conf/httpd.conf

#ServerName www.example.com:80
 ↓
ServerName squid01.md.jp:80

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
#AllowOverride None
 ↓
AllowOverride All  ← .htaccessの許可

#
#以下2つは不要かも?
#
AddDefaultCharset UTF-8
 ↓
#AddDefaultCharset UTF-8  ← コメントアウト

#AddHandler cgi-script .cgi
 ↓
AddHandler cgi-script .cgi .pl  ← CGIスクリプトに.plを追加

:wq

rm -f /etc/httpd/conf.d/welcome.conf
rm -f /var/www/error/noindex.html

/etc/rc.d/init.d/httpd start
chkconfig httpd on
chkconfig --list httpd


[.htpasswdの設定]
#
#ユーザ名:usr1
#Passwd:test
#
#ユーザ追加は -c無しで実行
#

htpasswd -b -c /etc/httpd/conf/.htpasswd usr1 test

cat /etc/httpd/conf/.htpasswd

/etc/rc.d/init.d/httpd restart


[dhcpd]
yum -y install dhcp

cp /usr/share/doc/dhcp-*/dhcpd.conf.sample /etc/dhcpd.conf

vi /etc/dhcpd.conf

ddns-update-style interim;
ignore client-updates;

#
#以下はOption252の設定
#
authoritative;
option wpad code 252 = string;
option wpad "http://192.168.12.147/proxy.pac";

#
#以下は普通のdhcpdの設定
#各項目の詳細説明は省略。っていうか見れば概ねわかるよね?
#

subnet 192.168.12.0 netmask 255.255.255.0 {

# --- default gateway
option routers192.168.12.7;
option subnet-mask255.255.255.0;

#option nis-domain"domain.org";
option domain-name"md.jp";
option domain-name-servers192.168.12.1;

option time-offset-18000;# Eastern Standard Time
#option ntp-servers192.168.1.1;
#option netbios-name-servers192.168.1.1;

range dynamic-bootp 192.168.12.128 192.168.12.159;
default-lease-time 21600;
max-lease-time 43200;

# we want the nameserver to appear at a fixed address

#host ns {
#next-server marvin.redhat.com;
#hardware ethernet 12:34:56:78:AB:CD;
#fixed-address 207.175.42.254;
#}

}

:wq

/etc/rc.d/init.d/dhcpd start
chkconfig dhcpd on
chkconfig --list dhcpd


[pacファイルの作成]
vi /var/www/html/proxy.pac

function FindProxyForURL(url,host)
{ if(isPlainHostName(host)||
isInNet(host,"192.168.12.0","255.255.0.0")) return "DIRECT";
else return "PROXY 192.168.12.7:8080; DIRECT";
}

#
#【上記スクリプトの説明】
#詳細はMS社IEAK8のヘルプなどを参照
#http://technet.microsoft.com/ja-jp/library/cc817437.aspx
#
#あて先URL=ホスト名のみ(「.」の文字を含まない名前)
# or
#あて先IP=192.168.12.0/24内
#であればDIRECTアクセス
#
#上記以外の場合はPROXYサーバ 192.168.12.7:8080を参照
#


[squid]
#★=追加
#▼=修正&変更

yum -y install squid

vi /etc/squid/squid.conf

(1)
# TAG: auth_param
#This is used to define parameters for the various authentication
#schemes supported by Squid.
#
#★1
#.htpasswdを利用する場合は以下のように設定
#基本はコメントアウトでOK
#以下を注意しないとSquidの起動で失敗する。
#x86の場合/usr/lib/squid/ncsa_auth
#x64の場合/usr/lib64/squid/ncsa_auth
#
#▼1
#コメントアウトのみでOK
#
#auth_param basic program

auth_param basic program /usr/lib64/squid/ncsa_auth /etc/httpd/conf/.htpasswd  ←★1
auth_param basic children 5  ←▼1コメントアウト
auth_param basic realm Squid proxy-caching web server  ←▼1コメントアウト
auth_param basic credentialsttl 2 hours  ←▼1コメントアウト


(2)
# TAG: acl
#Defining an Access List
#
#★2-1
#.htpasswdを利用する場合の設定(利用しない場合には不要)
#利用する場合は順番に注意!★2-2より下にすると認証掛からない
#
#★2-2
#192.168.12.0/255.255.255.0からプロキシサーバーへのアクセスを許可する
#
#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 Safe_ports port 70# gopher
acl Safe_ports port 210# wais
acl Safe_ports port 1025-65535# unregistered ports
acl Safe_ports port 280# http-mgmt
acl Safe_ports port 488# gss-http
acl Safe_ports port 591# filemaker
acl Safe_ports port 777# multiling http
acl CONNECT method CONNECT
acl password proxy_auth REQUIRED  ←★2-1
acl lan src 192.168.12.0/255.255.255.0  ←★2-2


(3)
# TAG: http_access
#Allowing or Denying access based on defined access lists
#
#★3-1
#.htpasswdを利用する場合の設定(利用しない場合には不要)
#利用する場合は順番に注意!★3-2より下にすると認証掛からない
#
#★3-2
#192.168.12.0/255.255.255.0からプロキシサーバーへのアクセスを許可する
#上記(2)の★2のACLをallowする設定です。
#注意「http_access deny all」よりも前の行で設定すること!
#CiscoのAccess-listと同様に上から順に読み取るので。
#
#Recommended minimum configuration:
#
# Only allow cachemgr access from localhost
http_access allow manager localhost
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 allow password  ←★3-1
http_access allow lan  ←★3-2
http_access deny all


(4)
#
# TAG: http_port
# Usage: port [options]
# hostname:port [options]
# 1.2.3.4:port [options]
#
#▼2
#Proxyサービスの待ちうけポートを変更
#Default=TCP3128をTCP8080に変更します。
#個人的にはICPとの絡みを考慮すると、TCP3128で良い気がするけど。
#
# Squid normally listens to port 3128
http_port 8080  ←▼2


(5)
#
# TAG: cache_peer
#
#★4
#Squid分散処理のため追加
#とりあえず、Squid1台のみで試すときは不要な設定。
#
#恐らく相手だけ追加すればOKなハズ(自分=.147、相手=.148とする)
#その他、sibling,Parent,MulticastやOptionについては、
#/etc/squid/squid.confに詳細が記載されている(英語だけどさッ)
#
#hostname=FQDNが定石なのでDNSへのlookupが必須
#でも、IPアドレス直打ちでもサービスは正常起動したw
#
# # proxy icp
# # hostname type port port options
# # -------------------- -------- ----- ----- -----------
# cache_peer parent.foo.net parent 3128 3130 proxy-only default
# cache_peer sib1.foo.net sibling 3128 3130 proxy-only
# cache_peer sib2.foo.net sibling 3128 3130 proxy-only
cache_peer192.168.12.147sibling80803130proxy-only  ←★4
cache_peer192.168.12.148sibling80803130proxy-only  ←★4


(6)
# TAG: header_access
# Usage: header_access header_name allow|deny [!]aclname ...
#
#★5
#以下を追加
#Proxy経由でアクセスしていることを相手先にわからないようにする。
#
#Default:
# none
header_access X-Forwarded-For deny all  ←★5
header_access Via deny all  ←★5
header_access Cache-Control deny all  ←★5


(7)
# TAG: visible_hostname
#
#★6
#以下を追加
#自サーバのFQDNを記載
#IPアドレス直打ちでもエラーは出ないw
#
#Squidのサービス起動時、以下のエラーの対処のため。
#[root@squid01 ~]# /etc/rc.d/init.d/squid start
#init_cache_dir /var/spool/squid...
#/etc/rc.d/init.d/squid: line 62: 3144 アボートしました$SQUID -z -F -D >> /var/log/squid/squid.out 2>&1
#/etc/rc.d/init.d/squid: line 42: 3145 アボートしました$SQUID $SQUID_OPTS >> /var/log/squid/squid.out 2>&1
#squid を起動中: [失敗]
#
#Default:
# none
visible_hostname squid01.md.jp  ←★6


(8)
# TAG: forwarded_for on|off
# If set, Squid will include your system's IP address or name
# in the HTTP requests it forwards. By default it looks like
# this:
#
#▼7
#Proxyを使用しているPCのLocalIPアドレスを隠蔽化する設定
#
#Default:
forwarded_for off  ←▼7

:wq

/etc/rc.d/init.d/squid start
chkconfig squid on
chkconfig --list squid

[動作確認]
いわずもがな?なので詳細は省略。
動作原理を理解していればわかるハズ。

ProxyサーバとクライアントPCで
netstatを叩けばわかる。

The Internetを閲覧するのであれば、
ProxyサーバはGlobalアドレスに対してSessionを張る。
クライアントPCはProxyサーバのみに対してSessionを張る。
別な言い方をすれば、
クライアントPCはGlobalアドレスに対してSessionを張らない。

もしくは、dhcpdの「option routers」で指定するGatewayアドレスを
ルータではなくProxyサーバに設定しても、
クライアントPCにてWeb閲覧できているのであれば、
それはProxy経由であることの証明です。
 ※
 前提としてDNSは別途LAN内で名前解決してくれる鯖が居ること。

by mdesign21 | 2010-05-16 16:34 | IT系