2015年4月11日土曜日

キャッシュサーバとownCloudサーバをRaspberryPi2に移行する-IPv6対応(5)

■Squid3のインストール


 現在のバージョンは3.1.20。
$ sudo apt-get install squid3

 初期設定を確認するなら
$ cat /etc/privoxy/config | grep -v ^#

 そして設定。
$ sudo nano /etc/squid3/squid.conf

 設定ファイルが超長い!!ので、公式のminimum settingを手直しして、ファイルを1から作ったほうがいいかも。
 ウチの設定はこんな感じ。
http_port [port of Squid3]
htcp_port 0
icp_port 0
cache_peer localhost parent [port of Ziproxy] 0 no-query no-digest no-netdb-exchange
cache_mem 64 MB
cache_dir ufs /var/spool/squid3 1024 16 256
maximum_object_size 32 MB
maximum_object_size_in_memory 64 KB
refresh_pattern ftp: 1440 20% 10080
refresh_pattern gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
hierarchy_stoplist cgi-bin ?
half_closed_clients off
negative_ttl 1 minutes
pipeline_prefetch on
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl localnet src 192.168.x.0/24 # RFC 1918 possible internal network
acl to_ipv6 dst ipv6
acl winupdate dstdomain .microsoft.com .windowsupdate.com
acl manager url_regex -i ^cache_object:// +i ^https?://[^/]+/squid-internal-mgr/
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
http_access deny to_ipv6 !all
http_access allow manager localhost
http_access deny manager
http_access allow winupdate
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access allow localnet
http_access deny all
tcp_outgoing_address [RPi2-IPAddr.] !to_ipv6
tcp_outgoing_address [RPi2-IPv6-Addr.] to_ipv6

 IPv6化のための設定をして、他に少し盛り込んである感じ。
 詳しいことは公式faqを参照。
 設定したら再起動。
$ sudo /etc/init.d/squid3 restart

■Privoxyのインストール


 現在のバージョンは3.0.19。
$ sudo apt-get install privoxy

 そして設定。
$ sudo nano /etc/privoxy/config
user-manual /usr/share/doc/privoxy/user-manual
confdir /etc/privoxy
logdir /var/log/privoxy
actionsfile match-all.action
actionsfile default.action
actionsfile user.action
filterfile default.filter
filterfile user.filter
logfile logfile
listen-address  :[port of Privoxy]
toggle 1
enable-remote-toggle 1
enable-remote-http-toggle 1
enable-edit-actions 1
enforce-blocks 0
permit-access 192.168.x.0/24
buffer-limit 8192
forward / localhost:[port of Squid3]
forwarded-connect-retries  0
accept-intercepted-requests 0
allow-cgi-request-crunching 0
split-large-forms 0
keep-alive-timeout 5
socket-timeout 300

 フィルタ内容は割と頻繁に変えると思うので、WebGUIは殺さずに残しておいた。
 フィルタ内容は「/etc/privoxy/user.action」を直接書いてもいいし、プロキシを通す設定をしたブラウザから「http://p.p/」で現れるPrivoxyのWebUIから設定しても良い。
$ sudo /etc/init.d/privoxy restart

 ウチの場合はWebGUIからmatch-all.actionを編集し、「Set to Cautious」で設定しておいた。
 GIF de-animation?NO!NO!NOooo!
 match-all.actionの設定についてはマニュアルを参照

 user.actionのフィルタは各自で適宜設定する。
 自分の場合は、Android上でFilterProxyを使っていたので、その設定を流用した。

■Muninのインストール


 RPi2を監視できるよう、ついにで入れておく。バージョンは2.0.6。
 以下のページを参考に、OwncloudPieでインストールされたnginxでMuninが参照できるように設定した。

- mk-mode BLOG
Debian 7 Wheezy - サーバ監視ツール munin 導入!

 ウチでは一週間使用して、500MB~700MBで安定して推移している。

■それ以外の設定


 カーネルパラメータの設定とかしてみるといいかもしれない。
 ネットワーク環境がジャンボフレームに対応してるなら、MTUを変えてみてもいいんじゃないだろうか。
(ウチはルータにヤマハのRTX810を使っているため、ジャンボフレーム化はしていない)

 せっかくdnsmasqで宅内DNSキャッシュサーバを立てたのに、IPv6優先設定をしたWindows機だと、先にIPv6を使って、IPv6のDHCP元のISPのDNSに問い合わせてしまって、宅内DNSを使ってくれないのが残念。
 まぁサーバ内部で使う機会が一番多いからいいんですけどね…。

■結果


 Squidのログを確認したところ、SquidからZiproxyに接続できない場合があるため、原因を調査したところ、ZiproxyはIPv6に対応していないことが判明。
 どうやらIPv6アドレスをリクエストした時にZiproxyに接続できず、Squidが直接リクエストを処理していたため気づかなかった模様。
 解決法は以下の2通り。

  1. Squid→Polipoにプロキシをバイパスする(Ziproxyを諦め、IPv6に対応する)
  2. 「/etc/modules」のIPv6モジュールを削除して、PolipoをIPv4対応に戻して不貞寝(IPv6を諦める)

さあ!不貞寝の時間だ!
(2.を選んだ模様)

1 件のコメント: