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}}
4
5 {{toc/}}
6
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.
8
9 = Install two instances of XWiki on the same MySQL database =
10
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:
12
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
15
16 See [[the installation instructions>>xwiki:Documentation.AdminGuide.Installation]] for more details on how to install XWiki.
17
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.
19
20 = Configure event distribution =
21
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.
23
24 == Enable remote observation ==
25
26 First you need to enable remote observation system.
27
28 For this go to xwiki.properties file and set the property ##observation.remote.enabled## to ##true##.
29
30 == Set the channels ==
31
32 Then you need to indicate to remote observation manager which communications channels it should start when XWiki starts.
33
34 For this you need to list in property ##observation.remote.channels## the names of the channels.
35
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.
37
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).
39
40 = Start XWiki instance on different ports =
41
42 For this tutorial we run two instance of XWiki in the same server. So we need each instance to use different ports.
43
44 To run a XWik instance if a custom port you can provide it in parameter of the script start_xwiki.sh.
45
46 Here we start the first instance with:
47
48 {{code}}
49 sh start_xwiki.sh -p 8080 -sp 8070
50 {{/code}}
51
52 and the second one with:
53
54 {{code}}
55 sh start_xwiki.sh -p 8081 -sp 8071
56 {{/code}}
57
58 {{info}}
59 On XWiki versions < 6.2, you should use:
60
61 {{code}}
62 sh start_xwiki.sh 8080 8070
63 {{/code}}
64
65 and
66
67 {{code}}
68 sh start_xwiki.sh 8081 8071
69 {{/code}}
70 {{/info}}
71
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 stop_xwiki.sh script ;)
73
74 Sometimes you have to force the bind address, you can do it using ##-Djgroups.bind_addr=localhost##
75
76 = Check the clustering setup =
77
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
82
83 = Add load balancing with apache2 ##mod_proxy_balancer## =
84
85 You probably want to do load-balancing in front of the clustered XWiki instances. This section provides sample configurations to do that.
86
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 :
88
89 {{code language="apacheconf"}}
90 ProxyRequests Off
91 ProxyPreserveHost On
92
93 <Proxy balancer://mycluster>
94 BalancerMember ajp://127.0.0.1:8009 route=jvm1
95 BalancerMember ajp://127.0.0.1:9009 route=jvm2
96 ProxySet stickysession=JSESSIONID
97 </Proxy>
98 ProxyPass /xwiki balancer://mycluster/xwiki
99 {{/code}}
100
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}}
103
104 On GlassFish and Tomcat and probably others, you can set the system property jvmRoute to the same value.
105
106 Where you replace ##jvm1## by the name of the route you have precised in the Apache configuration.
107
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.
109
110 == Testing the clustered setup ==
111
112 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.
113
114 You can also verify the JSESSIONID cookie value which will end with the route name.
115
116 Finally, to test that clustering works you can either:
117
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.
120
121 = Monitoring and Troubleshooting =
122
123 The error log of Apache reports an amount of details about the choice of load-balancing if the log-level is sufficient.
124
125 The balancer-manager is also precious:
126
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 http://example.com
134 AuthDigestFile /path/to/file.htdigest
135 Require valid-user
136 </Location>
137 {{/code}}
138
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.
140
141 == Debugging ==
142
143 See [[Debugging Section>>extensions:Extension.Observation Module Remote#HDebugging]] in the Observation Reference documentation.
144
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:
146
147
148 {{code language="html"}}
149 <a href="$doc.name"
150 onclick="d = new Date(); d.setDate(d.getDate()+7); document.cookie='JSESSIONID=xxx.$hostname; ' + d.toUTCString()" ##
151 >$hostname</a>
152 {{/code}}
153
154 (where you replace $hostname (twice) and $doc.name appropriately.

Get Connected