Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ha/routing/HA_register.cypherl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ADD COORDINATOR 1 WITH CONFIG {"bolt_server": "localhost:7691", "coordinator_server": "coord1:10111", "management_server": "coord1:12121"};
ADD COORDINATOR 2 WITH CONFIG {"bolt_server": "localhost:7692", "coordinator_server": "coord2:10112", "management_server": "coord2:12122"};
ADD COORDINATOR 3 WITH CONFIG {"bolt_server": "localhost:7693", "coordinator_server": "coord3:10113", "management_server": "coord3:12123"};

REGISTER INSTANCE instance_1 WITH CONFIG {"bolt_server": "localhost:7687", "management_server": "instance1:13011", "replication_server": "instance1:10001"};
REGISTER INSTANCE instance_2 WITH CONFIG {"bolt_server": "localhost:7688", "management_server": "instance2:13012", "replication_server": "instance2:10002"};
REGISTER INSTANCE instance_3 WITH CONFIG {"bolt_server": "localhost:7689", "management_server": "instance3:13013", "replication_server": "instance3:10003"};
SET INSTANCE instance_1 TO MAIN;
27 changes: 27 additions & 0 deletions ha/routing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

# Memgraph HA deployment with docker compose

This example demonstrates how to deploy Memgraph in a high availability mode with docker compose.

## 🚀 How to Run Memgraph with Docker

1. First, adjust the license in the `license.cypherl` file by providing your organization name and license key.
2. To run Memgraph, simply do the following command:

```bash
docker compose up
```


## 🔖 Version Compatibility

This example was built and tested with:

- **Memgraph MAGE v3.2.0**

If you run into any issues or have questions, feel free to reach out on the [Memgraph Discord server](https://discord.gg/memgraph). We're happy to help!


## 🏢 Enterprise or Community?

> 🛑 This example **requires Memgraph Enterprise**.
123 changes: 123 additions & 0 deletions ha/routing/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
services:
coord1:
image: "memgraph/memgraph-mage:3.2"
container_name: coord1
volumes:
- ./license.cypherl:/tmp/init/license.cypherl:ro
- ./HA_register.cypherl:/tmp/init/HA_register.cypherl:ro
- mg_lib1:/var/lib/memgraph
- mg_log1:/var/log/memgraph
environment:
- MEMGRAPH_HA_CLUSTER_INIT_QUERIES=/tmp/init/HA_register.cypherl
command: ["--init-file=/tmp/init/license.cypherl", "--log-level=TRACE", "--also-log-to-stderr", "--bolt-port=7691", "--coordinator-id=1", "--coordinator-port=10111", "--management-port=12121", "--coordinator-hostname=coord1", "--nuraft-log-file=/var/log/memgraph/nuraft"]
networks:
memgraph_ha:
ipv4_address: 172.21.0.4
ports:
- "7691:7691"
depends_on:
- instance1
- instance2
- instance3

coord2:
image: "memgraph/memgraph-mage:3.2"
container_name: coord2
volumes:
- ./license.cypherl:/tmp/init/license.cypherl:ro
- mg_lib2:/var/lib/memgraph
- mg_log2:/var/log/memgraph
command: [ "--init-file=/tmp/init/license.cypherl", "--log-level=TRACE", "--also-log-to-stderr", "--bolt-port=7692", "--coordinator-id=2", "--coordinator-port=10112", "--management-port=12122", "--coordinator-hostname=coord2" , "--nuraft-log-file=/var/log/memgraph/nuraft"]
networks:
memgraph_ha:
ipv4_address: 172.21.0.2
ports:
- "7692:7692"
depends_on:
- instance1
- instance2
- instance3

coord3:
image: "memgraph/memgraph-mage:3.2"
container_name: coord3
volumes:
- ./license.cypherl:/tmp/init/license.cypherl:ro
- mg_lib3:/var/lib/memgraph
- mg_log3:/var/log/memgraph
command: [ "--init-file=/tmp/init/license.cypherl", "--log-level=TRACE", "--also-log-to-stderr", "--bolt-port=7693", "--coordinator-id=3", "--coordinator-port=10113", "--management-port=12123", "--coordinator-hostname=coord3" , "--nuraft-log-file=/var/log/memgraph/nuraft"]

networks:
memgraph_ha:
ipv4_address: 172.21.0.3
ports:
- "7693:7693"
depends_on:
- instance1
- instance2
- instance3

instance1:
image: "memgraph/memgraph-mage:3.2"
container_name: instance1
volumes:
- ./license.cypherl:/tmp/init/license.cypherl:ro
- mg_lib4:/var/lib/memgraph
- mg_log4:/var/log/memgraph
command: ["--init-file=/tmp/init/license.cypherl", "--log-level=TRACE", "--also-log-to-stderr", "--bolt-port=7687", "--management-port=13011"]
networks:
memgraph_ha:
ipv4_address: 172.21.0.6
ports:
- "7687:7687"

instance2:
image: "memgraph/memgraph-mage:3.2"
container_name: instance2
volumes:
- ./license.cypherl:/tmp/init/license.cypherl:ro
- mg_lib5:/var/lib/memgraph
- mg_log5:/var/log/memgraph
command: ["--init-file=/tmp/init/license.cypherl", "--log-level=TRACE", "--also-log-to-stderr", "--bolt-port=7688", "--management-port=13012"]
networks:
memgraph_ha:
ipv4_address: 172.21.0.7
ports:
- "7688:7688"

instance3:
image: "memgraph/memgraph-mage:3.2"
container_name: instance3
volumes:
- ./license.cypherl:/tmp/init/license.cypherl:ro
- mg_lib6:/var/lib/memgraph
- mg_log6:/var/log/memgraph
command: ["--init-file=/tmp/init/license.cypherl", "--log-level=TRACE", "--also-log-to-stderr", "--bolt-port=7689", "--management-port=13013"]
networks:
memgraph_ha:
ipv4_address: 172.21.0.8
ports:
- "7689:7689"

volumes:
mg_lib1:
mg_lib2:
mg_lib3:
mg_lib4:
mg_lib5:
mg_lib6:
mg_log1:
mg_log2:
mg_log3:
mg_log4:
mg_log5:
mg_log6:

networks:
memgraph_ha:
name: memgraph_ha
driver: bridge
ipam:
driver: default
config:
- subnet: "172.21.0.0/16"
2 changes: 2 additions & 0 deletions ha/routing/license.cypherl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SET DATABASE SETTING 'organization.name' TO '<YOUR_ORGANIZATION_NAME>';
SET DATABASE SETTING 'enterprise.license' TO '<YOUR_ENTERPRISE_LICENSE>';
Empty file added ha/routing/requirements.txt
Empty file.
17 changes: 17 additions & 0 deletions ha/routing/routing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from neo4j import GraphDatabase

def execute_query(tx, query):
tx.run(query)

uris = ["neo4j://localhost:7691", "neo4j://localhost:7692", "neo4j://localhost:7693"]
for uri in uris:
driver = GraphDatabase.driver(uri, auth=("", ""))
with driver.session() as session:
session.execute_write(execute_query, "CREATE (n)")
driver.close()

for uri in uris:
driver = GraphDatabase.driver(uri, auth=("", ""))
with driver.session() as session:
session.execute_read(execute_query, "MATCH (n) RETURN n")
driver.close()