Skip to content

[DEPRECARED] Neo4J setup guide

Pouria Ezzati edited this page Oct 24, 2019 · 1 revision

🚧 DEPRECATED!1!! 🚧

⚠️ This guide is for Kutt v1 where Neo4j is used as the database. In Kutt v2 we use PostgreSQL and you don't to install or config Neo4j.

I basically just followed Neo4j's official documentation on how to install it on Debian. Important things is to make sure you have Java 8 installed on your machine and if you have multiple versions of Java installed, then read their docs on how to deal with it. This is the steps I went through:

Install Java 8

sudo apt-get update
sudo apt-get install default-jre

Add the repository

wget -O - https://debian.neo4j.org/neotechnology.gpg.key | sudo apt-key add -
echo 'deb https://debian.neo4j.org/repo stable/' | sudo tee -a /etc/apt/sources.list.d/neo4j.list
sudo apt-get update

Install Neo4j

sudo apt-get install neo4j=1:3.5.5

Set password for database

You can change the password using the desktop app too.

neo4j-admin set-initial-password YOUR_PASSWORD_HERE

Config Neo4j

The path for config file in Debian is /etc/neo4j/neo4j.conf. Find the path of config file for your machine in their docs.

You can find the full reference for the config file in Configuration settings. The only thing I'd usually change is to allow the database to be available remotely:

# Bolt connector
dbms.connector.bolt.enabled=true
dbms.connector.bolt.tls_level=OPTIONAL
dbms.connector.bolt.listen_address=0.0.0.0:7687

I have also updated the settings for the amount of RAM that Neo4j needs to take. You probably don't need to change this since Neo4j will calculate it based on available resources.

dbms.memory.heap.initial_size=1024m
dbms.memory.heap.max_size=1024m

Start

Start the database:

sudo service neo4j start

Assing indexes and constraints

Now we need a way to run some CYPHER queries. You can run commands in CLI by using cypher-shell but I like to run queries on the desktop app's browser. For some of these queries you might need to create some links and visit them to create records in the database.

First gonna add index to link nodes, it reduce the time that it takes to get links:

CREATE INDEX ON :URL(id)

Then let's add some constraints, to make sure we don't get duplicated views in our database:

CREATE CONSTRAINT ON (d:DATE) ASSERT d.date IS UNIQUE
CREATE CONSTRAINT ON (o:OS) ASSERT o.os IS UNIQUE
CREATE CONSTRAINT ON (r:REFERRER) ASSERT r.referrer IS UNIQUE
CREATE CONSTRAINT ON (c:COUNTRY) ASSERT c.country IS UNIQUE
CREATE CONSTRAINT ON (b:BROWSER) ASSERT b.browser IS UNIQUE