Ejabberdインストール
Jabberサーバ
今年はJabberをいじってみようと思っています.どれがいいのかと,Jabberの総本山に載っているサーバ一覧を見ていて,ejabberdというサーバに気がつきました.Erlangという聞いたことない言語で書かれていたので最初は敬遠していたのですが,ちょっと調べてみてびっくり.なんと,めんどくさくなって放りなげてしまっていたHaskellと同じ関数型言語じゃあないですか.そのerlangの概要はこんな感じ.
Erlang is a general-purpose programming language and runtime environment. Erlang has built-in support for concurrency, distribution and fault tolerance. Erlang is used in several large telecommunication systems from Ericsson.
超訳するとこんなもんでしょうか.
Erlangは汎用プログラミング言語兼実行環境です.並列動作,分散,フォルトトレラントといった機能を標準で備えています.エリクソン社でいくつかの大規模電話システムで使われています.
ぐぐってみたら,こんな文章もありました.
リアルタイム処理や誤り検出が可能で組込用途に使われていて、並行処理の記述も可能、 ML や Haskell、Clean などに代表される関数型プログラミング言語の一種
Erlangインストール
ソースをダウンロードして
- 展開
- cd opt_src_R10B-9
- LANG=C; export LANG (Bshの場合)
- ./configure
- make
- sudo make install
します.コンパイルするには,GNU make,GNU C compiler,Perl 5が必須で,OpenSSL,Sun Java jdk-1.2.2,X Windows,Flexがオプションです.私はオプション分はOpenSSLだけ設定しました.それから,Solarisではsedで問題が発生するかもしれないので"/bin/sed"か"/usr/bin/sed"を明示的に指定しろと書いてありましたが,私が使ったのはFreeBSDだったので特に気にしませんでした.念のために書いておくと,"www.erlang.org"はたまに落ちていることがあるようです.そのときには,ミラーサーバからダウンロードできます.
Ejabberdインストール
ソースをダウンロードして
- 展開
- cd ejabberd-1.0.0/src
- ./configure
- gmake
- su gmake install
します.これでejabberdが"/var/lib/ejabberd"に,設定ファイルが"/etc/ejabberd"に,ログファイルが"/var/log/ejabberd"にできます.
そうは問屋がどんどこしょ
ここまでくればejabberdを起動して,なんて思うんですが,そう簡単には行きませんでした.erlangの使い方がわからないのです."erl ejabberd"とかやればいいのかと思ったのですが,フォアグラウンドで起動してしまって,バックグラウンドにまわせません.色々調べて
erl -pa /var/lib/ejabberd/ebin \ -sname ejabberd \ -s ejabberd \ -ejabberd config \"/etc/ejabberd/ejabberd.cfg\" \ log_path \"/var/log/ejabberd/ejabberd.log\" \ -sasl sasl_error_logger \{file,\"/var/log/ejabberd/sasl.log\"} \ -mnesia dir \"/var/lib/ejabberd/spool\" \ -detached
とすればバックグラウンドに廻る(-detached)ことがわかりました.ちなみにmnesiaというオプションはejabberdが使う内部DB用ファイルの設置ディレクトリを指定しています.で,ejabberdのマニュアルに従えば,ejabberdctlというスクリプトを使えばユーザの登録削除,ejabberdのstopやrestartができるはずなんですが,動きません.どうもejabberdのインストーラにバグがあるみたいで,必要なライブラリがmakeした場所にあるような振る舞いをしていました.そこで,"/var/lib/ejabberd/ebin/ejabberdctl"を
#!/bin/sh cd /var/lib/ejabberd/ebin # <- この行を追加 exec erl -noinput -sname ejabberdctl -s ejabberd_ctl -extra $@
と書き直すことで問題を回避しました.落ち着いたら問題点を見つけたいと思います.ejabberdctlの使い方は,ejabberdをインストールしたマシンがfoo.bar.co.jpだったとしたら,
- 状態確認
/var/lib/ejabberd/ebin/ejabberdctl ejabberd@foo status
- 停止
/var/lib/ejabberd/ebin/ejabberdctl ejabberd@foo stop
- ユーザ削除
/var/lib/ejabberd/ebin/ejabberdctl ejabberd@foo unregister whoami foo.bar.co.jp
のようになります.
ejbabberd.cfg
設定ファイルは以下のように作りました.まだよくわかっていないので,後で見直すとおかしいかもしれません.でもとりあえず動いたので公開してみます.それから,見やすくするためにコメントアウト部分を一部削除しました.そのせいで動かないスクリプトになってるかもしれません.
% will be successfully registered on server to get admin access: {acl, admin, {user, "k.daiba"}}. % Local users: {acl, local, {user_regexp, ""}}. % Only admins can use configuration interface: {access, configure, [{allow, admin}]}. % Every username can be registered via in-band registration: % You could replace {allow, all} with {deny, all} to prevent user from using % in-band registration {access, register, [{allow, all}]}. % After successful registration user will get message with following subject % and body: {welcome_message, {"Welcome!", "Welcome to Jabber Service. " "For information about Jabber visit http://jabber.org"}}. % Only admins can send announcement messages: {access, announce, [{allow, admin}]}. % Only non-blocked users can use c2s connections: {access, c2s, [{deny, blocked}, {allow, all}]}. % Set shaper with name "normal" to limit traffic speed to 1000B/s {shaper, normal, {maxrate, 1000}}. % Set shaper with name "fast" to limit traffic speed to 50000B/s {shaper, fast, {maxrate, 50000}}. % For all users except admins used "normal" shaper {access, c2s_shaper, [{none, admin}, {normal, all}]}. % For all S2S connections used "fast" shaper {access, s2s_shaper, [{fast, all}]}. % Admins of this server are also admins of MUC service: {access, muc_admin, [{allow, admin}]}. % All users are allowed to use MUC service: {access, muc, [{allow, all}]}. % This rule allows access only for local users: {access, local, [{allow, local}]}. % Authentification method. If you want to use internal user base, then use % this line: {auth_method, internal}. % Host name: {hosts, ["foo.bar.co.jp"]}. % Default language for server messages {language, "en"}. % Listened ports: {listen, [{5222, ejabberd_c2s, [{access, c2s}, {shaper, c2s_shaper}, starttls, {certfile, "./ssl.pem"}]}, {5223, ejabberd_c2s, [{access, c2s}, tls, {certfile, "./ssl.pem"}]}, {5269, ejabberd_s2s_in, [{shaper, s2s_shaper}]}, {5280, ejabberd_http, [http_poll, web_admin]}, {8888, ejabberd_service, [{access, all}, {hosts, ["icq.localhost", "sms.localhost"], [{password, "secret"}]}]} ]}. % If SRV lookup fails, then port 5269 is used to communicate with remote server {outgoing_s2s_port, 5269}. % Used modules: {modules, [ {mod_register, [{access, register}]}, {mod_roster, []}, {mod_shared_roster, []}, {mod_privacy, []}, {mod_configure, []}, {mod_configure2, []}, {mod_disco, []}, {mod_stats, []}, {mod_vcard, []}, {mod_offline, []}, {mod_announce, [{access, announce}]}, {mod_echo, [{host, "echo.localhost"}]}, {mod_private, []}, {mod_muc, [{access, muc}, {access_create, muc}, {access_admin, muc_admin}]}, {mod_pubsub, []}, {mod_time, []}, {mod_last, []}, {mod_version, []} ]}.
これを簡単に説明すると,
管理者は"k.daiba"
% will be successfully registered on server to get admin access: {acl, admin, {user, "k.daiba"}}.
任意のユーザが利用可能
% Local users: {acl, local, {user_regexp, ""}}.
設定画面を触れるのは管理者だけ
% Only admins can use configuration interface: {access, configure, [{allow, admin}]}.
アカウントの登録をjabberクライアントから実施可能
% Every username can be registered via in-band registration: % You could replace {allow, all} with {deny, all} to prevent user from using % in-band registration {access, register, [{allow, all}]}.
チャット会議は誰でも利用可能
% All users are allowed to use MUC service: {access, muc, [{allow, all}]}.
サーバ名は"foo.bar.co.jp"
% Host name: {hosts, ["foo.bar.co.jp"]}.
ここからがよくわかっていない箇所です.TLSを使わないc2s(クライアントサーバ間),http(webからの管理画面表示と,JWCHATというwebベースのjabberクライアントを使える)ことだけを確認しました.
% Listened ports: {listen, [{5222, ejabberd_c2s, [{access, c2s}, {shaper, c2s_shaper}, starttls, {certfile, "./ssl.pem"}]}, {5223, ejabberd_c2s, [{access, c2s}, tls, {certfile, "./ssl.pem"}]}, {5269, ejabberd_s2s_in, [{shaper, s2s_shaper}]}, {5280, ejabberd_http, [http_poll, web_admin]}, {8888, ejabberd_service, [{access, all}, {hosts, ["icq.localhost", "sms.localhost"], [{password, "secret"}]}]} ]}.
いろいろモジュールを入れてみていますが,ここのところもまだよくわかっていません.登録しているからmod_registerは使えているし,アドレス帳(roster)をサーバでweb画面を使って登録しているのでmod_shared_rosterも使えているはずです.それから,テキスト会議も開催できたのでmod_mucも使えています.
% Used modules: {modules, [ {mod_register, [{access, register}]}, {mod_roster, []}, {mod_shared_roster, []}, {mod_privacy, []}, {mod_configure, []}, {mod_configure2, []}, {mod_disco, []}, {mod_stats, []}, {mod_vcard, []}, {mod_offline, []}, {mod_announce, [{access, announce}]}, {mod_echo, [{host, "echo.localhost"}]}, {mod_private, []}, {mod_muc, [{access, muc}, {access_create, muc}, {access_admin, muc_admin}]}, {mod_pubsub, []}, {mod_time, []}, {mod_last, []}, {mod_version, []} ]}.
これからぼちぼち精査していきたいと思ってます.んでもってある程度確実になったらs2s設定を使って他のサーバに接続しようと思っています.あ,そうそう.今回ejabberdをインストールしたサーバはINTRANETにあります.明示的にs2s設定をしていないので,他のサーバには繋がらないスタンドアロンです.設定に自信がもてるようになったら外ともつなごうと思っています.