ejabberd和客户端的配置
2010-01-28 17:24:26 阿炯

服务端安装:
1.下载bin文件,执行就可以了
2.从源码开始安装,附属文档比较全面.推荐!安装过程看源码包里的安装文档就ok

客户端安装:
1.桌面程序有psi
2.web客户端有很多

服务端配置:
主配置文件: ejabberd.cfg
{loglevel, 5}.-------------------------  debug  log的级别
{hosts, ["apache.yizhong.com"]}.-------  域名
{listen,  -----------------------------  监听
[
{5222, ejabberd_c2s, [---------------  5222    client to server 的端口
{access, c2s},
{shaper, c2s_shaper},
{max_stanza_size, 65536}
]},
{5269, ejabberd_s2s_in, [
{shaper, s2s_shaper},
{max_stanza_size, 131072}
]},
{5280, ejabberd_http, [--------------   管理端口,web界面
http_bind,
http_poll,
web_admin
]}
]}.
{auth_method, odbc}.  -----------------   登陆的认证方法,此为数据库
{odbc_server, {pgsql, "localhost", 5432, "ejabberd", "postgres", ""}}. ------- 用pgsql做认证
{pgsql_users_number_estimate, true}.--------  优化pgsql的统计选项
{shaper, normal, {maxrate, 1000}}.
{shaper, fast, {maxrate, 50000}}.
{acl, admin, {user, "admin", "apache.yizhong.com"}}.
{acl, local, {user_regexp, ""}}.
{access, max_user_sessions, [{100, all}]}.
{access, local, [{allow, local}]}.
{access, c2s, [{deny, blocked},
{allow, all}]}.
{access, c2s_shaper, [{none, admin},
{normal, all}]}.
{access, s2s_shaper, [{fast, all}]}.
{access, announce, [{allow, admin}]}.
{access, configure, [{allow, all}]}.
{access, muc_admin, [{allow, admin}]}.
{access, muc, [{allow, all}]}.
{access, register, [{allow, all}]}.
{access, pubsub_createnode, [{allow, all}]}.
{language, "en"}.
{modules,-----------------------------------虚拟主机加载的公共模块,还可以加载其他模块
[
{mod_adhoc,    []},
{mod_caps,     []},
{mod_disco,    []},
{mod_http_bind,[]},
{mod_http_fileserver, [{docroot, "/opt/ejabberd-2.0.2_2/www"}]},
{mod_irc,      []},
{mod_last,     []},
{mod_muc,      [
{access, muc},
{access_create, muc},
{access_persistent, muc},
{access_admin, muc_admin}
]},
{mod_offline,  []},
{mod_privacy,  []},
{mod_private,  []},
{access_createnode, pubsub_createnode},
{plugins, ["default", "pep"]}
]},
{mod_register, [
{welcome_message, {"Welcome!",
"Welcome to this Jabber server."}},
{access, register}
]},
{mod_roster,   []},
{mod_shared_roster,[]},
{mod_time,     []},
{mod_vcard,    []},
{mod_version,  []}
]}.

配置pgsql连接:
{auth_method, odbc}.  -----------------   登陆的认证方法,此为数据库
{odbc_server, {pgsql, "localhost", 5432, "ejabberd", "postgres", ""}}. ------- 用pgsql做认证
{pgsql_users_number_estimate, true}.--------  优化pgsql的统计选项

这3项必有
在源码包中有pg.sql文件,在psql客户端中执行这个文件
进入pgsql:
psql -U postgres template1
执行pg.sql文件建立数据库和表:
postgres#\i /----path---/pg.sql
之后,在postgresql中新建个数据库ejabberd

退出psql,进入ejabberd数据库:
psql -U postgres ejabberd
\dt
就能看到新建立的表了
注意:  连接数据库的几个要点,
pgsql --> 关键字
host --> "localhost"
端口 --> 5432   不用加引号
数据库名字 --> "ejabberd"
用户名 --> "postgres"
密码 --> "" 这里为空
还有其他的配置文件要看看,如conf文件夹里的odbcini, odbcinst.ini,里面也有用户名和密码等要点.注意要和ejabberd.cfg一致.

web客户端和服务端的通讯:
用apache中转下,做个映射才可以.当然,apache要开proxy模块了;下面是apache的虚拟主机的配置:

ServerName ezsoft
DocumentRoot "d:/web/"

Options +MultiViews

AddDefaultCharset UTF-8
ProxyPass /http-bind/ http://192.168.3.196:5280/http-bind/-----------> 这里!


在公司内,架设一个 IM 软件供员工们传送讯息,除了可增加彼此间的感情外,也是提高生产力的方式之一。要架设怎样的一个 IM 系统呢?以下是我的考虑:
1. 使用在 local lan 内,也就是在内部局域网络内
2. 架设及维护要简单
3. 要使用何种软件,个人使用基于 xmpp 协议的 ejabberd server 软件

以下是其 Features:
- (Mostly) XMPP-compliant
- Web based administration
- Load balancing: can run in a cluster of machines
- Fault-tolerance: database can be replicated and stored on multiple nodes (nodes can be added or replaced 'on the fly')
- SSL/TLS support
- Multi-User Chat (MUC/conference)
- IRC transport
- Jabber Users Directory, based on users vCards
- Service Discovery

以上或许有些复杂,但我们只需使用其中的一部份功能即可。另外 ejabberd 也可使用 web 网页的方式来管理,实在是很方便。
XMMP 的登入方式和 MSN,等常见的实时传讯类似,是使用 user@host_name 的方式,host_name 可以是一个 FQDN 或是 IP 地址,以下假设你的 FQDN 是 test.com,可能你的公司没有架设 DNS 系统,那么直接使用 ip(如 192.168.1.100)也是可行的。

★ 安装 ejabberd
直接使用 Synaptic 或是 apt-get 安装 ejabberd。安装完毕后会产生 ejabberd 及 ejabberdctl 这两个执行档,其中 ejabberd 是用来启动 XMPP 之用,而 ejabberdctl 顾名思议则是用来控制 XMPP 之用,像管理使用者、关闭 ejabberd 等.以下是 ejabberdctl 的语法

★ 设定
先说明一下,ejabberd 是使用 erlang 语言开发的,在 /etc/ejabberd/ejabberd.cfg 这个设定档中,% 这个符号是 comment out 的意思,所以如果在这行的最前面有 % 这个符号,表示此行已被批注掉,不起作用。
ejabberd 的设定档是 /etc/ejabberd/ejabberd.cfg 这个,如前所述首先设定主机名称,将
%{hosts, ["localhost"]}.

改为你的主机名称(以 test.com 为例)
{hosts, ["test.com"]}.

然后重新启动 ejabberd
# /etc/init.d/ejabberd restart

★ 管理 ejabberd
前面说过我们可利用 ejabberdctl 来管理 ejabberd,另外也可用 http://YOUR_HOST_NAME:5280/admin web 接口来管理。所以我们必需先建立一个使用者,且让这个使用者有管理者的权限。

1. 建立使用者(假设该账号为 test,密码为 goawayms)
# ejabberdctl register test test.com goawayms

2. 设定 /etc/ejabberd/ejabberd.cfg 檔
在此档案内加入
{acl, admin, {user, "test"}}.

这表示 test 这个 user 具有 admin(管理者) 的权限,当然如果一个管理者不够,你可多设几个.另外,再检查是否有
{access, configure, [{allow, admin}]}.
这行,这代表者允许(allow) admin 来管理及设定(configure) ejabberd

重新启动 ejabberd
# /etc/init.d/ejabberd restart

然后你可使用浏览器,输入 http://test.com:5280/admin 输入账号及密码后,就可管理你的 ejabberd server 了。
-------
经过以上安装、设定后,ejabberd 架设好了,可以使用 gaim 或是其它支持 jabber XMPP 协议的 CLIENT 软件来登入到 ejabberd server 上使用了。

参考数据:
man ejabberdctl
man ejabberd
http://www.process-one.net/en/projects/ejabberd/

Linux下安装ejabberd支持MySQL
# wget https://support.process-one.net/doc/download/attachments/415/mysql.tar.gz?version=5 --no-check-certificate
# wget http://www.process-one.net/downloads/ejabberd/2.0.5/ejabberd-2.0.5.tar.gz
# tar xzvf mysql.tar.gz?version=5
# tar xzvf ejabberd-2.0.5.tar.gz
# cp mysql/mysql* ejabberd-2.0.5/src
# cd ejabberd-2.0.5/src
# ./configure --prefix=/usr/local/ejabberd --enable-odbc
# make
# make install
# ln -s /usr/local/ejabberd/etc/ejabberd/ /etc/ejabberd
# vi /etc/ejabberd/ejabberd.cfg
{hosts, ["lip.com.cn"]}.

{auth_method, [odbc]}
{odbc_server, {mysql, "localhost", "ejabberd", "ejabberd", "ejabberd"}}.

{acl, admins, {user, "koven", "lip.com.cn"}}.
{access, configure, [{allow, admins}]}.

{5280, ejabberd_http, [
http_bind,
http_poll,
web_admin
]}

mod_offline_odbc, ... // 给有odbc的mod后面全加_odbc,让MySQL来保存数据。

# mysql -u root -pmysqlpasswd
mysql> create database ejabberd;
mysql> use ejabberd;
mysql> source ejabbersrc/odbc/mysql.sql
mysql> GRANT ALL PRIVILEGES ON ejabberd.* TO ejabberd@"localhost" IDENTIFIED BY 'ejabberd' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> quit

# sbin/ejabberdctl start
# sbin/ejabberdctl register koven lip.com.cn passwordforkoven // 添加一个管理员

Jabber Server
1.   Introduction
2.   ejabberd
2.1   Configuring ejabberd
2.2   DNS Records
2.3   ejabberd Port Forwarding
3.   Transports
3.1   AIM Transport
3.2   MSN Transport
4.   Gajim

Introduction
I've always fancied running my own Jabber server, but I would also like to run AIM and MSN transports. I have tried and failed to get Jabber 1.4 server workingg, so I have decided to give ejabberd a go.

ejabberd
aptitude install ejabberd

Configuring ejabberd
Edit '/etc/ejabberd/ejabberd.cfg'. % are comments.

nano /etc/ejabberd/ejabberd.cfg

This config file is read only once, and the settings are put into the ejabbed server database on startup. Unfortunately, that's probably already happened, so uncomment the 'override_acls' directive - this makes the server re-read the ACL settings from this file on next startup.
override_acls.

Edit the line below '%% Admin user'. It wants to be something like

%% Admin user
{acl, admin, {user, "user", "example.org"}}.

Change the line below '%% Hostname' to set the hostname of the server:

%% Hostname
{hosts, ["example.org"]}.

If you want to disable user registrations, set up the following ACL

% None username can be registered via in-band registration:
{access, register, [{deny, all}]}.

Take a look through the rest of the settings.Now restart the server, to pick up the new settings:
ejabberdctl restart

ejabberdctl can also register your admin / jabber user if you've turned off anonymous registration:
ejabberdctl register "user" example.org

DNS Records
eJabberd server and clients, are able to use DNS SRV records for hostname resolution. DNS SRV records allow for delegation of services 'by port' to other hosts. These instructions should work for Bind and NSD3, please check following documentation for full details...
* http://jabberd.jabberstudio.org/2/docs/section05.html#5_7

There are 3 SRV records that can be created for a eJabberd server installation:

_jabber._tcp.your_domain.com. 86400 IN SRV 5 0 5269 host.example.org.
_xmpp-server._tcp.your_domain.com. 86400 IN SRV 5 0 5269 host.example.org.
_xmpp-client._tcp.your_domain.com. 86400 IN SRV 5 0 5222 host.example.org.

Replace example.org. with your domain name and host with hostname of your eJabbered server.

Once the your DNS server is properly updated, you should test the listings using Dig. For example, to test the entry of _jabber._tcp.some_domain.com, using the DNS server my.dns_server.com, you would enter the command below:

dig @127.0.0.1 _jabber._tcp.example.org any +short

This should provide you with the data from your DNS SRV record:
5 0 5269 host.example.org.

ejabberd Port Forwarding
Use NAT or firewall rule to forward/allow the following ports to your Jabber server...
* TCP/5222
* TCP/5223
* TCP/5269
* TCP/5280

References
* http://jerakeen.org/blog/2007/10/running-a-jabber-server-with-ejabberd/
* http://michael-prokop.at/blog/2007/07/27/setting-up-your-own-jabber-server-ejabberd/
* http://morozovsky.blogspot.com/2007/11/task-installation-corporate-instant.html
* http://mattfleming.com/node/130
* http://www.debian-administration.org/articles/42
* http://www.debian-administration.org/articles/392

Transports
I no longer enable these transports since they were somewhat unstable on Debian Etch. I may re-visit these in the future...

AIM Transport
apt-get install pyaimt

Configure pyaimt
Edit '/etc/pyaimt.conf.xml' to suit your environment.
* The 'jid' setting should be what ID you want the transport to take on the network. Example: aim.myserver.org
* The 'mainServer' setting should be the IP address or DNS of the main Jabber server. Default: 127.0.0.1
* The 'secret' setting should match the secret specified for component connections in your main Jabber server. It's a password that only the Jabber server and the transport must know.
* The 'port' setting is the port that the transport and ejabberd server agree to use to connect between them. Use: 5556
* The 'name' setting should be what name you wish users to see in a service discovery request.

/etc/pyaimt.conf.xml

aim.example.org

chatrooms.aim.example.org

该文章最后由 阿炯 于 2013-06-08 09:39:29 更新,目前是第 3 版。