Skip to content

Neo4j Setup Guide

Shirley Cohen edited this page Oct 29, 2021 · 6 revisions

Follow this guide to set up your Neo4j environment for this class.

Run these commands on your Jupyter notebook instance:

  1. Start up your Jupyter notebook instance and open a terminal window. Run the following commands in the terminal:

  2. Install OpenJDK:
    echo 'deb http://ftp.debian.org/debian stretch-backports main' | sudo tee /etc/apt/sources.list.d/stretch-backports.list
    sudo apt update
    sudo apt install openjdk-11-jdk
    java -version

Expected output:
(base) jupyter@notebook:~$ java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2deb10u1, mixed mode, sharing)

  1. Get Neo4j binaries:
    gsutil cp gs://cs327e-open-access/neo4j-community-4.3.3-unix.tar .
    tar -xvf neo4j-community-4.3.3-unix.tar

  2. Add neo4j to your PATH by adding this line to your .bash_profile (not on your terminal):

export PATH=$PATH:/home/jupyter/neo4j-community-4.3.3/bin

  1. Run source .bash_profile to reload your PATH.

  2. Start Neo4j:
    neo4j console

Expected output:
(base) jupyter@notebook:~$ neo4j console
Directories in use:
home: /home/jupyter/neo4j-community-4.3.3
config: /home/jupyter/neo4j-community-4.3.3/conf
logs: /home/jupyter/neo4j-community-4.3.3/logs
plugins: /home/jupyter/neo4j-community-4.3.3/plugins
import: /home/jupyter/neo4j-community-4.3.3/import
data: /home/jupyter/neo4j-community-4.3.3/data
certificates: /home/jupyter/neo4j-community-4.3.3/certificates
licenses: /home/jupyter/neo4j-community-4.3.3/licenses
run: /home/jupyter/neo4j-community-4.3.3/run
Starting Neo4j.
2021-10-29 14:43:25.252+0000 INFO Starting...
2021-10-29 14:43:27.162+0000 INFO ======== Neo4j 4.3.3 ========
2021-10-29 14:43:28.907+0000 INFO Initializing system graph model for component 'security-users' with version -1 and status UNINITIALIZED
2021-10-29 14:43:28.913+0000 INFO Setting up initial user from defaults: neo4j
2021-10-29 14:43:28.913+0000 INFO Creating new user 'neo4j' (passwordChangeRequired=true, suspended=false)
2021-10-29 14:43:28.922+0000 INFO Setting version for 'security-users' to 3
2021-10-29 14:43:28.925+0000 INFO After initialization of system graph model component 'security-users' have version 3 and status CURRENT
2021-10-29 14:43:28.928+0000 INFO Performing postInitialization step for component 'security-users' with version 3 and status CURRENT
2021-10-29 14:43:29.183+0000 INFO Bolt enabled on localhost:7687.
2021-10-29 14:43:29.975+0000 INFO Remote interface available at http://localhost:7474/
2021-10-29 14:43:29.977+0000 INFO Started.

Before running steps 7 and 8, open up a new terminal in your notebook. Then, run the following commands in the new terminal without closing the first one off.

  1. Set DB Password:
    neo4j-admin set-initial-password neo4j
    **NOTE: If the above command does not work, double check your .bash_profile to make sure it is updated per step 4.

  2. Test Database Connection:
    cypher-shell -u neo4j -p neo4j

When prompted to change your password, enter a new password. Make sure you remember it.

Expected output:
(base) jupyter@notebook:~$ cypher-shell -u neo4j -p neo4j
Password change required
new password: ******
Connected to Neo4j using Bolt protocol version 4.3 at neo4j://localhost:7687 as user neo4j.
Type :help for a list of available commands or :exit to exit the shell.
Note that Cypher queries must end with a semicolon.
neo4j@neo4j>

If your connection failed, troubleshoot and resolve before continuing.

After you set a new password, make sure you change the content following "-p" to your password in step 8 for future connections.

The following section is optional. If you want to graphically visualize your Neo4j database, follow the next few steps. They will need to be run on your laptop or desktop computer. Note: these steps have been tested on OSX, but not Windows. Warning: If you are a Windows user, you may run into some unexpected issues.

  1. Set up SSH tunnel for accessing Neo4j Browser:
  • Install the Cloud SDK for your OS. Use the interactive installer from here.
  • Open a terminal (OSX) or command-line window (Windows) and run gcloud init. Go through the prompts by entering your project_id and authenticating with your gmail account.
  • Set these 3 environment variables:
    export PROJECT_ID={your_project_id} (e.g. cs327e-fa2021)
    export ZONE={your_zone} (e.g. us-central1-a)
    
export INSTANCE_NAME=<your_jupyter_instance> (e.g. notebook)

Note: The export command won't work on Windows. On Windows, you'll need to use setx instead:

setx PROJECT_ID "{your_project_id}"
setx ZONE "{your_zone}"
setx INSTANCE_NAME "{your_jupyter_instance}"

  • Set up SSH tunnel:
    gcloud compute ssh --project $PROJECT_ID --zone $ZONE $INSTANCE_NAME -- -L 7474:localhost:7474 -L 7687:localhost:7687


Expected output:
$ export PROJECT_ID=cs327e-fa2021
$ export ZONE=us-central1-a
$ INSTANCE_NAME=notebook
$ gcloud compute ssh --project $PROJECT_ID --zone $ZONE $INSTANCE_NAME -- -L 7474:localhost:7474 -L 7687:localhost:7687
Updating project ssh metadata...⠹Updated [https://www.googleapis.com/compute/v1/projects/cs327e-fa2021].

Updating project ssh metadata...done.

Waiting for SSH key to propagate.
Warning: Permanently added 'compute.2211384406573025853' (ED25519) to the list of known hosts.
======================================
Welcome to the Google Deep Learning VM
======================================

Version: common-cpu.m78
Based on: Debian GNU/Linux 10 (buster) (GNU/Linux 4.19.0-18-cloud-amd64 x86_64\n)

Resources:
* Google Deep Learning Platform StackOverflow: https://stackoverflow.com/questions/tagged/google-dl-platform
* Google Cloud Documentation: https://cloud.google.com/deep-learning-vm
* Google Group: https://groups.google.com/forum/#!forum/google-dl-platform

To reinstall Nvidia driver (if needed) run:
sudo /opt/deeplearning/install-driver.sh
Linux notebook 4.19.0-18-cloud-amd64 #1 SMP Debian 4.19.208-1 (2021-09-29) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
scohen@notebook:~$

If you get any errors, stop and debug.

Very important: each time you restart your Jupyter notebook instance, you'll also need to restart Neo4j using the command neo4j console and optionally create an SSH tunnel using the gcloud compute ssh command.

Clone this wiki locally