筆者について
FreeBSDを通じてOSSにささかな貢献を。
- 日本xrdpユーザ会発起人
- xrdp developer
- FreeBSD developer
OSS活動をご支援いただける方を募集しています
2009-05-02 Xmarks
■ Xmarks で自分のサーバを使う
Xmarks はFirefox のブックマークを同期し、複数の PC で同じブックマークを使えるようにする拡張機能です。
以前は Foxmarks という名前で、Xmarks と改名したタイミングでパスワードの同期機能なども追加されたようです。
パスワードの同期には暗号化のためのパスワードが必要で、生のデータは Xmarks のサーバには渡りません。しかし、暗号化されているとはいえパスワードを第三者に預けるのには不安があるので自分のサーバでブックマークとパスワードを同期させることにしました。
技術的には単に WebDAV をしているだけなので、Apache でサーバーを立ててやるだけです。
/usr/local/etc/apache22/extras/httpd-vhost.conf に以下の様に記述。
<VirtualHost *:80>
ServerAdmin meta@vmeta.jp
ServerName kephir.vmeta.jp
DocumentRoot "/usr/local/www"
ErrorLog "/home/meta/log/www-kephir/error_log"
CustomLog "/home/meta/log/www-kephir/access_log" combined
DavLockDB /var/tmp/DavLock
Alias /xmarks /home/meta/xmarks
<Location /xmarks>
Dav On
AuthType Digest
AuthName Xmarks
AuthUserFile /home/meta/xmarks/.htdigest
Require user meta
</Location>
</VirtualHost>
既に動作している Web サーバを設定する場合は WebDAV と認証関連の設定だけでOK。
認証用の .htdigest ファイルの作成も一緒に。
$ cd /home/meta/xmarks $ htdigest -c .htdigest Xmarks meta Adding password for meta in realm Xmarks. New password: Re-type new password:
WebDAV は Web サーバの権限でファイルの読み書きを行うので、適切に権限を設定しておく必要があります。 権限を設定したらブックマークとパスワードを記録するためのファイルを作成しておきます。
$ cd /home/meta/xmarks $ chown -R :www /home/meta/xmarks $ umask 007 $ touch bookmarks passwd
これで動くはずなので、あとは Xmarks 側を設定します。 詳細の自分のサーバの設定で、「自分のサーバを使う」にチェックを入れ、URL とパスワード URL のところに、さっき作成したファイルの URL をそれぞれ入力してやれば OK です。
2009-05-07 FreeBSD 7.2-RELEASE Available
■ cvsup-mirror でミラーサーバの構築
FreeBSD 7.2-RELEASE 出ました。リリース直後は freebsd-update サーバも cvsup サーバも混み合ってアップデートできない状態でした。
研究室や自宅やその他で FreeBSD マシンが増えてきたので、ローカルに1台 cvsup のミラーを構築してみました。
# cd /usr/ports/net/cvsup-mirror # make ===> Vulnerability check disabled, database not found ===> Extracting for cvsup-mirror-1.3_8 ===> Patching for cvsup-mirror-1.3_8 ===> Configuring for cvsup-mirror-1.3_8 I am going to ask you a few questions so that I can set up your FreeBSD mirror configuration. Every question has a [default] answer. To accept the default, just press ENTER. At this point, I am just gathering information. I will not touch your system until you type "make install". Master site for your updates [cvsup-master.freebsd.org]? cvsup2.jp.freebsd.org How many hours between updates of your files [1]? Now you must decide which sets of files you wish to make available from your mirror site. You can choose any combination, and you can put each set anywhere you want to on your disks. Although each set is optional, we strongly encourage every mirror site to carry at least the main source repository. Do you wish to mirror the main source repository [y]? Where would you like to put it [/home/ncvs]? Do you wish to mirror the installed World Wide Web data [y]? n Do you wish to mirror the GNATS bug tracking database [y]? n Do you wish to mirror the mailing list archive [y]? n Now, a few questions so that I can set up your CVSup server properly. For security reasons, both the CVSup client and server should run under their own unique user and group IDs. These IDs should have no special access privileges. Normally, the user:group "cvsupin:cvsupin" is used for the client and "cvsup:cvsup" is used for the server, but you can choose other names if you wish. At "make install" time, I will create the users and groups, if they don't already exist. Use unique user and group IDs for these. Do not use "nobody", "nonroot", or "nogroup". Unique unprivileged user ID for running the client [cvsupin]? Unique unprivileged group ID for running the client [cvsupin]? Unique unprivileged user ID for running the server [cvsup]? Unique unprivileged group ID for running the server [cvsup]? The CVSup server does its logging via syslog. At "make install" time, I will set up the logging for you, if necessary. I will use the "!program" feature of syslog to keep your CVSup log messages separate from the messages of your other daemons. Syslog facility for the server log [daemon]? You can control the load on your machine by limiting the number of clients that the CVSup server will serve at once. CVSup won't load your network especially heavily, but it is more CPU and disk intensive than most other file server software. Maximum simultaneous client connections [8]? Building the "config.sh" file ... Done. Building the "cvsupd.access" file ... Done. # make install
あとは /etc/rc.conf に
cvsupd_enable="YES"
とでも書いておきます。しばらく放っておくと cron で手元にミラーが構築されるので、
# /usr/local/etc/rc.d/cvsupd start
を実行して cvsupd を起動しておけばOKです。
cron で同期してくれるのを待つのではなく、すぐに同期を実行したい場合は
# /usr/local/etc/cvsup/update.sh
を実行します。シェルスクリプトの中を見るとわかりますが、フルパスで実行しないと動かないので注意が必要です。
これで構築したミラーサーバが cvsup.freebsd.vmeta.jp です。利用はご自由に。利用の際は supfile で compress を無効にするか、cvsup (csup) に -Z (大文字) オプションを付けて圧縮を無効にしてください。
2009-05-12 夏に向けて
■ net-snmp でハードディスクの温度を監視する
Linux では hddtemp や smartmontools でハードディスクの温度を取得することができますが、FreeBSD では smartmontools を使います。
ハードディスクが S.M.A.R.T. に対応していれば簡単です。
# portinstall smartmontools # smartctl -a /dev/ad4 | grep ^194 194 Temperature_Celsius 0x0022 039 042 000 Old_age Always - 39 (0 20 0 0)
この情報を net-snmp で取得できるようにします。
まずは hddtemp の -n オプションに相当する、ハードディスク温度の数値のみが出力されるようにする必要があります。適当に awk でも使って 数値のみを切り出し、これをシェルスクリプトにし /root/tools/get_hddtemp.sh として保存します。
複数のハードディスクがある場合のために、引数でハードディスクのデバイスファイルを与えるようにしました。
#!/bin/sh
/usr/local/sbin/smartctl -a $1 | /usr/bin/awk '{if($1=="194") print $10}'
これを実行するとこのようになります。
# /root/tools/get_hddtemp.sh /dev/ad4 41
net-snmp でこの情報を取得できるようにするため /usr/local/etc/snmp/snmpd.conf に次の1行を追加し、restart します。
extend ad4temp /root/tools/get_hddtemp.sh /dev/ad4
# /usr/local/etc/rc.d/snmpd restart
snmpwalk で試しに取ってみます。
$ snmpwalk -v 1 -c community localhost NET-SNMP-EXTEND-MIB::nsExtendOutLine NET-SNMP-EXTEND-MIB::nsExtendOutLine."ad4temp".1 = STRING: 41 NET-SNMP-EXTEND-MIB::nsExtendOutLine."echotest".1 = STRING: hello world
OID を取得するため、-On オプションをつけます。
$ snmpwalk -v 1 -c community localhost NET-SNMP-EXTEND-MIB::nsExtendOutLine -On .1.3.6.1.4.1.8072.1.3.2.4.1.2.7.97.100.52.116.101.109.112.1 = STRING: 41 .1.3.6.1.4.1.8072.1.3.2.4.1.2.8.101.99.104.111.116.101.115.116.1 = STRING: hello world
あとはこれを、snmp の監視ツールに適当にセットしてやればグラフの描画なりなんなり好きにできます。