<commit_before>[[ha-setup-tutorial]]
High Availability setup tutorial
================================

This is a guide to set up a Neo4j HA cluster and run embedded Neo4j or Neo4j Server instances participating as cluster members.
This tutorial shows how to do this on a single computer. Adjust configuration accordingly if you are using several separate computers to run your clusters.

== Background ==

A Neo4j HA cluster consists of a set of Neo4j Enterprise instances, either running in embedded or server mode. All that
is needed to set this up is to configure the instances so that they can find each other and communicate over the network.

[TIP]
Neo4j Server (see <<server>>) and Neo4j Embedded (see <<configuration-introduction>>) can both be used as nodes in the same HA cluster.
This opens for scenarios where one application can insert and update data via a Java or JVM language based application, and other instances can run Neo4j Server and expose the data via the REST API (<<rest-api>>).

Below, you will see how to set up a cluster with 3 participating Neo4j instances.

=== Download and unpack Neo4j Enterprise ===

Download and unpack three installations of Neo4j Enterprise 
(called +$NEO4J_HOME1+, +$NEO4J_HOME2+, +$NEO4J_HOME3+) from http://neo4j.org/download[the Neo4j download site].

== Start the Neo4j Servers in HA mode ==

In your 'conf/neo4j.properties' file, enable HA by setting the necessary parameters for all 3 installations.
Neo4j HA uses two ports, one for transmitting data and one for cluster coordination.
The cluster coordination port is by default set to a range, and Neo4j will try to bind in this range on startup, so there is no need to specify port number for that.
The config files should include the following:

[TIP]
The amount of necessary configuration increases for a cluster where many instances lives on the same physical machine, due to port clashes. 
This will be reduced further as HA develops.

Database instances #1

[source,properties]
----
# Unique server id for this graph database
# can not be negative id and must be unique
ha.server_id = 1

# IP and port for this instance to bind to for communicating data with the
# other neo4j instances in the cluster.
ha.server = 127.0.0.1:6361
online_backup_port = 6362

# IP and port for this instance to bind to for communicating cluster information
# with the other neo4j instances in the cluster.
ha.cluster_server = 127.0.0.1:5001

# 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
----

Database instances #2

[source,properties]
----
# Unique server id for this graph database
# can not be negative id and must be unique
ha.server_id = 2

# IP and port for this instance to bind to for communicating data with the
# other neo4j instances in the cluster.
ha.server = 127.0.0.1:6363
online_backup_port = 6364

# IP and port for this instance to bind to for communicating cluster information
# with the other neo4j instances in the cluster.
ha.cluster_server = 127.0.0.1:5002

# 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
----

Database instances #3

[source,properties]
----
# Unique server id for this graph database
# can not be negative id and must be unique
ha.server_id = 3

# IP and port for this instance to bind to for communicating data with the
# other neo4j instances in the cluster.
ha.server = 127.0.0.1:6365
online_backup_port = 6366

# IP and port for this instance to bind to for communicating cluster information
# with the other neo4j instances in the cluster.
ha.cluster_server = 127.0.0.1:5003

# 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
----

To avoid port clashes when starting the servers, adjust the ports for the REST end points in all instances under 'conf/neo4j-server.properties' and enable HA mode:

Database instances #1

[source,properties]
...
# http port (for all data, administrative, and UI access)
org.neo4j.server.webserver.port=7474
...
# https port (for all data, administrative, and UI access)
org.neo4j.server.webserver.https.port=7473
...
# Allowed values:
# HA - High Availability
# SINGLE - Single mode, default.
# To run in High Availability mode, configure the coord.cfg file, and the
# neo4j.properties config file, then uncomment this line:
org.neo4j.server.database.mode=HA
----

Database instances #2

[source,properties]
...
# http port (for all data, administrative, and UI access)
org.neo4j.server.webserver.port=7476
...
# https port (for all data, administrative, and UI access)
org.neo4j.server.webserver.https.port=7475
...
# Allowed values:
# HA - High Availability
# SINGLE - Single mode, default.
# To run in High Availability mode, configure the coord.cfg file, and the
# neo4j.properties config file, then uncomment this line:
org.neo4j.server.database.mode=HA
----

Database instances #3

[source,properties]
...
# http port (for all data, administrative, and UI access)
org.neo4j.server.webserver.port=7478
...
# https port (for all data, administrative, and UI access)
org.neo4j.server.webserver.https.port=7477
...
# Allowed values:
# HA - High Availability
# SINGLE - Single mode, default.
# To run in High Availability mode, configure the coord.cfg file, and the
# neo4j.properties config file, then uncomment this line:
org.neo4j.server.database.mode=HA
----


To avoid JMX port clashes adjust the assigned ports for all instances in 'conf/neo4j-wrapper.conf'.
The paths to the 'jmx.password' and 'jmx.access' files also needs to be set.
Note that the 'jmx.password' file needs the correct permissions set, see the configuration file for further information.

[source,properties]
----
#$NEO4J_HOME1/conf/neo4j-wrapper.conf
...
wrapper.java.additional.4=-Dcom.sun.management.jmxremote.port=3637
wrapper.java.additional.5=-Dcom.sun.management.jmxremote.password.file=conf/jmx.password
wrapper.java.additional.6=-Dcom.sun.management.jmxremote.access.file=conf/jmx.access
...
----

[source,properties]
----
#$NEO4J_HOME2/conf/neo4j-wrapper.conf
...
wrapper.java.additional.4=-Dcom.sun.management.jmxremote.port=3638
wrapper.java.additional.5=-Dcom.sun.management.jmxremote.password.file=conf/jmx.password
wrapper.java.additional.6=-Dcom.sun.management.jmxremote.access.file=conf/jmx.access
...
----

[source,properties]
----
#$NEO4J_HOME3/conf/neo4j-server.properties
...
wrapper.java.additional.4=-Dcom.sun.management.jmxremote.port=3639
wrapper.java.additional.5=-Dcom.sun.management.jmxremote.password.file=conf/jmx.password
wrapper.java.additional.6=-Dcom.sun.management.jmxremote.access.file=conf/jmx.access
...
----

Now, start all three server instances.

[source,shell]
----
neo4j_home1$ ./bin/neo4j start<commit_msg>Fixed a format issue<commit_after>[[ha-setup-tutorial]]
High Availability setup tutorial
================================

This is a guide to set up a Neo4j HA cluster and run embedded Neo4j or Neo4j Server instances participating as cluster members.
This tutorial shows how to do this on a single computer. Adjust configuration accordingly if you are using several separate computers to run your clusters.

== Background ==

A Neo4j HA cluster consists of a set of Neo4j Enterprise instances, either running in embedded or server mode. All that
is needed to set this up is to configure the instances so that they can find each other and communicate over the network.

[TIP]
Neo4j Server (see <<server>>) and Neo4j Embedded (see <<configuration-introduction>>) can both be used as nodes in the same HA cluster.
This opens for scenarios where one application can insert and update data via a Java or JVM language based application, and other instances can run Neo4j Server and expose the data via the REST API (<<rest-api>>).

Below, you will see how to set up a cluster with 3 participating Neo4j instances.

=== Download and unpack Neo4j Enterprise ===

Download and unpack three installations of Neo4j Enterprise 
(called +$NEO4J_HOME1+, +$NEO4J_HOME2+, +$NEO4J_HOME3+) from http://neo4j.org/download[the Neo4j download site].

== Start the Neo4j Servers in HA mode ==

In your 'conf/neo4j.properties' file, enable HA by setting the necessary parameters for all 3 installations.
Neo4j HA uses two ports, one for transmitting data and one for cluster coordination.
The cluster coordination port is by default set to a range, and Neo4j will try to bind in this range on startup, so there is no need to specify port number for that.
The config files should include the following:

[TIP]
The amount of necessary configuration increases for a cluster where many instances lives on the same physical machine, due to port clashes. 
This will be reduced further as HA develops.

Database instances #1

[source,properties]
----
# Unique server id for this graph database
# can not be negative id and must be unique
ha.server_id = 1

# IP and port for this instance to bind to for communicating data with the
# other neo4j instances in the cluster.
ha.server = 127.0.0.1:6361
online_backup_port = 6362

# IP and port for this instance to bind to for communicating cluster information
# with the other neo4j instances in the cluster.
ha.cluster_server = 127.0.0.1:5001

# 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
----

Database instances #2

[source,properties]
----
# Unique server id for this graph database
# can not be negative id and must be unique
ha.server_id = 2

# IP and port for this instance to bind to for communicating data with the
# other neo4j instances in the cluster.
ha.server = 127.0.0.1:6363
online_backup_port = 6364

# IP and port for this instance to bind to for communicating cluster information
# with the other neo4j instances in the cluster.
ha.cluster_server = 127.0.0.1:5002

# 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
----

Database instances #3

[source,properties]
----
# Unique server id for this graph database
# can not be negative id and must be unique
ha.server_id = 3

# IP and port for this instance to bind to for communicating data with the
# other neo4j instances in the cluster.
ha.server = 127.0.0.1:6365
online_backup_port = 6366

# IP and port for this instance to bind to for communicating cluster information
# with the other neo4j instances in the cluster.
ha.cluster_server = 127.0.0.1:5003

# 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
----

To avoid port clashes when starting the servers, adjust the ports for the REST end points in all instances under 'conf/neo4j-server.properties' and enable HA mode:

Database instances #1

[source,properties]
---
# http port (for all data, administrative, and UI access)
org.neo4j.server.webserver.port=7474
...
# https port (for all data, administrative, and UI access)
org.neo4j.server.webserver.https.port=7473
...
# Allowed values:
# HA - High Availability
# SINGLE - Single mode, default.
# To run in High Availability mode, configure the coord.cfg file, and the
# neo4j.properties config file, then uncomment this line:
org.neo4j.server.database.mode=HA
----

Database instances #2

[source,properties]
---
# http port (for all data, administrative, and UI access)
org.neo4j.server.webserver.port=7476
...
# https port (for all data, administrative, and UI access)
org.neo4j.server.webserver.https.port=7475
...
# Allowed values:
# HA - High Availability
# SINGLE - Single mode, default.
# To run in High Availability mode, configure the coord.cfg file, and the
# neo4j.properties config file, then uncomment this line:
org.neo4j.server.database.mode=HA
----

Database instances #3

[source,properties]
---
# http port (for all data, administrative, and UI access)
org.neo4j.server.webserver.port=7478
...
# https port (for all data, administrative, and UI access)
org.neo4j.server.webserver.https.port=7477
...
# Allowed values:
# HA - High Availability
# SINGLE - Single mode, default.
# To run in High Availability mode, configure the coord.cfg file, and the
# neo4j.properties config file, then uncomment this line:
org.neo4j.server.database.mode=HA
----


To avoid JMX port clashes adjust the assigned ports for all instances in 'conf/neo4j-wrapper.conf'.
The paths to the 'jmx.password' and 'jmx.access' files also needs to be set.
Note that the 'jmx.password' file needs the correct permissions set, see the configuration file for further information.

Database instance #1

[source,properties]
----
...
wrapper.java.additional.4=-Dcom.sun.management.jmxremote.port=3637
wrapper.java.additional.5=-Dcom.sun.management.jmxremote.password.file=conf/jmx.password
wrapper.java.additional.6=-Dcom.sun.management.jmxremote.access.file=conf/jmx.access
...
----

Database instance #2

[source,properties]
----
...
wrapper.java.additional.4=-Dcom.sun.management.jmxremote.port=3638
wrapper.java.additional.5=-Dcom.sun.management.jmxremote.password.file=conf/jmx.password
wrapper.java.additional.6=-Dcom.sun.management.jmxremote.access.file=conf/jmx.access
...
----

Database instance #3

[source,properties]
----
...
wrapper.java.additional.4=-Dcom.sun.management.jmxremote.port=3639
wrapper.java.additional.5=-Dcom.sun.management.jmxremote.password.file=conf/jmx.password
wrapper.java.additional.6=-Dcom.sun.management.jmxremote.access.file=conf/jmx.access
...
----

Now, start all three server instances.

[source,shell]
----
neo4j_home1$ ./bin/neo4j start
{'fraction_non_alphanumeric': 0.09837638376383764, 'fraction_numerical': 0.03985239852398524, 'mean_word_length': 4.217943781286099, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 30, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '672228', 'n_tokens_mistral': 4378, 'n_tokens_neox': 4045, 'n_words': 1586}