preface
Recently, the organization assigned a task to mirror neo4j and write a docker - compose YML implements causal clusters with a number of 3 one click deployments
Previously, I wasn't very good at dockerfile and docker compose. I have gained a lot after completing this task. Please record it
Writing Dockerfile for neo4j enterprise
The organization provides the folder of neo4j Enterprise Edition, and needs to create an image by itself through Dockerfile
Let's package the folder into a tar package for easy transmission to the machine where we operate docker
tar -zcvf neo4j.tar.gz ./ongdb-enterprise-3.6.2
After packing, go to the machine that operates docker
Create any folder
mkdir ./home/neo4jtest
Unzip the neo4j compressed package to this folder, because the operation of neo4j depends on jdk1 8 (neo4j version 3)
Also prepare a jdk1 Unzip the compressed package of 8 into it
Write a start at the same time SH dockerfile recommends using script to run commands, although our script is only two lines..
#!/bin/bash /usr/neo4j/bin/neo4j start
centos images are used to create images. You can pull them down first
docker pull centos
You can start writing Dockerfile
vim ./Dockfile
FROM centos #Switch the image directory and enter the / usr directory WORKDIR /usr #Create a jdk directory under / usr / to store jdk files RUN mkdir jdk #Create a neo4j directory under / usr / to store neo4j RUN mkdir neo4j #Copy the files in the jdk directory of the host to the / usr/jdk directory of the image ADD jdk1.8.0_321 /usr/jdk/ #Copy the files in the neo4j directory of the host to the / usr/neo4j directory of the image ADD neo4j-3.5.14 /usr/neo4j #Add startup script ADD start.sh /usr/start.sh RUN chmod +x /usr/start.sh #Setting environment variables ENV JAVA_HOME=/usr/jdk ENV JRE_HOME=$JAVA_HOME/jre ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH ENV PATH=/sbin:$JAVA_HOME/bin:$PATH #Set start command CMD /usr/start.sh && /bin/bash
It should be noted here that & & / bin / Bash is usually added to the startup command, and then - itd is added to the docker run to avoid the problem that the container can not run in the background due to automatic closing
After the file is written, enter the command to create an image
docker build -t neo4j-3.5.14 .
Test run container
Prepare folders and files for mounting neo4j clusters
Primary directory:
Secondary directory:
Copy neo4j in the conf folder. The default is neo4j Conf is used to modify the container's neo4j
After copying, add the following content at the bottom of the configuration file to enable remote access
dbms.connector.http.listen_address=0.0.0.0:7474 dbms.connector.bolt.listen_address=0.0.0.0:7687
After that, we need to set the cluster information separately
The configuration file of the neo4j1 folder is added as the leader of the cluster
dbms.mode=CORE causal_clustering.initial_discovery_members=neo4j1:5000,neo4j2:5000 causal_clustering.minimum_core_cluster_size_at_formation=2 causal_clustering.minimum_core_cluster_size_at_runtime=2 causal_clustering.discovery_type=LIST dbms.connectors.default_advertised_address=neo4j1 dbms.connectors.default_listen_address=0.0.0.0
The configuration file of the neo4j2 folder is added as a follower of the cluster
dbms.mode=CORE causal_clustering.initial_discovery_members=neo4j1:5000,neo4j2:5000 causal_clustering.minimum_core_cluster_size_at_formation=2 causal_clustering.minimum_core_cluster_size_at_runtime=2 causal_clustering.discovery_type=LIST dbms.connectors.default_advertised_address=neo4j2 dbms.connectors.default_listen_address=0.0.0.0
neo4j3 configured as a read-only node
dbms.mode=READ_REPLICA causal_clustering.initial_discovery_members=neo4j1:5000,neo4j2:5000,neo4j3:5000 causal_clustering.minimum_core_cluster_size_at_formation=3 causal_clustering.minimum_core_cluster_size_at_runtime=3 causal_clustering.discovery_type=LIST dbms.connectors.default_advertised_address=neo4j3 dbms.connectors.default_listen_address=0.0.0.0
Note that the addresses given in the configuration file are neo4j1 and neo4j2. This is because we later let the container run in the docker network. We can find the container address in this way
When ready, put the mount folder in the / home directory
Run container
Create a docker network for subsequent operations
docker network create -d bridge kgap-net
Execute the commands to start the neo4j cluster respectively: note that the container names must correspond to the neo4j1 and neo4j2 configuration files
docker run --network=kgap-net -itd --name neo4j1 -p 7474:7474 -p 7687:7687 -v /home/neo4j/neo4j1/data:/usr/neo4j/data -v /home/neo4j/neo4j1/logs:/usr/neo4j/logs -v /home/neo4j/neo4j1/conf:/usr/neo4j/conf -v /home/neo4j/neo4j1/import:/usr/neo4j/import neo4j-3.5.14:latest
docker run --network=kgap-net -itd --name neo4j2 -p 8474:7474 -p 8687:7687 -v /home/neo4j/neo4j2/data:/usr/neo4j/data -v /home/neo4j/neo4j2/logs:/usr/neo4j/logs -v /home/neo4j/neo4j2/conf:/usr/neo4j/conf -v /home/neo4j/neo4j2/import:/usr/neo4j/import neo4j-3.5.14:latest
docker run --network=kgap-net -itd --name neo4j3 -p 9474:7474 -p 9687:7687 -v /home/neo4j/neo4j3/data:/usr/neo4j/data -v /home/neo4j/neo4j3/logs:/usr/neo4j/logs -v /home/neo4j/neo4j3/conf:/usr/neo4j/conf -v /home/neo4j/neo4j3/import:/usr/neo4j/import neo4j-3.5.14:latest
Access host: 7474. The default user name and password is neo4j
View the cluster status after entering the panel:
CALL dbms.cluster.overview()
Successfully deployed to this neo4j cluster