转自肥肥世家 http://www.ringkee.com
8.11. 安装Jabberd2服务器
jabberd2服务器还没正式进入Debian的软件包,但我们可从源码开始安装。下面介绍如何在Debian平台中如何从源码安装jabberd-2.0s10。这里的2.0s10表示jabberd2.0的第十个stable发行版。
*
到jabberd的官方网站下载最新的软件包jabberd-2.0s10.tar.gz。用tar -zxvf jabberd-2.0s10.tar.gz命令解压后会在当前目录下生成jabberd-2.0s10目录。
*
进入源码目录,我们就可以用configure工具配置软件包。但在配置前,先要安装一些支持软件包,分别是libssl-dev和libidn11- dev,还有libmysqlclient14-dev,该软件包用于支持Mysql数据库作为后台数据存储和用户验证,如果你想通过ldap目录服务器来进行用户认证,则还需安装libldap2-dev软件包。准备好后,运行以下命令配置jabberd2:
debian:~/inst/jabberd-2.0s10# ./configure --prefix=/usr/local/jabberd2 --enable-ldap --enable-debug
配置成功后,运行make和make install即可把软件安装到/usr/local/jabberd2目录中。
*
现在可以配置服务器了,jabberd2的配置文件位于/usr/local/jabberd2/etc/jabberd目录下,配置文件的文本是XML格式的。现在我们要修改sm.xml和c2s.xml这两个配置文件,把真实的服务器名写到这两个配置文件中:
修改sm.xml文件,把id标签内的localhost改成真实服务器名
<!-- Session manager configuration -->
<sm>
<!-- Our ID on the network. Users will have this as the domain part of
their JID. If you want your server to be accessible from other
Jabber servers, this ID must be resolvable by DNS.s
(default: localhost) -->
<id>localhost</id>
...
修改c2s.xml文件,也是把id标签内的localhost改成真实服务器名
...
<!-- Local network configuration -->
<local>
<!-- Who we identify ourselves as. This should correspond to the
ID (host) that the session manager thinks it is. You can
specify more than one to support virtual hosts, as long as you
have additional session manager instances on the network to
handle those hosts. The realm attribute specifies the auth/reg
or SASL authentication realm for the host. If the attribute is
not specified, the realm will be selected by the SASL
mechanism, or will be the same as the ID itself. Be aware that
users are assigned to a realm, not a host, so two hosts in the
same realm will have the same users.
If no realm is specified, it will be set to be the same as the
ID. -->
<id>localhost</id>
...
*
jabberd2默认使用MySQL来存放数据和进行用户认证。所以我们还要配置MySQL数据库,为 jabberd2增加相应的数据库和表。jabberd2软件包已为我们提供了一个MySQL脚本自动完成数据库和表的创建。这个脚本位于源码目录下的 tools目录中,文件名是db-setup.mysql。该目录还有针对不同数据库(Oracle、PostgreSQL)的脚本可用。我们以管理员身份登录MySQL服务器,用以下命令运行db-setup.mysql脚本。在运行脚本前,请确保该脚本在当前目录下。
debian:~/inst/jabberd-2.0s10/tools# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 68 to server version: 4.0.24_Debian-10sarge1-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> \. db-setup.mysql
Query OK, 1 row affected (0.00 sec)
Database changed
Query OK, 0 rows affected (0.13 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.02 sec)
...
创建完数据库和表后,我们还要配置该数据库的访问权限,很简单,运行以下命令即可:
mysql> grant select,insert,delete,update on jabberd2.* to jabberd2@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
现在我们就在MySQL数据库创建一个jabberd2用户,密码是123456。该用户可以在jabberd2数据库中做 select,insert,delete,update操作。为了使jabberd2服务器能登录该数据库,我们还需用"jabberd2"和 "123456"这两个参数更新sm.xml和c2s.xml两个配置文件的相关内容。
修改sm.xml文件
...
<!-- Storage database configuration -->
<storage>
<!-- By default, we use the MySQL driver for all storage -->
<driver>mysql</driver>
<!-- Its also possible to explicitly list alternate drivers for
specific data types. -->
<!-- Store vcards in a PostgreSQL database instead -->
<!--
<driver type='vcard'>pgsql</driver>
-->
<!-- MySQL driver configuration -->
<mysql>
<!-- Database server host and port -->
<host>localhost</host>
<port>3306</port>
<!-- Database name -->
<dbname>jabberd2</dbname>
<!-- Database username and password -->
<user>jabberd2</user>
<pass>123456</pass>
...
修改c2s.xml
...
<!-- MySQL module configuration -->
<mysql>
<!-- Database server host and port -->
<host>localhost</host>
<port>3306</port>
<!-- Database name -->
<dbname>jabberd2</dbname>
<!-- Database username and password -->
<user>jabberd2</user>
<pass>123456</pass>
</mysql>
...
*
最后一步,根据sm.xml或c2s.xml中pidfile标签的内容创建进程ID目录。在我的机器上sm.xml配置文件中pidfile标签的内容如下:
<pidfile>/usr/local/jabberd2/var/jabberd/pid/sm.pid</pidfile>
创建pid目录的命令如下:
debian:/usr/local/jabberd2# mkdir -p var/jabberd/pid/
是否创建该目录对服务器的正常运行没有影响,只是有了该目录后,当服务器运行时,在该目录下会生成jabberd2服务进程Id文件,我们可跟踪jabberd2服务器的进程Id号。
*
启动服务器
debian:/usr/local/jabberd2/bin# ./jabberd
如果启动不成功,可查询系统日志或用-D选项启动服务器。
服务器启动后,我们就可用Gaim等客户端连接它。具体操作和上一节内容一样,这里就不再讲了。