Book Image

Building web applications with Python and Neo4j

By : Sumit Gupta
Book Image

Building web applications with Python and Neo4j

By: Sumit Gupta

Overview of this book

Table of Contents (14 chapters)
Building Web Applications with Python and Neo4j
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Licensing and configuring – Neo4j


Neo4j is an open source graph database, which means all its sources are available to the public (currently on GitHub at https://github.com/neo4j/neo4j). However, Neo Technology, the company behind Neo4j, distributes the latter in two different editions—the Community edition and Enterprise edition. Let's briefly discuss the licensing policy for the Community and Enterprise editions, and then we will talk about the installation procedures on the Unix/Linux operating systems.

Licensing – Community Edition

Community Edition is a single node installation licensed under General Public License (GPL) Version 3 (http://en.wikipedia.org/wiki/GNU_General_Public_License) and is used for the following purposes:

  • Preproduction environments, such as development or QA for fast paced developments

  • Small to medium scale applications where it is preferred to embed the database within the existing application

  • Research and development where advanced monitoring and high performance is not the focus

You can benefit from the support of the whole Neo4j community on Stack Overflow, Google Groups, and Twitter.

Note

If you plan to ask a question on Stack Overflow, do not forget to tag your question with the #Neo4j hashtag.

Licensing – Enterprise Edition

Enterprise Edition comes with three different kinds of subscription options and provides the distributed deployment of the Neo4j databases, along with various other features, such as backup, recovery, replication, and so on.

  • Personal license: It is free of charge and may look very similar to Community Edition. It targets students, as well as small businesses.

  • Startup program: Starting from this plan, you can benefit from the enterprise support. A startup license allows workday support hours—10 hours per 5 business days.

  • Enterprise subscriptions: With this plan, you can benefit from 24/7 support and emergency custom patches if needed. At this scale, your company will have to directly contact Neo Technology to assess the cost of your required setup.

    Note

    The license defines instance as the Java Virtual Machine hosting a Neo4j server.

Each of the subscription is subject to its own license and pricing. Visit http://neo4j.com/subscriptions/ for more information about available subscriptions with Enterprise Edition.

Installing Neo4J Community Edition on Linux/Unix

In this section, we will talk about the Neo4j installation on the Linux/Unix operating system. At the end of this section, you will have a fully-functional Neo4j instance running on your Linux/Unix desktop/server.

Let's perform the following common steps involved in the Neo4j installation on Linux/Unix:

  1. Download and install Oracle Java 7 (http://www.oracle.com/technetwork/java/javase/install-linux-self-extracting-138783.html) or open JDK 7 (https://jdk7.java.net/download.html).

  2. Set JAVA_HOME as an environment variable and the value of this variable will be the file system path of your JDK installation directory:

    export JAVA_HOME=<Path of Java install Dir>
  3. Download the stable release of the Linux distribution, neo4j-community-2.2.0-RC01-unix.tar.gz, from http://neo4j.com/download/other-releases/.

Neo4j can be installed and executed as a Linux service, or it can also be downloaded as the .tar file, where, after installation, it needs to be started manually.

Let's talk about the steps involved in installing Neo4j as a service, and then we will also talk about the standalone archive.

Installing as a Linux tar / standalone application

Architects have always preferred to install critical applications as a Linux service, but there can be reasons, such as insufficient privileges, which restrict you from installing software as a Linux service. So, whenever you cannot install software as a Linux service, there is another way in which you can download Neo4j, perform manual configuration, and start using it.

Let's perform the following steps to install Neo4j as a Linux tar / standalone application:

  1. Once you have downloaded the Neo4j archive, browse the directory from where you want to extract the Neo4j server and untar the Linux/Unix archive: tar –xf <location of Archive file>. Let's refer to the top-level extracted directory as $NEO4J_HOME.

  2. Open the Linux shell or console and execute the following commands for starting the sever:

    • <$NEO4J_HOME>/bin/neo4j - start: This command is used for running the server in a new process

    • <$NEO4J_HOME>/bin/neo4j - console: This command is used for running the server in the same process or window without forking a new process

    • <$NEO4J_HOME>/bin/neo4j - restart: This command is used for restarting the server

  3. Browse http://localhost:7474/browser/ and you will see the login screen of the Neo4j browser.

  4. Enter the default username/password as neo4j/neo4j and press Enter. The next screen will ask you to change the default password.

  5. Change the password and make sure that you remember it. We will use this new password in the upcoming examples.

  6. Stop the server by pressing Ctrl + C or by typing <$NEO4J_HOME>/bin/neo4j - stop.

Installing as a Linux service

This is the most preferred procedure for installing Neo4j in all kinds of environments, whether it's production, development, or QA. Installing Neo4j as a Linux service helps a Neo4j server and database to be available for use at server start-up and also survive user logons/logoffs. It also provides various other benefits such as ease of installation, configuration, and up-gradation.

Let's perform the following steps and install Neo4j as a Linux service:

  1. Once the Neo4j archive is downloaded, browse the directory from where you want to extract the Neo4j server and untar the Linux/Unix archive: tar –xf <location of Archive file>. Let's refer to the top-level extracted directory as $NEO4J_HOME.

  2. Change the directory to $NEO4J_HOME; and execute the command, sudo bin/neo4j neo4j-installer install; and follow the steps as they appear on the screen.

    Note

    The installation procedure will provide an option to select the user that will be used to run the Neo4j server. You can supply any existing or new Linux user (defaults to Neo4j). If a user is not present, it will be created as a system account and the ownership of <$NEO4J_HOME>/data will be moved to that user.

  3. Once the installation is successfully completed, execute sudo service neo4j-service start on the Linux console for starting the server and sudo service neo4j-service stop for gracefully stopping the server.

  4. Browse http://localhost:7474/browser/ and you will see the login screen of the Neo4j browser.

  5. Enter the default username/password as neo4j/neo4j and press Enter. The next screen will ask you to change the default password.

  6. Change the password and make sure that you remember it. We will use this new password in the upcoming examples.

    Note

    To access the Neo4j browser on remote machines, enable and modify org.neo4j.server.webserver.address in neo4j-server.properties and restart the server.

Installing Neo4j Enterprise Edition on Unix/Linux

High availability, fault tolerance, replication, backup, and recovery are a few of the notable features provided by Neo4j Enterprise Edition. Setting up a cluster of Neo4j nodes is quite similar to the single node setup, except for a few properties which need to be modified for the identification of node in a cluster.

Let's perform the following steps for installing Neo4j Enterprise Edition on Linux:

  1. Download and install Oracle Java 7 (http://www.oracle.com/technetwork/java/javase/install-linux-self-extracting-138783.html) or open JDK 7 (https://jdk7.java.net/download.html).

  2. Set JAVA_HOME as the environment variable and the value of this variable will be the file system path of your JDK installation directory:

    export JAVA_HOME=<Path of Java install Dir>
  3. Download the stable release of the Linux distribution, neo4j-community-2.2.0-RC01-unix.tar.gz from http://neo4j.com/download/other-releases/.

  4. Once downloaded, extract the archive into any of the selected folders and let's refer to the top-level extracted directory as $NEO4J_HOME.

  5. Open <$NEO4J_HOME>\conf\neo4j-server.properties and enable/modify the following properties:

    • org.neo4j.server.database.mode=HA: Keep this value as HA, which means high availability. You can run it as a standalone too by providing the value as SINGLE.

    • org.neo4j.server.webserver.address=0.0.0.0: This property enables and provides the IP of the node for enabling remote access.

  6. Open <$NEO4J_HOME>\conf\neo4j.properties and enable/modify the following properties:

    • ha.server_id=: This property is the unique ID of each node that will participate in the cluster. It should be an integer (1, 2, or 3).

    • ha.cluster_server=192.168.0.1:5001: This property is the IP address and port for communicating the cluster status information with other instances.

    • ha.server=192.168.0.1:6001: This property is the IP address and port for the node for communicating the transactional data with other instances.

    • ha.initial_hosts=192.168.0.1:5001,192.168.0.2:5001: This property is a comma-separated list of host:port (ha.cluster_server) where all nodes will be listening. This will be the same for all the nodes participating in the same cluster.

    • remote_shell_enabled=true: Enable this property for connecting the server remotely through the shell.

    • remote_shell_host=127.0.0.1: This property enables and provides an IP address where remote shell will be listening.

    • remote_shell_port=1337: This property enables and provides the port at which shell will listen. You can keep it as default in case the default port is not being used by any other process.

  7. Open <$NEO4J_HOME>/bin, execute ./neo4j start and you are done. Stop the server by pressing Ctrl + C or by typing ./neo4j stop.

  8. Browse http://<IP>:7474/browser/ for interactive shell, and on the login screen, enter the default username/password as neo4j/neo4j and press Enter.

  9. The next screen will ask you to change the default password. Change the password and make sure that you remember it. We will use this new password in the upcoming examples.