CentLinux | Learn How to Install CentOS/Rocky Linux Servers

Thursday, June 6, 2019

How to 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.

Install ejabberd XMPP Server on CentOS 7

Table of Contents:


Environment Specification:

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

  • Hostname: - ejabberd-01.example.com
  • IP Address - /24
  • Operating System - CentOS 7.6


Installing ejabberd Prerequisites:

Connect with ejabberd-01.example.com 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.

# yum install -y mariadb-server glibc

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.

# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
# systemctl start mariadb.service

Configure MariaDB instance as follows.

# mysql_secure_installation


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.

# cd /tmp
# wget https://www.process-one.net/downloads/downloads-action.php?file=/ejabberd/19.05/ejabberd-19.05-0.x86_64.rpm
--2019-06-04 18:29:05--  https://www.process-one.net/downloads/ejabberd/19.05/ejabberd-19.05-0.x86_64.rpm
Reusing existing connection to www.process-one.net:443.
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.

# 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%]

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.

# 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)

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> EXIT;

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

# 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

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.

# cat >> /opt/ejabberd/conf/ejabberd.yml << EOF
> sql_type: mysql
> sql_server: "localhost"
> sql_database: "ejabberd"
> sql_username: "ejabberd"
> sql_password: "123"

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.

# cp /opt/ejabberd-19.05/bin/ejabberd.service /usr/lib/systemd/system/ejabberd.service

Enable and start ejabberd service.

# systemctl enable ejabberd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/ejabberd.service to /usr/lib/systemd/system/ejabberd.service.
# 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.

# firewall-cmd --permanent --add-port={5280,5222}/tcp
# firewall-cmd --reload


Create an Admin User for ejabberd Admin Console:

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

# export PATH=$PATH:/opt/ejabberd-19.05/bin/
# ejabberdctl register admin ejabberdexample.com 123
User admin@ejabberdexample.com successfully registered

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

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

Browse URL http://ejabberd-01.example.com:5280/admin in a client's browser.

Login as admin@ejabberdexample.com user with 123 password.


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


Go to Virtual Hosts > ejabberdexample.com > 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.

If you find this article useful? Consider supporting us by Buy Me A Coffee

No comments:

Post a Comment

© 2023 CentLinux. All Rights Reserved.