Raspberry Pi 2 Model Bを購入

Raspberry Pi2を購入して、自宅サーバを構築したときのメモ

munin

ローカルリソースの状態をWEBからグラフで確認できるツール

# apt-get install munin

LAN内(192.168.0.0/24)からのアクセスを許可
[/etc/munin/apache.conf]

#       Allow from localhost 127.0.0.0/8 ::1
        Allow from localhost 127.0.0.0/8 ::1 192.168.0.0/24

監視するリソースに、ping結果を追加

# ln -s /usr/share/munin/plugins/ping_ /etc/munin/plugins/ping_www.google.co.jp
# service munin-node restart
# service munin restart

監視するリソースに、CPU温度を追加

[./cputemp]

#!/usr/bin/env perl

use strict;
my $cpu = `cat /sys/class/thermal/thermal_zone0/temp`;
$cpu = ($cpu / 1000) if $cpu;

if ($ARGV[0] eq "autoconf") {
        if ($cpu) {
                print "yes";
        } else {
                print "no";
        }
} elsif ($ARGV[0] eq "config") {
        print "graph_title CPU temperature\n";
        print "graph_vlabel Celsius\n";
        print "graph_category system\n";
        print "cputemp.warning 50\n";
        print "cputemp.critical 60\n";

        print "cputemp.label CPU_temp\n";
} else {
        print "cputemp.value $cpu";
}

cputempを移動してmuninを再起動

# chmod +x cputemp
# mv cputemp /usr/share/munin/plugins
# ln -s /usr/share/munin/plugins/cputemp /etc/munin/plugins/cputemp
# service munin-node restart
# service munin restart

muninの試験方法

# munin-run

参考

PPTP

外出先からWi-Fi利用時に、自宅にPPTPVPN接続すると盗聴対策が出来て、安心してネットを利用可能。
インターネット→PPPoEルータ→raspberry piの経路で接続。通常PPTPは外部向けWAN NIC(サブネット)と内部向けLAN NICが必要だが、WAN NICのみでも動作。

# apt-get install pptp

raspberry piは192.168.0.22の固定IPで運用。PPTP接続してきたクライアントには192.168.0.50〜59をアサイ
[/etc/pptpd.conf]

localip 192.168.0.22
remoteip 192.168.0.50-59

DHCPで払い出すDNSサーバはルータ(192.168.0.1)を指定
[/etc/ppp/pptpd-options]

ms-dns 192.168.0.1

[/etc/sysctl.conf]

net.ipv4.ip_forward=1

sysctl.confの設定内容を反映させて、iptablesを設定

# sysctl -p
# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# crontab -e
@reboot sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

[/etc/ppp/chap-secrets]

vpn_user_name     *       vpn_password   *

pptpdを再起動して新しい設定を反映

# service pptpd restart

ルータの設定でポート1723をraspberry piへ転送


参考

VNC

# apt-get install x11vnc

OS起動時にX11自動起動するように設定し、VNCサーバも自動起動するように設定。

起動するときは-neversharedを付けないと、vncセッションが浮いたときに後からvnc接続できなくなるので注意。

[.config/autostart/x11vnc.desktop]

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=X11VNC
Comment=
Exec=x11vnc -forever -display :0 -ultrafilexfer -nevershared
StartupNotify=false
Terminal=false
Hidden=false

パスワードをかけるときは x11vnc -storepasswdで設定して、x11vnc起動時に-usepwオプションを付与する。


参考

ssh rsa keyを使いパスワードなしでログイン

$ ssh-keygen
$ mv .ssh/id_rsa.pub .ssh/authorized_keys

[/etc/ssh/ssh_config]

   RSAAuthentication yes
   PubkeyAuthentication yes

sshdを再起動

# service ssh restart

  1. id_rsawinscpでローカルに転送
  2. Putty Key Generatorでid_rsaをLoadして「Save private key」でid.ppkとして保存
  3. Pagentでid.ppkを「Add Key」
  4. Puttyの設定(接続→SSH→認証)で「認証のためのプライベートキーファイル」にid.ppkを指定し、「Pagentを使って認証する」にチェック


参考

squid

透過Proxyを構築。X-Forwarded-ForとViaヘッダを付けないように設定変更し、接続にはパスワード認証をするように設定

# aptitude install squid
# htpasswd -bcp /etc/squid/passwd proxy_user proxy_password

[/etc/squid/squid.conf]

#http_port 3128
http_port 93128

# forwarded_for on
forwarded_for off

# via on
via off

#acl password proxy_auth REQUIRED
acl password proxy_auth REQUIRED

http_access allow password

auth_param digest program /usr/lib/squid/digest_pw_auth /etc/squid/passwd
auth_param digest children 5
auth_param digest realm Squid proxy-caching web server
auth_param digest nonce_garbage_interval 5 minutes
auth_param digest nonce_max_duration 30 minutes
auth_param digest nonce_max_count 50

squidを再起動

# service squid restart