How to install ejabberd 2.0.0 with PostgreSQL support
Roberto Ostinelli - - April 28, 2008I’ve recently been looking for a set of detailed instructions on how to proceed in order to have a working ejabberd 2.0.0 server on a Ubuntu server box, that would in addition use PostgreSQL to store its data instead of the native Mnesia database which is provided by default. However, I could not find something that would completely get me through this whole process.
Therefore, here comes a detailed guide to compiling ejabberd version 2.0.0 on an Ubuntu server 7.10 box, complete with PostgreSQL 8.2 support. I am not a linux geek, therefore please do feel free to leave comments on any suggestions / mistakes that you may find in this small guide.
The following are my recommended points to follow. Definitely not exhaustive. One last thing: this worked for me. It doesn’t mean that it will work for you.
Let’s start the operations. First thing, we need to install the dependencies needed to compile and run ejabberd. This can be easily done by issuing the command:
:~$ sudo apt-get install erlang-base erlang-nox erlang-dev build-essential libssl-dev libexpat1-dev
Now, get the ejabberd v2.0.0 source. Download it into your home directory, then unzip it.
:~$ wget http://www.process-one.net/downloads/ejabberd/2.0.0/ejabberd-2.0.0.tar.gz :~$ tar xfz ejabberd-2.0.0.tar.gz
We need to compile ejabberd, with ODBC support enabled. To do so, configure with the –enable-odbc option, then compile and install.
:~$ cd ejabberd-2.0.0/src :~/ejabberd-2.0.0/src$ ./configure --enable-odbc && make :~/ejabberd-2.0.0/src$ sudo make install
Next, we need to provide ejabberd with the Erlang pgsql library. The best way to proceed is to gather the necessary files with subversion and compile them. To proceed, you therefore will need subversion installed on your box. If you do not have it, it can easily be installed on your system:
:~/ejabberd-2.0.0/src$ sudo apt-get install subversion
The necessary Erlang pgsql library can be found on the SVN repository for ejabberd contributions hosted by Process-one. To get the files:
:~/ejabberd-2.0.0/src$ cd :~$ mkdir ejabberd-modules :~$ svn checkout http://svn.process-one.net/ejabberd-modules ejabberd-modules
Now we compile the .beam files.
:~$ cd ejabberd-modules/pgsql/trunk :~/ejabberd-modules/pgsql/trunk$ ./build.sh
The resulting beam files have to be moved where they can be accessed by ejabberd. The best place where to put them is where all the other ejabberd .beam files already are, i.e. into the /var/lib/ejabberd/ebin/ directory.
:~/ejabberd-modules/pgsql/trunk$ cd ebin :~/ejabberd-modules/pgsql/trunk/ebin$ sudo cp * /var/lib/ejabberd/ebin/ :~/ejabberd-modules/pgsql/trunk/ebin$ cd
If we are to use PostgreSQL, we need to have installed on our system. I assume you do not have PostgreSQL installed, otherwise you may skip the appropriate steps. First thing, we get it installed:
:~$ sudo apt-get install postgresql-8.2
Then we configure user postgres with a password.
:~$ sudo su postgres -c psql template1 Welcome to psql 8.2.7, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit postgres=# ALTER USER postgres WITH PASSWORD 'my_postgres_user_password_here'; ALTER ROLE postgres=# \q
Create the ejabberd database.
:~$ sudo -u postgres createdb ejabberd
Now we have a database up and running, but we need to create the necessary database tables and structure. To do so, we have first to download the necessary SQL script:
:~$ wget http://svn.process-one.net/ejabberd/trunk/src/odbc/pg.sql
Then, we can run the script as user postgres.
:~$ sudo su postgres postgres@ubuntu:/home/roberto$ psql ejabberd < pg.sql ...creation here… postgres@ubuntu:/home/roberto$ exit :~$
We now have:
- ejabberd 2.0.0 installed on our system, though not configured yet;
- PostgreSQL with a compliant ejabberd database up and running.
It is time that we configure ejabberd. Open the configuration file:
:~$ sudo pico /etc/ejabberd/ejabberd.cfg
In the file, configure the host of your XMPP server (please change where appropriate):
{hosts, ["my_xmpp_server_dns_here"]}.
Comment out the internal authentication method (since we are going to use PostgreSQL):
%%{auth_method, internal}.
Add ODBC as internal authentication method:
{auth_method, odbc}.
Add a user administrator (please change where appropriate):
{acl, admin, {user, "myadmin_username_here", "my_xmpp_server_dns_here"}}.
Don’t forget to configure the database access (please change where appropriate):
{odbc_server, {pgsql, "www.ostinelli.net", "ejabberd", "postgres", "my_postgres_user_password_here"}}.
If needed, you may also change in this configuration file to store additional data in the PostgreSQL database. To do so:
- Change mod_last to mod_last_odbc to store the last seen date in PostgreSQL.
- Change mod_offline to mod_offline_odbc to store offline messages in PostgreSQL.
- Change mod_roster to mod_roster_odbc to store contact lists in PostgreSQL.
- Change mod_vcard to mod_vcard_odbc to store user description in PostgreSQL.
Save the configuration file and exit.
Now, since you will most presumably want the server to start as daemon on boot, we have to create an appropriate init file. To do so:
:~$ sudo pico /etc/init.d/ejabberd
In the newly created file, copy and paste all of this code:
#! /bin/sh
#
# ejabberd Start/stop ejabberd server
# code modified by Roberto Ostinelli roberto at ostinelli dot net
#### BEGIN INIT INFO
# Provides: ejabberd
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts ejabberd jabber server
# Description: Starts ejabberd jabber server, an XMPP
# compliant server written in Erlang.
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
EJABBERDCTL=/sbin/ejabberdctl
NAME=ejabberd
test -f $EJABBERDCTL || exit 0
. /lib/lsb/init-functions
# Include ejabberd defaults if available
if [ -f /etc/default/ejabberd ] ; then . /etc/default/ejabberd
fi
ctl()
{ action="$1" $EJABBERDCTL $action >/dev/null
}
# 0 is force-ok, 1 is force-ko, 2 is don't know
opstatus=2
case "$1" in start) log_daemon_msg "Starting jabber server: $NAME" if ctl status ; then log_daemon_msg "Server is already running." opstatus=0 else ctl start fi ;; stop) log_daemon_msg "Stopping jabber server: $NAME" if ctl status ; then if ctl stop ; then cnt=0 sleep 1 while ctl status ; do cnt=`expr $cnt + 1` if [ $cnt -gt 60 ] ; then log_daemon_msg "Could not stop server." opstatus=1 break fi sleep 1 done else opstatus=1 fi else log_daemon_msg "Server is not running." opstatus=0 fi ;; restart|force-reload) log_daemon_msg "Restarting jabber server: $NAME" if ctl status ; then ctl restart else log_daemon_msg "Server is not running. Starting $NAME" ctl restart fi ;; *) echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2 exit 1 ;;
esac
if [ $opstatus = 2 ] ; then if [ $? -eq 0 ]; then log_end_msg 0 else log_daemon_msg "Errors were encoundered." log_end_msg 1 fi
else log_end_msg $opstatus
fi
exit 0
Save and exit file. We need to set the properties of this newly created file to be executable, therefore:
:~$ sudo chmod 755 /etc/init.d/ejabberd
You now have an init file which needs to be called at boot and shutdown times, therefore we generate the appropriate rc files with the command:
sudo update-rc.d /etc/init.d/ejabberd defaults 30
We are almost done. First thing, fire up your freshly generated ejabberd installation:
:~$ sudo /etc/init.d/ejabberd start
Then, create the admin account and set its password, and then restart the server:
:~$ sudo ejabberdctl register myadmin_username_here my_xmpp_server_dns_here myadmin_password_here :~$ sudo /etc/init.d/ejabberd restart
If everything went well, you can now access to the administrative server from the URL http://my_xmpp_server_dns_here:5280/admin, from where you can administer your server, add users, etc.
You may also want to check that in the PostgreSQL ejabberd database, in the table ‘users’, you have a first entry with the myadmin_username and myadmin_password you previously configured.
Enjoy.
A thank you to Jody Appermans for his help on some linux insights ;)
Categories: Blogs Roberto Ostinelli
Comments
Hi,
thanks a lot for the tutorial. There is a problem in the init script. On Debian 5.0 (lenny) x86, I get the following error:
/etc/init.d/ejabberd: line 28: syntax error near unexpected token `then’
Any help?
Thanks, Marcus
Posted by Marcus on 08 Nov 2009 at 10:55Thanks.. the odbc part of ejabberd is certainly exposed finally ... was much needed!!
Posted by Bikash Shah on 14 Jan 2010 at 05:10
Add comment
Erlang on Twitter
» fedorausers (Fedora Linux Users): #linux #fedora Re: erlang-doc - dubious dependencies http://dlvr.it/4cWnw
» bestform (bestform): @danielefrijia lisp und erlang habe ich beides schon beruflich eingesetzt.
» bestform (bestform): Es gibt übrigens durchaus Antworten, die ich akzeptieren würde. Lisp, Erlang, Clojure, von mir aus auch Scala. Na? Wie sieht’s aus? :)
» charpi (Nicolas Charpentier): RT @pavlobaron: Even if #erlang hasn’t been mentioned in the latest #thoughtworks report, it won’t keep us from building real cool things with it
» chrisumbel (chris umbel): the functional work i’ve done in the last 18 months (erlang & clojure) have clearly changed how i write Java & .Net code 4 the good
» grzegorzkazulak (Grzegorz Kazulak): @strzalekk erlang? nice :)
» aprimc (Andrej Primc): Reinventing the wheel. No agreeable template engine in Erlang.
» fedorausers (Fedora Linux Users): #linux #fedora erlang-doc - dubious dependencies http://dlvr.it/4cNwW
» opencrowd (OpenCrowd): Cloudant’s BigCouch is open-source. BigCouch is a set of Erlang/OTP applications for creating a cluster of CouchDBs http://bit.ly/bILJ8p
» Missing_Faktor (Rahul Goma Phulore): RT @pavlobaron: Even if #erlang hasn’t been mentioned in the latest #thoughtworks report, it won’t keep us from building real cool things with it
Statistics
Number of aggregated posts: 10079
Number of comments: 554
Most recent article: September 01, 2010
Latest comments
» Nissan Frontier Superchager on Erlang Doesn’t Fit The JVM: I don’t believe it is the silver bullet that fixes all the problems that required you to do your JVM tuning….Nissan Frontier Superchager
» Nissan Frontier Superchager on What to do About Erlang's Records?: The general solution is to delete all the keys that should have new values, then insert the new key/value pairs…
» videomob on Java And Threads (Jetty): Хватит спамить, накинулись