Ubuntuを利用していく上で、
preloadの利用
第8回で紹介したpreloadも一種のキャッシュです。詳細な使い方は第8回を参照してください。
DNSのキャッシュ――dnsmasqを使う
Webブラウザなどを用いてインターネットアクセスを行う場合、
ローカルでdnsmasqというDNSサーバを稼働させることで、
ただし、
dnsmasqのインストール
今回紹介するdnsmasqは、
dnsmasqのインストールは次のように行います。まずパッケージをインストールしましょう。
$ sudo apt-get install dnsmasq
dnsmasqは他のPCから参照することもできますが、
--- /etc/dnsmasq.conf.orig
+++ /etc/dnsmasq.conf
@@ -87,7 +87,7 @@
#except-interface=
# Or which to listen on by address (remember to include 127.0.0.1 if
# you use this.)
-#listen-address=127.0.0.1
+listen-address=127.0.0.1
# If you want dnsmasq to provide only DNS service on an interface,
# configure it as shown above, and then use the following line to
# disable DHCP on it.
設定ファイルを修正したら、
なお、
$ sudo /etc/init.d/dnsmasq restart * Restarting DNS forwarder and DHCP server dnsmasq ...done.
dnsmasqが正しく動作していることを確認するため、
$ dig @127.0.0.1 example.com
resolv.conf/dhclient.confの設定
このままでは通常の名前解決にはdnsmasqは利用されませんので、
nameserver 127.0.0.1
nameserver 208.77.188.166
これでシステムが利用するDNSサーバとして127.
$ dig | grep 127.0.0.1 ;; SERVER: 127.0.0.1#53(127.0.0.1)
また、
これでは非常に使いにくいので、
/etc/
DNSキャッシュのクリア
dnsmasqを利用している場合、
そのような場合は、
$ sudo /etc/init.d/dnsmasq force-reload
Apache2を利用したcache proxy
DNSキャッシュサーバに続けて、
HTTPプロクシサーバには様々な実装が存在しますが、
なお、
プロクシサーバとしてのApacheのインストール
Apache2.
以下のようにインストールしてください。
$ sudo apt-get install apache2 $ for i in proxy proxy_http proxy_ftp proxy_connect cache disk_cache mem_cache; do sudo a2enmod $i ; done $ sudo /etc/init.d/apache2 force-reload
このままでは意味もなく外部から接続できてしまいますので、
Listen 127.0.0.1:80
<IfModule mod_ssl.c>
Listen 127.0.0.1:443
</IfModule>
この状態でApacheをリスタートします。
$ sudo /etc/init.d/apache2 restart
Apacheが正しくローカルホストからのみの接続をListenしているかをチェックしましょう。以下のコマンドを利用します。以下のように、
$ sudo lsof -i | grep apache apache2 11835 root 3u IPv4 68519 TCP localhost:www (LISTEN) apache2 11840 www-data 3u IPv4 68519 TCP localhost:www (LISTEN) apache2 11858 www-data 3u IPv4 68519 TCP localhost:www (LISTEN)
ここまでの設定が終了したら、
--- proxy.conf.orig
+++ proxy.conf
@@ -2,19 +2,18 @@
#turning ProxyRequests on and allowing proxying from all may allow
#spammers to use your proxy to send email.
- ProxyRequests Off
+ ProxyRequests On
<Proxy *>
AddDefaultCharset off
Order deny,allow
Deny from all
- #Allow from .example.com
+ Allow from 127.0.0.1
</Proxy>
# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block
- ProxyVia On
+ ProxyVia Off
</IfModule>
修正したら、
$ sudo /etc/init.d/apache2 force-reload
これでプロクシサーバの準備ができました。Firefoxの設定を変更しましょう。
キャッシュの制限
Apache2のディスクキャッシュは、
上記の設定を行った時点で
デフォルトではキャッシュが300MB以下になるように動作します。このキャッシュの増減は、