This tutorial is a simple way to setup a XWiki clustering for test purpose.

The goal of a cluster of XWiki instance is to provide several XWiki in different servers accessing the same database server to be able to do load balancing.

Install two instances of XWiki on the same MySQL database

Here we will use the XWiki standard distribution but instead of using the embedded hsqldb database we will use a MySql database. For this you need to:

  • modify the hibernate.cfg.xml file to change hsqldb configuration by a proper MySQL configuration
  • copy your database driver JAR in WEB-INF/lib or in some shared lib directory

See http://www.xwiki.org/xwiki/bin/view/AdminGuide/Installation for more details on how to install XWiki.

At this point you almost have a XWiki cluster: you have two instances of XWiki which are using the same datas. But there is a remaining "detail": the problem is that for performance reason XWiki is using lots of different caches which mean that even if one instance of XWiki modify a document it's possible the other XWiki instance will not see it and keep showing the document from its cache.

Configure event distribution

To handle this we will use the network event distribution system. When anything happens in a XWiki instances it generate a local event which is used to update caches. Here we will make theses events send to other XWiki instances as well and emulate local events. This way all the code updating its cache each time something changed in a particular document for example will also be notified if it has been done by another instance of XWiki.

Enable remote observation

First you need to enable remote observation system.

For this go to xwiki.properties file and set the property observation.remote.enabled to true.

Set the channels

Then you need to indicate to remote observation manager which communications channels it should start when XWiki starts.

For this you need to list in property observation.remote.channels the names of the channels.

Here we set udp in both instances to use embedded JGroups udp.xml configuration file which auto discover cluster members.

Start XWiki instance on different ports

For this tutorial we run two instance of XWiki in the same server. So we need each instance to use different ports.

To run a XWik instance if a custom port you can provide it in parameter of the script start_xwiki.sh.

Here we start the first instance with:

sh start_xwiki.sh 8080 8070

and the second one with:

sh start_xwiki.sh 8081 8071

The second port is the port used to stop jetty server, it's not mandatory to run XWiki but it's better to have differents ports if you don't want to have to kill the java process instead of using the stop_xwiki.sh script emoticon_wink

Sometimes you have to force the bind address, you can do it using -Djgroups.bind_addr=127.0.0.1

Check the clustering setup

  • Load a page in both instances
  • Modify a page in one instance
  • Reload it in the other instance
  • It should have taken into account the modification made on the other instance

Add load balancing with apache2 mod_proxy_balancer

You probably want to do load-balancing in front of the clustered XWiki instances. This section provides sample configurations to do that.

Replace if you have one your apache proxy configuration by the following one, or set it as proxy of your apache site configuration if you don't have one yet :

ProxyRequests Off
ProxyPreserveHost On

<Proxy balancer://mycluster>
BalancerMember ajp://127.0.0.1:8009 route=jvm1
BalancerMember ajp://127.0.0.1:9009 route=jvm2
ProxySet stickysession=JSESSIONID
</Proxy>
ProxyPass /xwiki balancer://mycluster/xwiki

You need also to precise the name of the JVM route for each tomcat member of the balancer. In conf/server.xml, edit the Engine node as follow :
   <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">

Where you replace jvm1 by the name of the route you have precised in the Apache configuration.

To test the load-balancing setup, you can edit the version.properties file of your wiki to add a suffix to be able to recognize each member of the cluster. For example version=2.6.33077-node1 for the first node of a cluster of XWiki 2.6 nodes. Then, connect to the wiki via the URL that points to the load-balancer with a first browser, and look at which node is being used. Just after connect with a second browser (to have a different session), and make sure the node used is the other one (since mod_proxy_rewrite affects balancing members sequentially.

Troubleshoot

Debugging

See Debugging Section in the Observation Reference documentation.

Tags:
   

Get Connected