Neo4j

Basic Concepts

Neo4j is an open-source native graph database management system developed in Java. Unlike traditional relational databases, it does not use table structures (Schema-less) but stores and manages structured data in the form of graphs.

Core Features

  1. Native Graph Storage:

    • Data is stored as nodes and relationships
    • Nodes represent entities (such as people, places, things)
    • Relationships represent connections between nodes (such as “friend”, “belongs to”)
  2. Transaction Support:

    • Full ACID (Atomicity, Consistency, Isolation, Durability) transaction support
  3. Storage Architecture:

    • Embedded database design, can be directly integrated into Java applications
    • Disk-based persistent storage

Environment Setup

Container Setup

# docker-compose.yml
services:
  neo4j:
    image: neo4j:5.26
    container_name: neo4j
    ports:
      - "7474:7474"   # HTTP
      - "7687:7687"   # Bolt
    environment:
      NEO4J_AUTH: neo4j/neo4j123   # Change password on first login
      NEO4J_server_default__listen__address: 0.0.0.0
      NEO4J_server_default__advertised__address: ${HOST_IP:-127.0.0.1}
      NEO4J_server_memory_heap_max__size: 2G
      NEO4J_server_memory_pagecache_size: 1G
    volumes:
      - ./data:/data
      - ./logs:/logs
      - ./conf:/var/lib/neo4j/conf

Run initialization script after startup:

CREATE (e1:Emp {name:"Zhang San"})-[:WORKS_FOR {since:2018}]->(d1:Dept {name:"R&D Department"});
CREATE (e2:Emp {name:"Li Si"})-[:WORKS_FOR {since:2020}]->(d1);
CREATE INDEX emp_name IF NOT EXISTS FOR (e:Emp) ON (e.name);
CREATE INDEX dept_name IF NOT EXISTS FOR (d:Dept) ON (d.name);

Service Setup

cd /opt/software
wget https://neo4j.com/artifact.php?name=neo4j-community-3.5.17-unix.tar.gz
tar -zxvf neo4j-community-3.5.17-unix.tar.gz
mv neo4j-community-3.5.17 ../servers/

Modify configuration for remote access:

dbms.connectors.default_listen_address=0.0.0.0

Start service:

./bin/neo4j start

Access http://10.10.52.38:7474/browser/, default username and password are both neo4j