This guide will help you understand how to configure and deploy a Neo4j High Availability cluster. Two scenarios will be considered:
- Configuring three instances to be deployed on three separate machines in a setting similar to what might be encountered in a production environment.
- Modifying the former to make it possible to run a cluster of three instances on the same physical machine, which is particularly useful during development.
Background
Each instance in a Neo4j HA cluster must be assigned an integer ID, which serves as its unique identifier.
At startup, a Neo4j instance contacts the other instances specified in the ha.initial_hosts
configuration option.
When an instance establishes a connection to any other, it determines the current state of the cluster and ensures that it is eligible to join. To be eligible the Neo4j instance must host the same database store as other members of the cluster (although it is allowed to be in an older state), or be a new deployment without a database store.
Explicitly configure IP Addresses/Hostnames for a cluster
Neo4j will attempt to configure IP addresses for itself in the absence of explicit configuration. However in typical operational environments where machines have multiple network cards and support IPv4 and IPv6 it is strongly recommended that the operator explicitly sets the IP address/hostname configuration for each machine in the cluster. |
Let’s examine the available settings and the values they accept.
ha.server_id
ha.server_id
is the cluster identifier for each instance.
It must be a positive integer and must be unique among all Neo4j instances in the cluster.
For example, ha.server_id=1
.
ha.host.coordination
ha.host.coordination
is an address/port setting that specifies where the Neo4j instance will listen for cluster communications (like hearbeat messages).
The default port is 5001
.
In the absence of a specified IP address, Neo4j will attempt to find a valid interface for binding.
While this behavior typically results in a well-behaved server, it is strongly recommended that users explicitly choose an IP address bound to the network interface of their choosing to ensure a coherent cluster deployment.
For example, ha.host.coordination=192.168.33.22:5001
will listen for cluster communications on the network interface bound to the 192.168.33.0 subnet on port 5001.
ha.initial_hosts
ha.initial_hosts
is a comma separated list of address/port pairs, which specify how to reach other Neo4j instances in the cluster (as configured via their ha.host.coordination
option).
These hostname/ports will be used when the Neo4j instances start, to allow them to find and join the cluster.
Specifying an instance’s own address is permitted.
Warning
Do not use any whitespace in this configuration option. |
For example, ha.initial_hosts=192.168.33.22:5001,192.168.33.21:5001
will attempt to reach Neo4j instances listening on
192.168.33.22 on port 5001 and 192.168.33.21 on port 5001 on the 192.168.33.0 subnet.
ha.host.data
ha.host.data
is an address/port setting that specifies where the Neo4j instance will listen for transactions (changes to the graph data) from the cluster master.
The default port is 6001
.
In the absence of a specified IP address, Neo4j will attempt to find a valid interface for binding.
While this behavior typically results in a well-behaved server, it is strongly recommended that users explicitly choose an IP address bound to the network interface of their choosing to ensure a coherent cluster topology.
ha.host.data
must use a different port to ha.host.coordination
.
For example, ha.host.data=192.168.33.22:6001
will listen for cluster communications on the network interface bound to the 192.168.33.0 subnet on port 6001.
Address/port format
The For For Either the address or the port can be omitted, in which case the default for that part will be used.
If the address is omitted, then the port must be preceded with a colon (eg. The syntax for setting the port range is: |
Getting started: Setting up a production cluster
Download and configure
- Download Neo4j Enterprise from the Neo4j download site, and unpack on three separate machines.
-
Configure the HA related settings for each installation as outlined below.
Note that all three installations have the same configuration except for the
ha.server_id
property.
- Neo4j instance #1 — neo4j-01.local
-
conf/neo4j.conf
# Unique server id for this Neo4j instance # can not be negative id and must be unique ha.server_id = 1 # List of other known instances in this cluster ha.initial_hosts = neo4j-01.local:5001,neo4j-02.local:5001,neo4j-03.local:5001 # Alternatively, use IP addresses: #ha.initial_hosts = 192.168.0.20:5001,192.168.0.21:5001,192.168.0.22:5001 # HA - High Availability # SINGLE - Single mode, default. dbms.mode=HA dbms.connector.http.type=HTTP dbms.connector.http.enabled=true dbms.connector.http.address=0.0.0.0:7474
- Neo4j instance #2 — neo4j-02.local
-
conf/neo4j.conf
# Unique server id for this Neo4j instance # can not be negative id and must be unique ha.server_id = 2 # List of other known instances in this cluster ha.initial_hosts = neo4j-01.local:5001,neo4j-02.local:5001,neo4j-03.local:5001 # Alternatively, use IP addresses: #ha.initial_hosts = 192.168.0.20:5001,192.168.0.21:5001,192.168.0.22:5001 # HA - High Availability # SINGLE - Single mode, default. dbms.mode=HA dbms.connector.http.type=HTTP dbms.connector.http.enabled=true dbms.connector.http.address=0.0.0.0:7474
- Neo4j instance #3 — neo4j-03.local
-
conf/neo4j.conf
# Unique server id for this Neo4j instance # can not be negative id and must be unique ha.server_id = 3 # List of other known instances in this cluster ha.initial_hosts = neo4j-01.local:5001,neo4j-02.local:5001,neo4j-03.local:5001 # Alternatively, use IP addresses: #ha.initial_hosts = 192.168.0.20:5001,192.168.0.21:5001,192.168.0.22:5001 # HA - High Availability # SINGLE - Single mode, default. dbms.mode=HA dbms.connector.http.type=HTTP dbms.connector.http.enabled=true dbms.connector.http.address=0.0.0.0:7474
Start the Neo4j Servers
Start the Neo4j servers as usual. Note that the startup order does not matter.
neo4j-01$ ./bin/neo4j start
neo4j-02$ ./bin/neo4j start
neo4j-03$ ./bin/neo4j start
Startup Time
When running in HA mode, the startup script returns immediately instead of waiting for the server to become available. This is because the instance does not accept any requests until a cluster has been formed. In the example above this happens when you start the second instance. To keep track of the startup state you can follow the messages in neo4j.log — the path is printed before the startup script returns. |
Now, you should be able to access the three servers and check their HA status.
Open the locations below in a web browser and issue the following command in the editor after having set a password for the database:
:play sysinfo
Tip You can replace database #3 with an arbiter instance, see Section 25.4, “Arbiter Instances”. |
That’s it! You now have a Neo4j HA cluster of three instances running. You can start by making a change on any instance and those changes will be propagated between them. For more HA related configuration options take a look at Section 25.2, “HA Setup and configuration”.
Alternative setup: Creating a local cluster for testing
If you want to start a cluster similar to the one described above, but for development and testing purposes, it is convenient to run all Neo4j instances on the same machine.
This is easy to achieve, although it requires some additional configuration as the defaults will conflict with each other.
Furthermore, the default dbms.memory.pagecache.size
assumes that Neo4j has the machine to itself.
If we in this example assume that the machine has 4 gigabytes of memory, and that each JVM consumes 500 megabytes of memory, then we can allocate 500 megabytes of memory to the page cache of each server.
Download and configure
- Download Neo4j Enterprise from the Neo4j download site, and unpack into three separate directories on your test machine.
- Configure the HA related settings for each installation as outlined below.
- Neo4j instance #1 — ~/neo4j-01
-
conf/neo4j.conf
# Reduce the default page cache memory allocation dbms.memory.pagecache.size=500m # Port to listen to for incoming backup requests. dbms.backup.address = 127.0.0.1:6366 # Unique server id for this Neo4j instance # can not be negative id and must be unique ha.server_id = 1 # List of other known instances in this cluster ha.initial_hosts = 127.0.0.1:5001,127.0.0.1:5002,127.0.0.1:5003 # IP and port for this instance to bind to for communicating cluster information # with the other neo4j instances in the cluster. ha.host.coordination = 127.0.0.1:5001 # IP and port for this instance to bind to for communicating data with the # other neo4j instances in the cluster. ha.host.data = 127.0.0.1:6363 # HA - High Availability # SINGLE - Single mode, default. dbms.mode=HA dbms.connector.http.type=HTTP dbms.connector.http.enabled=true dbms.connector.http.address=0.0.0.0:7474
- Neo4j instance #2 — ~/neo4j-02
-
conf/neo4j.conf
# Reduce the default page cache memory allocation dbms.memory.pagecache.size=500m # Port to listen to for incoming backup requests. dbms.backup.address = 127.0.0.1:6367 # Unique server id for this Neo4j instance # can not be negative id and must be unique ha.server_id = 2 # List of other known instances in this cluster ha.initial_hosts = 127.0.0.1:5001,127.0.0.1:5002,127.0.0.1:5003 # IP and port for this instance to bind to for communicating cluster information # with the other neo4j instances in the cluster. ha.host.coordination = 127.0.0.1:5002 # IP and port for this instance to bind to for communicating data with the # other neo4j instances in the cluster. ha.host.data = 127.0.0.1:6364 # HA - High Availability # SINGLE - Single mode, default. dbms.mode=HA dbms.connector.http.type=HTTP dbms.connector.http.enabled=true dbms.connector.http.address=0.0.0.0:7475
- Neo4j instance #3 — ~/neo4j-03
-
conf/neo4j.conf
# Reduce the default page cache memory allocation dbms.memory.pagecache.size=500m # Port to listen to for incoming backup requests. dbms.backup.address = 127.0.0.1:6368 # Unique server id for this Neo4j instance # can not be negative id and must be unique ha.server_id = 3 # List of other known instances in this cluster ha.initial_hosts = 127.0.0.1:5001,127.0.0.1:5002,127.0.0.1:5003 # IP and port for this instance to bind to for communicating cluster information # with the other neo4j instances in the cluster. ha.host.coordination = 127.0.0.1:5003 # IP and port for this instance to bind to for communicating data with the # other neo4j instances in the cluster. ha.host.data = 127.0.0.1:6365 # HA - High Availability # SINGLE - Single mode, default. dbms.mode=HA dbms.connector.http.type=HTTP dbms.connector.http.enabled=true dbms.connector.http.address=0.0.0.0:7476
Start the Neo4j Servers
Start the Neo4j servers as usual. Note that the startup order does not matter.
localhost:~/neo4j-01$ ./bin/neo4j start
localhost:~/neo4j-02$ ./bin/neo4j start
localhost:~/neo4j-03$ ./bin/neo4j start
Now, you should be able to access the three servers and check their HA status.
Open the locations below in a web browser and issue the following command in the editor after having set a password for the database:
:play sysinfo