How to install and configure japperd2 with MySQL

Introduction

This guide is going to walkthrough the process of installing and configuring the XMPP or Jabber server jabberd2 on Ubuntu 10.04. In this guide we are going to configure jabberd2 to use a MySQL database for storage and authentication. I’m assuming that you already have MySQL installed and running on the machine that you would like to install jabberd2 on, if not search Google for a guide on how to install and configure MySQL.

Selecting

First a little bit of information on how and why I choose jabberd2 over some of the other XMPP servers out there. I didn’t have a lot of criteria when I was selecting a XMPP server, they where as follows.

Open Source, I think the biggest reason for this personally is that any none-open source XMPP server are not free. Also, I like open source software.

Current Development, it had to still be maintained. There is a number of XMPP server projects on the Internet that have not been maintain in years. I wanted one that was actively being developed.

Small Footprint, this was important because I don’t have a big server. It gets the job done to serve a few websites and processes email. I didn’t want to load an XMPP server that was going to eat a lot of memory and CPU for mostly personal use.

Not written in Java, this was to keep the memory footprint down. Java is not the easiest program on memory, because you have to run the Java interrupter and the Java application. The other reason it could not be written in Java, was because I was not installing the Java interrupter (which I don’t currently have installed) just to run an XMPP server for personal use.

Some other XMPP servers worth checking out are OpenFire and eJabberd (there are many more, check the official XMPP website for a list). I decided against these for one or more of the reasons listed above. That is how I decided on jabberd2.

Install

The first step is to install jabberd2, to do this you might need to uncomment the universe repositories in sources.lst.

This command will open sources.list for editing in vi.

sudo vi /etc/apt/sources.list

Make sure the below lines are uncommented.

deb http://us.archive.ubuntu.com/ubuntu/ lucid universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid universe multiverse

deb http://us.archive.ubuntu.com/ubuntu/ lucid-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-updates universe

deb http://security.ubuntu.com/ubuntu lucid-security universe
deb-src http://security.ubuntu.com/ubuntu lucid-security universe

Now we need to update the local repository index.

This command will update the list of packages in the local repository index.

sudo apt-get update

The final step of install is to install jabberd2.

This command will install jabberd2.

sudo apt-get install jabberd2

Database

The first thing we are going to do is setup the database. We are going to use a MySQL database for both storage (logs, groups, chats) and authentication (users). The easiest way to setup the database is to import the database dump that was downloaded as part of jabberd2.

This command will uncompress the database dump.

sudo gzip -d /usr/share/doc/jabberd2/db-setup.mysql.gz

Now we need to import the database dump into our running instance of MySQL.

This command will import the database dump file into MySQL (MySQL root password is required).

sudo mysql -u root -p < /usr/share/doc/jabberd2/dp-setup.mysql

Now we need to create a MySQL user for jabberd2 to access the database with limited permissions and accesses.

This command will create a user named jabberd2 with access to the database jabberd2 (MySQL root password is required).

sudo mysql -u root -p -e "GRANT select,insert,delete,update ON jabberd2.* to jabberd2@localhost IDENTIFIED by 'secret';"

You should change “secret” (the password) to something else.

Configuration

Now we need to configure jabberd2. There are two files that you have to edit to configure jabberd2 to work with your domain and MySQL database.

sm.xml

The first we are going to edit is sm.xml, this file is configuration information for the session manager.

This command will open sm.xml for editing in vi.

sudo vi /etc/jabberd2/sm.xml

Within sm.xml you need to make the following changes.

Find id and change it to your domain.

<id>jabber.example.com

Find driver, which is under storage and make sure it is set to mysql.

<driver>mysql</driver>

Find the mysql section (a few lines down from driver) and make sure that the following are set correctly for your database configuration from above.

<dbname>jabberd2</dbname>
<user>jabberd2</user>
<pass><strong>secret</strong></pass>

Save and close sm.xml. In vi, press the “Esc” key, then type “:wq” (colon, w, q). This will write out the changes to the file and quit.

c2s.xml

Finally we need to edit c2s.xml, which is the configuration for the client to server communications. It also has the configuration for authentication mechanism.

This command will open c2s.xml for editing in vi.

sudo vi /etc/jabberd2/c2s.xml

Within c2s.xml you need to make the following changes.

Now you need to change the id to your domain, watch out because there is two different id options in the configuration file. So look for local, then look for id within that option.

<id register-enable='true'>localhost.localdomain</id>

Find module, which is under authreg and make sure it is set to mysql.

<module>mysql</module>

Find the mysql section (a few lines down from authreg) and make sure that the following are set correctly for your database configuration from above.

<dbname>jabberd2</dbname>
<user>jabberd2</user>
<pass>secret</pass>

iptables

Almost done, we just need to configure the firewall to allow inbound and outbound connections to our XMPP server.

Inbound

First, we need to open two ports for inbound connections from clients and other XMPP servers.

These commands will open ports 5222 and 5269 for inbound TCP connections.

sudo iptables -A INPUT -p tcp --dport 5222 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 5269 -j ACCEPT

Outbound

Second, we need to open two ports for outbound connections to clients and other XMPP servers.

These commands will open ports 5222 and 5269 for outbound TCP connections.

sudo iptables -A OUTPUT -p tcp --dport 5222 -j ACCEPT
sudo iptables -A OUTPUT -p tcp --dport 5269 -j ACCEPT

Start

Finally, it is time to start our newly installed XMPP server.

This command will start jabberd2.

sudo /etc/init.d/jabberd2 start

Conclusion

If everything was successful you will have running instances of jabberd. You can check this by looking at the running processes.

This command will show running processes that have “jabberd” in their name.

ps -e | grep jabberd2

You should see “jabberd” in the output of the above command. If you don’t, then double check that you didn’t miss a step. You might also want to check your log files.

Comment are closed.