Published on Sep 5 2017 in Java

Neo4j is graph database written in Java. As such it can be run on our private JVM products under regular user on shared cPanel-based server.

In this tutorial we will set it up on our basic product Tomcat which has enough resources for demonstrating setup but for production you will need to upgrade at least JVM heap. See Neo4j system requirements for production.

Default configuration is made for runnng Neo4j as root on a VPS or dedicated server. A few changes are required to run it as regular user. Instead of systemctl-based system service Neo4j can be started from /etc/rc.local using autostart (on server boot) feature provided by host to user’s JVM. Simply make sure you have local alias command js that starts Neo4j (neo4j start) and it will be run while server boots.

As Neo4j will start embedded server, it does not need the default application server. You may do one of the following:

Installing and configuring Neo4j as regular user

Download, unzip, create easy access link, update environment variables and config file.

wget --content-disposition 'https://neo4j.com/artifact.php?name=neo4j-community-3.2.3-unix.tar.gz'
tar xzf neo4j-community-3.2.3-unix.tar.gz 
ln -s neo4j-community-3.2.3 neo4j
cat>>~/.bashrc<<EOF
export NEO4J_HOME=/home/neo4j/neo4j
export JAVA_HOME=/opt/jdk1.8.0_73
export PATH=\$PATH:\$NEO4J_HOME/bin:\$JAVA_HOME/bin
EOF
source ~/.bashrc

Now you need to update configuration settings specific to shared server in $NEO4J_HOME/conf/neo4j.conf

sed -ri 's/^#?dbms.memory.heap.initial_size=.*/dbms.memory.heap.initial_size=128m/' $NEO4J_HOME/conf/neo4j.conf
sed -ri 's/^#?dbms.memory.heap.max_size=.*/dbms.memory.heap.max_size=128m/' $NEO4J_HOME/conf/neo4j.conf
sed -ri 's/^#?dbms.memory.pagecache.size=.*/dbms.memory.pagecache.size=128m/' $NEO4J_HOME/conf/neo4j.conf
sed -ri 's/^#?#dbms.connectors.default_listen_address=.*/dbms.connectors.default_listen_address=0.0.0.0/' $NEO4J_HOME/conf/neo4j.conf
sed -ri 's/^#?dbms.connector.bolt.listen_address=.*/dbms.connector.bolt.listen_address=:11088/' $NEO4J_HOME/conf/neo4j.conf
sed -ri 's/^#?dbms.connector.http.listen_address=.*/dbms.connector.http.listen_address=:11089/' $NEO4J_HOME/conf/neo4j.conf
sed -ri 's/^#?dbms.connector.https.listen_address=.*/dbms.connector.https.listen_address=:11090/' $NEO4J_HOME/conf/neo4j.conf

In production setup you will probably also need to configure a commercial (or not self-signed) SSL certificate.

Starting Neo4j

The binary is now in your PATH so you can call it just by typing neo4j with one of the following parameters: console, start, stop, restart, status, version.

[email protected] [~]# neo4j start
Active database: graph.db
Directories in use:
  home:         /home/neo4j/neo4j
  config:       /home/neo4j/neo4j/conf
  logs:         /home/neo4j/neo4j/logs
  plugins:      /home/neo4j/neo4j/plugins
  import:       /home/neo4j/neo4j/import
  data:         /home/neo4j/neo4j/data
  certificates: /home/neo4j/neo4j/certificates
  run:          /home/neo4j/neo4j/run
Starting Neo4j.
WARNING: Max 1024 open files allowed, minimum of 40000 recommended. See the Neo4j manual.
Started neo4j (pid 13736). It is available at http://0.0.0.0:11089/
There may be a short delay until the server is ready.
See /home/neo4j/neo4j/logs/neo4j.log for current status.

Use default credentials. User and password are ‘neo4j’.

neo4j1.png

You will then be asked to set a new password.

neo4j2.png

Then you can create first graph as prompted with the ‘Hello World’ example.

neo4j3.png

Example graph representation follows.

neo4j4.png

Idle system with 2 example nodes uses 26MB of JVM heap.

Feel free to post your comments and contact us if you have any questions related to hosting Neo4j or any other Java app.