Skip to content

Instantly share code, notes, and snippets.

@holtbp
Last active June 27, 2018 06:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holtbp/67356943dfc0900573806d9dc123b619 to your computer and use it in GitHub Desktop.
Save holtbp/67356943dfc0900573806d9dc123b619 to your computer and use it in GitHub Desktop.
Ejabberd + Riak on Mac OS X

Install ejabberd

Started out by following the instructions here for installing ejabberd on my Mac.

Configure and make:

## Enable flags ensure modules are included to support Riak and Redis
./configure --enable-riak --enable-redis --prefix=$HOME/my-ejabberd
./rebar get-deps
./rebar compile
make && make install

Testing

I installed Adium and Spark to test out 2 users sending/receiving messages. You can find a long list of clients here.

Ejabberd & Riak KV

Riak KV provides a distributed database architecture, focusing on high-availability. You can read more about why/when to choose Riak here.

Install Riak KV

I initially followed these steps on Basho's website to get 1 Riak vnode running, however it became difficult to get multiple vnodes running in a cluster.

So, I abandoned that approach and found the riak-dev-cluster repo. I was able to get 5 Riak vnodes up and running in a cluster in under 10 minutes.

Configuring ejabberd to use Riak

Once you have Riak running, you need to add some lines into ejabberd.yml (which can be found in my-ejabberd/etc/ejabberd/)

Add the following lines to configure the Riak connection:

## Riak
riak_server: "localhost"
riak_port: 11087

For more details, see the Ejabberd docs on Riak configuration.

Then, you have to set the db_type for individual ejabberd modules to use Riak. I have listed the modules below that are compatible with Riak, out of the box:

modules:
  mod_announce: # recommends mod_adhoc
    db_type: riak
    access: announce
  mod_caps: 
    db_type: riak
  mod_last:
   db_type: riak 
  mod_muc:
    ## host: "conference.@HOST@"
    db_type: riak
    access: muc
    access_create: muc_create
    access_persistent: muc_create
    access_admin: muc_admin
  mod_offline:
    db_type: riak
    access_max_user_messages: max_user_offline_messages
  mod_privacy: 
    db_type: riak
  mod_private: 
    db_type: riak
  mod_roster: 
    db_type: riak
  mod_vcard:
    db_type: riak
    search: false

Here is a link to the full ejabberd.yml.

Once you start up ejabberd, you should connect your chat clients and write some messages back and forth. Then, you should see buckets created in Riak KV, and values stored in each.

Ejabberd & Redis

Ejabberd by default uses Mnesia for storing session management data. We prefer to use something a little more "heavy duty" like Redis for storing transient data.

Install Redis

Using Homebrew:

$ brew install redis

Configuring ejabberd to use Redis

Start the Redis server. Then, add some lines into ejabberd.yml (which can be found in my-ejabberd/etc/ejabberd/)

Add the following lines to configure the Redis connection:

## Redis
##   These are all the default values
redis_server: "localhost"
redis_port: 6379
redis_db: 0

Then set the default session management storage to Redis:

## Set session storage type
sm_db_type: redis

For more details, see the Ejabberd docs on Redis configuration.

Start ejabberd with the new configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment