on  it road.com

为 ejabberd 创建 Systemd 服务

现在,我们需要为 ejabberd 创建一个 systemd 服务。

ejabberd 目录中提供了用于 ejabberd XMPP 服务器的预定义 systemd 服务。

将 ejabberd.service 复制到 systemd 服务目录。

[root@ejabberd-01 tmp]# cp /opt/ejabberd-19.05/bin/ejabberd.service /usr/lib/systemd/system/ejabberd.service

启用并启动 ejabberd 服务。

[root@ejabberd-01 tmp]# systemctl enable ejabberd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/ejabberd.service to /usr/lib/systemd/system/ejabberd.service.
[root@ejabberd-01 tmp]# systemctl start ejabberd.service

ejabberd systemd 服务已经启动。

如果我们在 ejabberd.service 启动过程中遇到任何错误,很可能是由于 ejabberd.yml 文件中的拼写错误或者语法错误。

使用 IM 客户端测试 ejabberd XMPP 服务器

为了测试我们的 ejabberd XMPP 服务器,我们需要一个 IM(即时消息)客户端软件。

Internet 上有许多免费的 IM 客户端。
但是我们使用的是 MS Windows 的 Spark IM 客户端。

从 Ignite Realtime 官方网站下载 Spark 客户端。

Spark 安装非常简单,因此我们跳过了安装步骤。

Spark 安装后,使用桌面上的快捷方式运行它。

Spark 软件将显示登录提示。

但是在登录之前,我们必须其中进行一些设置。

单击高级设置。

根据上面的屏幕截图调整设置。

单击确定。

我们再次进入登录屏幕。

以 jackli 用户身份登录。

我们成功登录到 ejabberd XMPP 服务器。

将 MariaDB 配置为 ejabberd 的后端数据库

我们已经安装了 MariaDB 服务器。

现在,我们需要为 ejabberd 创建一个数据库和用户。

[root@ejabberd-01 tmp]# mysql -u root -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE ejabberd;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON ejabberd.* TO 'ejabberd'@'localhost' IDENTIFIED BY '123';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> EXIT;
Bye

使用 ejabberd 安装目录中提供的脚本创建 ejabberd 数据库模式。

[root@ejabberd-01 tmp]# mysql -u ejabberd -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> USE ejabberd;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [ejabberd]> SOURCE /opt/ejabberd-19.05/lib/ejabberd-19.05/priv/sql/mysql.sql;
...
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0
Query OK, 0 rows affected (0.00 sec)
MariaDB [ejabberd]> exit
Bye

我们的 MariaDB 数据库已成功配置并可供 ejabberd 软件使用。

现在,是时候将 ejabberd 与我们的 MariaDB 数据库连接起来了。

ejabberd 默认的内部数据库后端是 Mnesia 。
但是 ejabberd XMPP 服务器非常灵活,支持 MySQL、PostgreSQL 和其他一些作为 ejabberd 数据库后端。

在 ejabberd.yml 文件中添加以下参数来配置 MariaDB 数据库后端。

[root@ejabberd-01 tmp]# cat >> /opt/ejabberd/conf/ejabberd.yml << EOF
> sql_type: mysql
> sql_server: "localhost"
> sql_database: "ejabberd"
> sql_username: "ejabberd"
> sql_password: "123"
> EOF

ejabberd XMPP 服务器已配置为使用 MariaDB 数据库后端。

在 CentOS 7 上为 ejabberd 配置防火墙

配置 Linux 防火墙以允许 ejabberd 跟随服务端口。

[root@ejabberd-01 tmp]# firewall-cmd --permanent --add-port={5280,5222}/tcp
success
[root@ejabberd-01 tmp]# firewall-cmd --reload
success

在 CentOS 7 上安装 ejabberd

我们可以从 ProcessOne 的 ejabberd 官方下载页面下载 Linux x86 64-bits RPM Package。

[root@ejabberd-01 ~]# cd /tmp
[root@ejabberd-01 tmp]# wget https://www.process-one.net/downloads/downloads-action.php?file=/ejabberd/19.05/ejabberd-19.05-0.x86_64.rpm

使用 rpm 命令安装 ejabberd 软件包。

[root@ejabberd-01 tmp]# rpm -ivh ejabberd-19.05-0.x86_64.rpm
Retrieving https://www.process-one.net/downloads/ejabberd/19.05/ejabberd-19.05-0.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:ejabberd-19.05-0                 ################################# [100%]

CentOS 7 上已安装 ejabberd 软件。

安装 ejabberd 准备工作

我们将使用 MariaDB 作为 ejabberd 软件的后端数据库。
因此,我们正在安装 mariadb-server 软件包。

ejabberd 还需要 glibc 包才能正常运行。

使用 yum 命令安装这两个软件包。

[root@ejabberd-01 ~]# yum install -y mariadb-server glibc

注意:如果我们想在 CentOS 7 上安装最新版本的 MariaDB,请参考我们之前的文章。

启用并启动 MariaDB 服务。

[root@ejabberd-01 ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@ejabberd-01 ~]# systemctl start mariadb.service

如下配置 MariaDB 实例。

[root@ejabberd-01 ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
 ... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

我们的 CentOS 7 服务器上已安装了必备软件包。

为 ejabberd 管理控制台创建一个管理用户

我们可以使用 ejabberdctl 命令创建用户以访问 ejabberd 管理控制台。

[root@ejabberd-01 tmp]# export PATH=$PATH:/opt/ejabberd-19.05/bin/
[root@ejabberd-01 tmp]# ejabberdctl register admin ejabberdonitroad.com 123
User admin@ejabberdonitroad.com successfully registered

我们在 ejabberd.yml 文件中使用预定义的主机 ejabberdonitroad.com。

如果我们对此不满意,那么我们可以在 ejabberd.yml 文件中添加自定义主机。

在客户端浏览器中浏览 URL http://ejabberd-01.onitroad.com:5280/admin。

以 admin@ejabberdonitroad.com 用户身份登录,密码为 123.

成功登录后,我们将进入 ejabberd 管理控制台的仪表板。

转到 Virtual Hosts > ejabberdonitroad.com > Users 并添加一个 IM(即时消息)用户,如下所示。

在 CentOS 7 上安装 ejabberd XMPP 服务器

ejabberd 是一个免费的开源 XMPP 应用服务器。

在本文中,我们将在 CentOS 7 上安装 ejabberd XMPP Server,使用 MariaDB Server 作为 ejabberd 数据库后端,然后使用 Spark IM Client 测试配置。

日期:2020-09-17 00:16:39 来源:oir作者:oir