How to deploy a neo4j instance in Amazon EC2 in 10 minutes
The Cloud Zone is brought to you in partnership with Iron.io. Discover how Microservices have transformed the way developers are building and deploying applications in the era of modern cloud infrastructure.
Neo4j is a high-performance, NOSQL graph database with all the features of a mature and robust database. In this post I will explain how to deploy a neo4j instance in Amazon EC2 web service.
For this tutorial to take you no more than 10 minutes you should be able to execute properly some bash commands like mv, tar, ssh and scp (secure copy). I also assume that you have an account in Amazon Web Services and you are familiar to the process of launching instances. If not, I strongly recommend you to follow this starting guide and complete it till you manage to connect to your instance with ssh.
Start downloading the latest stable version of neo4j. Which you can find here. The “Community Edition” fits well for development purposes. Do not forget to select the Unix version of the server. This will download a tar.gz file which you will copy to your EC2 instance later.
While you download the neo4j server open the AWS Management Console and launch a Basic 32-bit Amazon Linux AMI. If you want to launch an Ubuntu AMI please notice that it doesn’t ship with Java, which is required for running neo4j.
If you are not familiar with key pairs, pem files or security groups I insist you to follow the EC2 starting guide I mentioned above. You can either create a new security group or use the default, but you will need to configure a new security rule for the neo4j server port.
After launching the instance, create a TCP rule on port 7474 with source 0.0.0.0/0. Here you are opening port 7474 for anyone. If you are planning to use the neo4j REST API and remotely call it from another server, for example a Rails application hosted in Heroku, for security reasons, you may want to change the source field to the address of your Heroku server.
Do not forget to open port 22 (SSH), this is typically the first rule normal people create after launching an instance.
You are almost done! You should now install neo4j in your instance. Open a terminal in your localhost and navigate to the path where you downloaded neo4j. Copy the file to your Amazon instance by using the scp command:
scp -i your_pem_file.pem neo4j-community-1.6.M01-unix.tar.gz ec2-user@YOUR_PUBLIC_INSTANCE_DNS:/home/ec2-user
Please notice that you will need to change the path to your pem file, typically placed in ~/.ssh, the filename of the neo4j server you just downloaded and the plublic DNS of your instance.
Now connect to your instance with SSH:
ssh -i your_pem_file.pem ec2-user@YOUR_PUBLIC_INSTANCE_DNS
Untar the neo4j server:
tar xvfz neo4j-community-1.6.M01-unix.tar.gz.tar.gz
Move it to /usr/local and rename the folder to neo4j:
sudo mv neo4j-community-1.6.M01 /usr/local/neo4j
Almost done!!! You should now open neo4j-server.properties under the conf directory and add the following line:
This lines allows anyone to connect remotely to your neo4j database server.
Now run the start script. From the neo4j server folder.
sudo ./bin/neo4j start
Finally, open a browser and access the webadmin interface of your neo4j database by typing http://YOUR_PUBLIC_INSTANCE_DNS:7474. You should see the Neo4j Monitoring and Management Tool, pretty cool!
If not, ask me
You can now try using the REST API and the curl bash command to insert nodes and relationships.
I hope this post helped you, good luck! Follow me on Twitter @negarnil