Show last authors
1 {{warning}}
2 This tutorial is a simple way to setup a XWiki clustering for testing purpose. There is many ways to setup JGroups depending on your need.
3 {{/warning}}
5 {{toc/}}
7 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.
9 = Install two instances of XWiki on the same MySQL database =
11 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:
13 * modify the ##hibernate.cfg.xml## file to change hsqldb configuration by a proper MySQL configuration
14 * copy your database driver JAR in WEB-INF/lib or in some shared lib directory
16 See [[the installation instructions>>xwiki:Documentation.AdminGuide.Installation]] for more details on how to install XWiki.
18 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.
20 = Configure event distribution =
22 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.
24 == Enable remote observation ==
26 First you need to enable remote observation system.
28 For this go to file and set the property ##observation.remote.enabled## to ##true##.
30 == Set the channels ==
32 Then you need to indicate to remote observation manager which communications channels it should start when XWiki starts.
34 For this you need to list in property ##observation.remote.channels## the names of the channels.
36 Here we set ##udp## in both instances to use embedded JGroups udp.xml configuration file which auto discover cluster members. In general you should always start by looking at the example configurations files in jgroups jar. Most of them are even configurable with system properties so you don't even have to copy and modify them.
38 This tutorial is working with two instances on the same host but it's possible udp does not work if whatever router or switch behind the members of the cluster does not allow multicast. In that case you might want to try using ##tcp## instead (see tcp.xml in JGroups jar).
40 = Start XWiki instance on different ports =
42 For this tutorial we run two instance of XWiki in the same server. So we need each instance to use different ports.
44 To run a XWik instance if a custom port you can provide it in parameter of the script
46 Here we start the first instance with:
48 {{code}}
49 sh -p 8080 -sp 8070
50 {{/code}}
52 and the second one with:
54 {{code}}
55 sh -p 8081 -sp 8071
56 {{/code}}
58 {{info}}
59 On XWiki versions < 6.2, you should use:
61 {{code}}
62 sh 8080 8070
63 {{/code}}
65 and
67 {{code}}
68 sh 8081 8071
69 {{/code}}
70 {{/info}}
72 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 script ;)
74 Sometimes you have to force the bind address, you can do it using ##-Djgroups.bind_addr=localhost##
76 = Check the clustering setup =
78 * Load a page in both instances
79 * Modify a page in one instance
80 * Reload it in the other instance
81 * It should have taken into account the modification made on the other instance
83 = Add load balancing with apache2 ##mod_proxy_balancer## =
85 You probably want to do load-balancing in front of the clustered XWiki instances. This section provides sample configurations to do that.
87 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 :
89 {{code language="apacheconf"}}
90 ProxyRequests Off
91 ProxyPreserveHost On
93 <Proxy balancer://mycluster>
94 BalancerMember ajp:// route=jvm1
95 BalancerMember ajp:// route=jvm2
96 ProxySet stickysession=JSESSIONID
97 </Proxy>
98 ProxyPass /xwiki balancer://mycluster/xwiki
99 {{/code}}
101 You need also to precise the name of the JVM route for each member of the balancer. On Tomcat, in ##conf/server.xml##, edit the ##Engine## node as follow :
102 {{code language="apacheconf"}} <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">{{/code}}
104 On GlassFish and Tomcat and probably others, you can set the system property jvmRoute to the same value.
106 Where you replace ##jvm1## by the name of the route you have precised in the Apache configuration.
108 This setting will complement the JSESSIONID with a suffix made by this jvmRoute: thus any session will contain the node name and this will instruct Apache to choose that route the next time a request comes. Thus, the browser will remain hooked to that server as long as the session remains.
110 == Testing the clustered setup ==
112 To test the load-balancing setup, you can edit the 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.
114 You can also verify the JSESSIONID cookie value which will end with the route name.
116 Finally, to test that clustering works you can either:
118 * set-up a dedicated virtual host to each cluster node so that you can check that, for example, a changed document, is changed on every node
119 * force the route by adding the URL parameter JSESSIOND=jvm1: this will make sure that this route is used which, in turn, will set the cookie to a session-identifier suffixed with jvm1.
121 = Monitoring and Troubleshooting =
123 The error log of Apache reports an amount of details about the choice of load-balancing if the log-level is sufficient.
125 The balancer-manager is also precious:
127 {{code language="apacheconf"}}
128 <Location /balancer-manager>
129 SetHandler balancer-manager
130 AuthType digest
131 AuthName "XWiki Cluster Management"
132 AuthType Digest
133 AuthDigestDomain
134 AuthDigestFile /path/to/file.htdigest
135 Require valid-user
136 </Location>
137 {{/code}}
139 Using this configuration, properly specialized, provides a small interface at /balancer-manager where you can see the cluster nodes which are active, their load, and where you can disable them to take them offline for a bit.
141 == Debugging ==
143 See [[Debugging Section>>extensions:Extension.Observation Module Remote#HDebugging]] in the Observation Reference documentation.
145 You can also easily include the following HTML to force your browser to change from one node of the cluster to the other. This is extremely important to verify that clustering works:
148 {{code language="html"}}
149 <a href="$"
150 onclick="d = new Date(); d.setDate(d.getDate()+7); document.cookie='JSESSIONID=xxx.$hostname; ' + d.toUTCString()" ##
151 >$hostname</a>
152 {{/code}}
154 (where you replace $hostname (twice) and $ appropriately.

Get Connected