Wiki source code of Run Two Nodes Locally

Last modified by Eleni Cojocariu on 2026/10/20 06:46

Show last authors
1 Run two XWiki instances on one machine, sharing a single database and exchanging their events, to see a [[cluster>>doc:documentation.xs.admin.clustering.architecture.WebHome]] work from end to end.
2
3 {{warning}}
4 This is a way to try clustering out, not a topology to run a wiki on. A real cluster puts its nodes on separate servers behind a load balancer, and they share more than the database: [[Shared Resources>>doc:documentation.xs.admin.clustering.shared-resources.WebHome]] lists what.
5 {{/warning}}
6
7 1. Install the [[Standalone (Demo) Distribution>>doc:documentation.xs.admin.installation.methods.install-standalone-demo-distribution.WebHome]] twice, in two directories of your own choosing. Everything below is done in both of them.(((
8 {{code language="none"}}
9 ~/xwiki-node1
10 ~/xwiki-node2
11 {{/code}}
12 )))
13 1. Point both installations at one MySQL database instead of the HSQLDB each of them ships with, since a cluster is first of all a set of nodes sharing their content. In ##webapps/xwiki/WEB-INF/hibernate.cfg.xml##, comment out the HSQLDB block that is active and uncomment the MySQL one that follows it, then adjust the database name, user and password to the ones you created by following [[Configure MySQL>>doc:documentation.xs.admin.installation.methods.install-xwiki-war.install-relational-database.configure-mysql.WebHome]].(((
14 {{code language="xml"}}
15 <property name="hibernate.connection.url">jdbc:mysql://localhost/xwiki?useSSL=false</property>
16 <property name="hibernate.connection.username">xwiki</property>
17 <property name="hibernate.connection.password">xwiki</property>
18 <property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
19 {{/code}}
20 )))
21 1. Copy the MySQL driver jar into the ##webapps/xwiki/WEB-INF/lib## directory of both installations. The distribution ships the HSQLDB driver only, so without this step neither node starts.(((
22 {{code language="none"}}
23 webapps/xwiki/WEB-INF/lib/hsqldb-*.jar
24 webapps/xwiki/WEB-INF/lib/mysql-connector-j-*.jar
25 {{/code}}
26 )))
27 1. Enable event distribution in ##webapps/xwiki/WEB-INF/xwiki.properties##, on both nodes, giving the second one ##node2## as identifier. This tutorial takes the ##udp## channel, which needs no further configuration on a single machine; [[Enable Event Distribution>>doc:documentation.xs.admin.clustering.enable-event-distribution.WebHome]] covers ##tcp## and channel files of your own.(((
28 {{code language="properties"}}
29 observation.remote.enabled = true
30 observation.remote.channels = udp
31 observation.remote.id = node1
32 {{/code}}
33 )))
34 1. Start each node on its own ports. The first one needs no argument, since 8080 and 8079 are the defaults; the second takes both a HTTP port and a stop port, the latter being the port ##stop_xwiki.sh## talks to, so that stopping one node never touches the other.(((
35 {{code language="none"}}
36 cd ~/xwiki-node1 && ./start_xwiki.sh
37 cd ~/xwiki-node2 && ./start_xwiki.sh -p 8081 -sp 8078
38 {{/code}}
39 )))
40 1. If the two nodes do not find each other, force the interface JGroups binds to, passing it through the environment variable the start script reads for JVM options and keeping its memory setting.(((
41 {{code language="none"}}
42 XWIKI_OPTS="-Xmx1024m -Djgroups.bind_addr=127.0.0.1" ./start_xwiki.sh
43 {{/code}}
44 )))
45 1. Edit a page on the first node, then load that same page on the second: your edit is already there, with no restart. That is the whole point of the exercise, and [[Verify a Cluster>>doc:documentation.xs.admin.clustering.verify.WebHome]] shows how to read which node answered and that both are members of the channel.(((
46 {{code language="none"}}
47 http://localhost:8080/xwiki/bin/view/Sandbox/
48 http://localhost:8081/xwiki/bin/view/Sandbox/
49 {{/code}}
50
51 To put the two nodes behind a single address, continue with [[Add a Load Balancer>>doc:documentation.xs.admin.clustering.load-balancer.WebHome]], whose example balances exactly these two ports.
52 )))

Get Connected