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:10This kind of information is very limited on internet. Thanks. http://semiformaldresses.org
Posted by Firentze on 12 Sep 2010 at 16:23Thanks a lot for an excellent tutorial. Since ejabberd moved from svn to git, the pg.sql is not available from the link. Use this instead:
https://git.process-one.net/ejabberd/mainline/blobs/raw/master/src/odbc/pg.sql
Posted by Eldad Mor on 03 Nov 2010 at 21:57Thanks for all the great information, it was very helpful and useful. Many people just clutter tutorials and make them confusing. You did a great job…keep up the good work!
Posted by Frank on 05 Jan 2011 at 20:22Did not know this was possible. I am only using Outlook and I want to try something else. This maybe just the one I am looking for. chicago website design company site.
Posted by GerryGuz75 on 02 Feb 2011 at 21:43I too have been trying to do this. I’ve found that the default native Mnesia database is difficult to use and have been looking for alternatives. I think I might be way over my head but we are looking to run this type of server for our green manufacturing process.
Posted by Jameson on 15 Feb 2011 at 20:57You need build 3 beam files and drop them into ejabberd’s ebin directory. Also create the empty database in Postgresql. Delete old ejabberd mnesia database and restart ejabberd.
it would be interesting for me to try to buy a few custom essays
on it, who knows, maybe it would be interesting!
The Toronto-born Casey was also recently named Editor-in-Chief of O, the Oprah Magazine. Custom Assignment | Book Report Help | Dissertation Writing
Posted by Zieg on 22 Feb 2011 at 08:36Laird Hamilton is known as the guiding genius of crossover board sports Buy Essay | Buy Research Paper
Posted by Zieg on 22 Feb 2011 at 08:37Your tutorial and explanations were quite clear and easy to follow. But why did you need to use PostgreSQL over Mnesia? Is PostgreSQL better or faster? Darryl, business voip
Posted by Darryl on 23 Feb 2011 at 19:46Thanks for explaining. I will use this code in my work.
George. custom writing services
I really enjoyed reading it and I think need to read more on this topic.student essay -Sara
Posted by SaraFord on 29 Apr 2011 at 09:50Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging. Austin Texas Houses
Posted by rocc on 29 Apr 2011 at 20:01nice post
Posted by James on 05 May 2011 at 08:46Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging. hvac los angeles
Posted by niki on 07 May 2011 at 10:56Yes you got a good point that “native Mnesia database which is provided by default”.But it has been used for a very ling time.
Donald
<a >
These tips seem, I have ever found before. However, I myself do not feel so sure with this. I think that’s it. Cord Blood Banking Cost
Posted by Cord Blood Banking Cost on 15 May 2011 at 23:26i still have trouble with sql stuff. articles like this help tho. thanks
Electricians Los Angeles | electrical contractor la
Posted by electrical contractor la on 16 May 2011 at 19:25Every time we want to install something, we should know about the application and the attributes first. If we don’t know the details, we could find difficulties in the progress.
Small business accountant
Add comment
Erlang on Twitter
» despenjahatdos (Jon champion): Eits jangan salah begini2 saya titisan dewa erlang RT @yolapitalokaa: Yg ngepost twit kyknya jg lg galau drtd ... http://t.co/QfCyVSIl
» erlangtriaji (erlang triaji ): Sini sun ahahaha RT @Encays: Udah udah, lo berduaan aja RT @revianh: Kepooo! RT @erlangtriaji: Hadir RT @Encays: Udah, sama erlang aj
» Encays (antarif cahyadi): Menjepit RT @erlangtriaji: Tegang! RT @revianh: Kepooo! RT @erlangtriaji: Hadir RT @Encays: Udah, sama erlang aja RT @revianh
» erlangtriaji (erlang triaji ): Tegang! RT @revianh: Kepooo! RT @erlangtriaji: Hadir RT @Encays: Udah, sama erlang aja RT @revianh: Nanggepnya lama banget
» Encays (antarif cahyadi): Udah udah, lo berduaan aja RT @revianh: Kepooo! RT @erlangtriaji: Hadir RT @Encays: Udah, sama erlang aja RT @revianh: Nanggepnya lama
» revianh (Revian Hermansyah): Kepooo! RT @erlangtriaji: Hadir RT @Encays: Udah, sama erlang aja RT @revianh: Nanggepnya lama banget -_-
» erlangtriaji (erlang triaji ): Hadir RT @Encays: Udah, sama erlang aja RT @revianh: Nanggepnya lama banget -_-
» Encays (antarif cahyadi): Udah, sama erlang aja RT @revianh: Nanggepnya lama banget -_-
» mshiba64 (Masami Shibatani): Erlangではシリアライズはterm_to_binaryというBuilt-in-functionで実行される。画像データもErlangで扱われるいくつかのTermも全てBinary型に可逆変換できる。
» tomohikoseven (tomohiko nagase): 更新した。|andreのブログ: Erlang avl tree insert を作った : http://t.co/4uBqenSw
Statistics
Number of aggregated posts: 10454
Number of comments: 1392
Most recent article: January 31, 2012
Latest comments
» nobelboy on OpaDo Data Storage: Feel free to add some Qs here or contact me offline, and I will see what I can work into…
» darrensy on The Twisted Matrix: This has been a great idea you have shared. covers for kindle
» jony on Principle Software Engineer at LonoCloud (Full-time): That provides will become a internet marketer of little kinds of expert methods developers developing strategy using Erlang/OTP. There will…