1. 安装

    执行apt-get install ejabberd也可登录官网https://www.process-one.net下载软件包安装。


2. 启停服务

    ejabberdctl restart / stop /start / stop / status

注:有时使用ejabberdctl start启动时会有“Failed RPC connectionto the node ejabberd@ubuntu12: nodedown”之类的报错,此时可从/etc/init.d/ejabberd start启动。


3. 创建用户

3.1 使用命令注册用户

例如要在localhost上注册用户“user1”,密码为“123456”:

    ejabberdctl register user1localhost 123456

 

3.2 修改配置文件

编辑文件/etc/ejabberd/ejabberd.cfg,在

 %% Admin user

{acl, admin,{user, "", "localhost"}}.

后(约第57行)添加

{acl, admin, {user, "user1","localhost"}}.

{access, configure, [{allow, admin}]}.

 

3.3 重启

    ejabberdctl restart

 

3.4 访问管理界面

用浏览器访问http://192.168.10.142:5280/admin,用户名为user1@localhost,密码为123456。登录后界面如下图所示:

wKiom1XKMPmTirfAAAIP9XGhOG4546.jpg

 

4 连接Mysql

4.1 mysql中创建数据库和用户

create database ejabberd default character set utf8 collate utf8_general_ci;

grantall privileges on ejabberd.* to ej_user@'localhost' identified by 'ej123456';

 

4.2 初始化数据库

通过apt-get安装的ejabberd不带有数据库初始化脚本,若是手动安装,则mysql脚本位于ejabberd/lib/ejabberd/priv/sql/mysql.sql。也可直接从https://github.com/processone/ejabberd/blob/master/sql/mysql.sql下载该脚本。

用以下命令导入数据

mysql -u ej_user -p ejabberd < mysql.sql

此时可能会出现这个错误:

ERROR 1214 (HY000) at line 99: The usedtable type doesn't support FULLTEXT indexes

原因为mysql 5.5不支持全文索引,将该表的存储引擎改为MyISAM可解决该问题。

 

4.3 修改配置文件

修改文件/etc/ejabberd/ejabberd.cfg

注释{auth_method,internal}.

取消注释{auth_method,odbc}.

取消注释并修改数据库连接信息{odbc_server, {mysql, "server","database", "username", "password"}}.

修改模块,大约从579行开始,在原模块后增加_odbc,如:

{mod_last_odbc,

{mod_offline_odbc,

{mod_privacy_odbc,

{mod_private_odbc,

{mod_pubsub_odbc,

{mod_roster_odbc,

{mod_vcard_odbc,

 

4.4 编译Mysql模块

ejabberd默认没有mysql模块,需手动编译,否则在启动时将出现以下报错:

=ERROR REPORT==== 2015-08-11 23:55:24 ===

C(<0.684.0>:ejabberd_check:63) : ejabberd is configured to use 'mysql', but the following Erlang modules are not installed: '[mysql,                     


mysql_auth,

mysql_conn,

mysql_recv]'

=INFO REPORT==== 2015-08-11 23:55:24 ===

    application: ejabberd

    exited: {bad_return,{{ejabberd_app,start,[normal,[]]},

                         {'EXIT',database_module_missing}}}

    type: temporary

 

https://svn.process-one.net/ejabberd-modules/mysql/trunk/下载模块的源码,使用命令erlc  *.erl编译src中的模块,将得到mysql_auth.beammysql.beammysql_conn.beammysql_recv.beam四个文件,将其放入/usr/lib/ejabberd/ebin/中,将能正常启动ejabberd

 

4.5 添加用户

使用如下命令添加用户

ejabberdctl register rootlocalhost 123456

用浏览器访问http://192.168.10.142:5280/admin,用户名为root@localhost,密码为123456