Monday, September 3, 2012

Easy ejabberd clustering procedure

I was fed up with lack of easy ways to connect multiple ejabberd together. The documentation contains what you need but because of not so friendly command lines, I was never satisfied by the procedure.

So I've added a simple command "attach" to "ejabberdctl" that speed up the procedure, basically it uses already defined vars from the script:


    $EXEC_CMD "$ERL \
      $NAME $ERLANG_NODE \
      -mnesia dir \"\\\"$SPOOLDIR\\\"\" \
        -mnesia extra_db_nodes \"[$MASTER]\" \
      -s mnesia"

}
Apply this patch, and enjoy the "attach" command:
=== modified file 'src/ejabberdctl.template'
--- src/ejabberdctl.template    2012-08-02 14:39:16 +0000
+++ src/ejabberdctl.template    2012-08-31 09:06:56 +0000
@@ -364,13 +364,63 @@
         status=0
     }
     return $status
+}
+
+attach ()
+{
+
+RUNAS=${INSTALLUSER-root}
+
+cat <<END
+- Attaching Procedure - (running as '$RUNAS')
+
+You're about to initialise this local mnesia with another running instance.
+Data will be written to '$SPOOLDIR'
+
+First, determine which node do you want to use as master, and answer the question.
+
+Now, once you're in the erlang shell, type:
+mnesia:info().
+
+Look at the line that starts with: "running db nodes", and observe that your node
+is listed.
+
+Then type the following:
+mnesia:change_table_copy_type(schema, node(), disc_copies).
+
+You'll normally get: "{atomic,ok}"
+
+You can now close the shell using:
+q().
+
+You can start ejabberd now, and observe this new node in the webadmin...
+END
+
+echo -n "Specify which master do you want to use (ex: ejabberd@node02): "
+read MASTER
+
+        if [[ -n $MASTER ]]
+        then
+
+    $EXEC_CMD "$ERL \
+      $NAME $ERLANG_NODE \
+      -mnesia dir \"\\\"$SPOOLDIR\\\"\" \
+        -mnesia extra_db_nodes \"[$MASTER]\" \
+      -s mnesia"
+
+        else
+                echo
+
+        fi
 }

+
 case $ARGS in
     ' start') start;;
     ' debug') debug;;
     ' live') live;;
     ' started') wait_for_status 0 30 2;; # wait 30x2s before timeout
     ' stopped') wait_for_status 3 15 2; stop_epmd;; # wait 15x2s before timeout
+    ' attach') attach;;
     *) ctl $ARGS;;
 esac



Ejabberd cluster connection problem using mnesia ?

If you try to connect two ejabberd servers and still can't get the job done because mnesia seems to be blind, check out the content of the file "ejabberdctl.cfg". By default ejabberd vm don't accept network connections ...
#.
#' INET_DIST_INTERFACE: IP address where this Erlang node listens other nodes
#
# This communication is used by ejabberdctl command line tool,
# and in a cluster of several ejabberd nodes.
# Notice that the IP address must be specified in the Erlang syntax.
#
# Default: {127,0,0,1}

INET_DIST_INTERFACE={0,0,0,0}
Fix your file like the code above and retry...

Configuring ejabberd for BOSH using a specific url

Put this inside the "listen" part:
  {5280, ejabberd_http, [
                         {request_handlers,
                                [
                                        {["boshurl"], mod_http_bind}
                                ]
                        },
                         http_bind,
                         web_admin
                        ]}

Reload ejabberd, and connect to "yourdomain:5280/boshurl" and enjoy :)

Sticky