Install ejabberd XMPP Server on CentOS 7 - CentLinux


Thursday, 6 June 2019

Install ejabberd XMPP Server on CentOS 7

Install ejabberd XMPP Server on CentOS 7

ejabberd is a free and open source XMPP application server. ejabberd is developed by ProcessOne and distibuted under the terms of GNU GPL license. ejabberd is written in ERlang programming language. The name ejabberd is stands for Erlang Jabber Daemon.

As of year 2009, ejabberd is one of the most popular open source applications written in ERlang. Since the release of version 3 of ejabberd the versioning scheme was changed to reflect the dates as “Year.Month-Revision”. Latest stable release 19.05 is available through ejabberd official download page, whereas, we can download the latest in-development version of ejabberd from Github.

In this article, we will install ejabberd XMPP Server on CentOS 7 with MariaDB Server as ejabberd database backend and then test the configurations using Spark IM Client.

This article provides the detail steps to install and configure ejabberd on CentOS 7 but it does not provide the in-depth theoritical concepts of XMPP technology. Therefore, it is recommend that, you should read a good book on XMPP, like Xmpp: The Definitive Guide: Building Real-Time Applications With Jabber Technologies by O'Reilly Media to increase you understanding of XMPP protocol and related technologies.


Table of Contents:


Environment Specification:

We have provisioned a CentOS 7 virtual machine with following specifications:

  • Hostname: -
  • IP Address - /24
  • Operating System - CentOS 7.6


Installing ejabberd Prerequisites:

Connect with using ssh as root user.

We will use MariaDB as the backend database for ejabberd software. Therefore, we are installing mariadb-server software package.

ejabberd also required glibc package to function properly.

We are installing both software packages using yum command.

[root@ejabberd-01 ~]# yum install -y mariadb-server glibc ... Installed: mariadb-server.x86_64 1:5.5.60-1.el7_5 Dependency Installed: mariadb.x86_64 1:5.5.60-1.el7_5 perl.x86_64 4:5.16.3-294.el7_6 perl-Carp.noarch 0:1.26-244.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBD-MySQL.x86_64 0:4.023-6.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7 perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7 perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-3.el7 perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PathTools.x86_64 0:3.40-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7 perl-Pod-Escapes.noarch 1:1.04-294.el7_6 perl-Pod-Perldoc.noarch 0:3.20-4.el7 perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7 perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7 perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7 perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7 perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-294.el7_6 perl-macros.x86_64 4:5.16.3-294.el7_6 perl-parent.noarch 1:0.225-244.el7 perl-podlators.noarch 0:2.5.1-3.el7 perl-threads.x86_64 0:1.87-4.el7 perl-threads-shared.x86_64 0:1.43-6.el7 Updated: glibc.x86_64 0:2.17-260.el7_6.5 Dependency Updated: glibc-common.x86_64 0:2.17-260.el7_6.5 Complete!

Note: Please refer to our previous article, if you want to install the latest version of MariaDB on CentOS 7.

Enable and start MariaDB service.

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

Configure MariaDB instance as follows.

[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!

Prerequisite software packages have been installed on our CentOS 7 server.


Installing ejabberd on CentOS 7:

ejabberd Community Server 19.05 is released at the time of this writeup.

We can download Linux x86 64-bits RPM Package from ProcessOne's ejabberd official download page.

[root@ejabberd-01 ~]# cd /tmp [root@ejabberd-01 tmp]# wget --2019-06-04 18:29:04-- Resolving ( Connecting to (||:443... connected. HTTP request sent, awaiting response... 302 Found Location: [following] --2019-06-04 18:29:05-- Reusing existing connection to HTTP request sent, awaiting response... 200 OK Length: 18799821 (18M) [application/x-redhat-package-manager] Saving to: âdownloads-action.php?file=%2Fejabberd%2F19.05%2Fejabberd-19.05-0.x86_64.rpmâ 100%[======================================>] 18,799,821 228KB/s in 97s 2019-06-04 18:30:42 (189 KB/s) - âdownloads-action.php?file=%2Fejabberd%2F19.05%2Fejabberd-19.05-0.x86_64.rpmâ saved [18799821/18799821]

Install ejabberd software package using rpm command.

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

ejabberd software has been installed on CentOS 7.


Configure MariaDB as Backend Database for ejabberd:

We have already installed MariaDB Server.

Now, we are required to create a database and user for 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

Create the ejabberd database schema using the script, provided within ejabberd installation directory.

[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

Our MariaDB database is successfully configured and ready to use by ejabberd software.

Now, its time to connect ejabberd with our MariaDB database.

ejabberd default internal database backend is Mnesia. But ejabberd XMPP server is very flexible and support MySQL, PostgreSQL and a few others as ejabberd database backend.

Add the following parameters in ejabberd.yml file to configure MariaDB database backend.

[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 server has been configured to use MariaDB database backend.


Create Systemd Service for ejabberd:

Now, we need to create a systemd service for ejabberd.

There is a predefined systemd service for ejabberd XMPP server has been provided within ejabberd directory.

Copy the ejabberd.service to systemd services directory.

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

Enable and start ejabberd service.

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

ejabberd systemd service has been started.

If you encounter any error during startup of ejabberd.service, it is most probably due to the typostatic or syntax error in ejabberd.yml file.


Configure Firewall for ejabberd on CentOS 7:

Configure Linux Firewall to allow ejabberd following service ports.

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


Create an Admin User for ejabberd Admin Console:

We can create users to access ejabberd Admin Console using ejabberdctl command.

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

We are using the predefined host in ejabberd.yml file.

If you are not happy with that, then you can add a custom host in ejabberd.yml file.

Browse URL in a client's browser.

Login as user with 123 password.


After successful login, you will be at the dashboard of ejabberd Admin console.


Go to Virtual Hosts > > Users and add an IM (Instant Messaging) user as follows.



Test ejabberd XMPP Server using an IM client:

To test our ejabberd XMPP server, we need an IM (Instant Messaging) client software.

There are many free IM clients are available over the Internet. But we are using Spark IM client for MS Windows.

Download Spark client from Ignite Realtime Official Website.

Spark installation is pretty straight forward, thus we are skipping the installation steps.

After Spark installation, run it using the shortcut on the Desktop.

The Spark software will display a login prompt.


But before login, we have to do some settings therein.

Click on Advanced settings.


Adjust the settings as per the above screenshot.

Click on Ok.


We are again at the Login screen.

Login as ahmer user.


We are successfully logged in to ejabberd XMPP Server.



We have successfully installed ejabberd XMPP server on CentOS 7 and tested it using Spark IM client.

No comments:

Post a Comment