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
Emergency Locksmiths Basingstoke is always ready when you have an emergency. Our company is open every day in the calendar year. Basingstoke Locksmiths
Posted by Basingstoke Locksmiths on 23 Nov 2011 at 17:14Thanks for providing this tutorial. I was having problems with it for days but with your help I could finally solve it.
Posted by Maple on 23 Dec 2011 at 10:08Oh Thank you so much for the help and I am learning now how to install ejabberd 2.00 with PostgreSQL support.plumbers in
Posted by marygrace on 20 Jan 2012 at 16:08yeah right. Thanks much for sharing this great news and on how to install this one. PMP Certification Sacramento California PMP Certification Washington DC
Posted by harry on 23 Jan 2012 at 06:33soon which would have lot of features which everyone is waiting for. There would definitely be a was between iPhone 6 and Samsung Galaxy.. Samsung Galaxy S3
Posted by rahul on 16 Feb 2012 at 19:51Our company is open every day in the calendar year.Nike free sale store Australia,
Posted by nike free run sale on 24 Feb 2012 at 18:36Personally I am not huge fan of army bases in Florida but they are everywhere so you have to love them
Posted by Information on 17 Mar 2012 at 20:32Thanks for sharing with us this information, it is interesting and nice. I can get some more information from your article here so it will be wonderful if you can share more, thanks again. :)
free cell phone spy
i need a complete set of instructions for configuring mysql with ejabberd on windows..
pls help!!
It was an excellent effort made by you through your nice piece of writing, holding the quality and knowledge together for the readers.
Umpire Training
Thanks a lot for the help because I was able to install mine with this ejabberd with postgresql. Thanks for that.
Thanks,
Electrical Surplus Buyer
Thanks for letting us know about this and this tutorial really helps me a lot to understand wbout this ejabberd.
thanks,
casual sandals
yeah that’s right then. I hope I can also do such things and I would really love to have it then. thanks for all of that.
thanks,
designer kids clothes & “wholesale”
yeah that’s right then. I hope I agree with what you just said. I love it.
PMP training course
Keep it up.I would state that you possess lots of understanding on this subject and you wrote outstanding. bottless
Posted by leah on 27 Apr 2012 at 15:52Add comment
Erlang on Twitter
» ajfeed (Ajinkya Feed): Erlang: Erlang : UDP socket usage example with gen_udp: submitted by dzysyak [link] [comment] http://t.co/WMpJtySv
» rianindahinyonk (Rian Indah Syafitri): RT @fathiaamandaaa: RT @indrasan: selamat ulang tahun saudara reza erlang @rezasur semoga makin banyak proyek nya ya.
» ericmoritz (Eric Moritz): RT @Burbass: I can now control my Mindstorm Lego car with Erlang. #erlang #mindstorm http://t.co/Jn78yViH
» dalnefre (Dale Schumacher): RT @Burbass: I can now control my Mindstorm Lego car with Erlang. #erlang #mindstorm http://t.co/Jn78yViH
» Erlang_ABNIC (Erlangga .A): “Dream, Believe, and Make it Happen”. ☺ RT @cjerikho829: “Believe”
» aidilnasution (M Aidil Nasution): RT @fathiaamandaaa: RT @indrasan: selamat ulang tahun saudara reza erlang @rezasur semoga makin banyak proyek nya ya.
» indytertuing (indy hamid): ƪ(^ヮ^)ʃ RT @fathiaamandaaa: RT @indrasan: selamat ulang tahun saudara reza erlang @rezasur semoga makin banyak proyek nya ya.
» rvirding (Robert Virding): RT @Burbass: I can now control my Mindstorm Lego car with Erlang. #erlang #mindstorm http://t.co/Jn78yViH
» pikuseru (Dave Birdsall): @mho105 I bought an O’Reilly book about Clojure, a language for the JVM. Bought Scala and Erlang books over a year ago. Just interesting.
» maxmurphy (Max Murphy): @mdesjardins LOL, erlang might fix something….but not that
Statistics
Number of aggregated posts: 10503
Number of comments: 2135
Most recent article: May 21, 2012
Latest comments
» DRS786 on 25 May 2012: Poznan Erlang User Group Event: I’m going!
» the tantric way in london on TextOne HD for webOS: Interesting articles are published here. By reading it I acquired great deal of knowledge on various subject. Thank you for…
» israeli jewelry on 08 February 2012: Erlang Express 3-day Course in San Francisco on 8 February: It is a wonderful blog. It helps me out a lot. Thank you. I really need help in development and…