Skip to content

Neo4j Setup

Orieus edited this page Sep 2, 2020 · 1 revision

Requirements

  • neo4j server

    • go to Community Server
    • choose your OS

    Let us denote by $NEO4J_DIR the directory where you uncompressed neo4j. Actually, you can export this as an environment variable in bash, e.g.,

    export NEO4J_DIR=/home/manu/neo4j-community-3.5.0
    

    and then copy-paste the commands below.

  • Awesome Procedures On Cypher, aka APOC

    • download the latest release (a jar file) from here. At the time of writing this, you could do

      wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.5.0.1/apoc-3.5.0.1-all.jar
      
  • GraphAware

  • Anaconda and, in particular

    Putting everything together:

    conda install pyyaml colorama pandas matplotlib tqdm
    conda install -c conda-forge ipdb
    pip install neo4j-driver mysqlclient

Setup

  • Move the downloaded jar files for APOC (just one) and GraphAware (two files) to the neo4j directory. For the above version, it would be something along the lines of

    mv  apoc-3.5.0.1-all.jar graphaware-uuid-3.5.0.53.17.jar graphaware-server-community-all-3.5.0.53.jar $NEO4J_DIR/plugins
    
  • Edit $NEO4J_DIR/conf/neo4j.conf

    • comment out the line

      dbms.directories.import=import
      

      This allows neo4j (server) read files from any location (not allowed by default for security reasons)

    • Add, e.g. at the end in Other Neo4j system properties,

      dbms.security.procedures.unrestricted=apoc.*
      

      This allows the (unrestricted) execution of APOC procedures.

    • Add settings (also at the end?) for GraphAware

      com.graphaware.runtime.enabled=true
      
      #UIDM becomes the module ID:
      com.graphaware.module.UIDM.1=com.graphaware.module.uuid.UuidBootstrapper
      
      #optional, default is uuid:
      com.graphaware.module.UIDM.uuidProperty=uuid
      
      #optional, default is false:
      com.graphaware.module.UIDM.stripHyphens=false
      
      #optional, default is all nodes:
      com.graphaware.module.UIDM.node=hasLabel('person')
      
      #optional, default is no relationships:
      #com.graphaware.module.UIDM.relationship=isType('Type1')
      
      #optional, default is uuidIndex
      com.graphaware.module.UIDM.uuidIndex=uuidIndex
      
      #optional, default is uuidRelIndex
      com.graphaware.module.UIDM.uuidRelationshipIndex=uuidRelIndex
      
    • (optional) uncomment line

      dbms.connectors.default_listen_address=0.0.0.0
      

      This allows remote connections to neo4j. You may also have to tweak the firewall settings of the machine running neo4j server.

A basic config file with the above settings (and some more) can be found here.

Starting neo4j server

In a terminal, run

$NEO4J_DIR/bin/neo4j start
  • (optional): you can check what's going on by monitoring the messages neo4j is logging:

    tail -f $NEO4J_DIR/logs/neo4j.log
    

    (Press Ctrl-C to stop)

The neo4j browser should (by default) be now accesible at http://localhost:7474/

If this is the first time...

...you'll be asked for a login and password. They are both neo4j. Next, you'll be asked to choose a new password. Anything will do, but if you choose any other than wapwap, don't forget to update the yaml parameters file.

Stoping neo4j server

In a terminal, run

$NEO4J_DIR/bin/neo4j stop

Reseting the database (in case you screw something up)

In a terminal, after stopping neo4j, run

rm -rf $NEO4J_DIR/data/databases/graph.db/

Shortcuts for developers

  • Start neo4j and monitor the log

    $NEO4J_DIR/bin/neo4j start && tail -f $NEO4J_DIR/logs/neo4j.log
    
  • Stop neo4j and reset the database

    $NEO4J_DIR/bin/neo4j stop && rm -rf $NEO4J_DIR/data/databases/graph.db/
    

files/scripts directory

Setup

The Anaconda-less part of the setup can (sort of) be automated using this script here. If you want to give it a try, you should also download the config patch and the environment file. Additionally, you might have to edit the latter. The easy thing to do is to clone the entire wiki.

Starting, stopping and resetting neo4j

In the files/scripts directory, you can also find the files start_neo4j.sh, stop_neo4j.sh and clean_neo4j.sh. They depend on the environment file.

Advanced

Multiple databases

In practice you can have several databases by keeping different conf directories. Assume you have or intend to create a new database named foo. It should go in $NEO4J_DIR/data/databases/foo (the default db goes in $NEO4J_DIR/data/databases/graph.db).

  • create a new conf directory; the default conf directory is $NEO4J_DIR/conf, but you can create another one, e.g., $NEO4J_DIR/conf_foo

  • edit $NEO4J_DIR/conf_foo/neo4j.conf and set dbms.active_database to the directory (relative to $NEO4J_DIR/data/databases) of a different database (in the above example, dbms.active_database=foo)

  • start neo4j server with

    NEO4J_CONF=$NEO4J_DIR/conf_foo $NEO4J_DIR/bin/neo4j start
    

    (notice the environment variable NEO4J_CONF being set at the beginning)

See also this post.

Clone this wiki locally