Quantcast
Channel: linoxide.com
Viewing all articles
Browse latest Browse all 1507

How to Install and Use Arango Database on Ubuntu16.04

$
0
0

Arango database (ArangoDB) is a multi-model database system, meaning one that uses combination of Key-Value pairs, documents and graphs to store data. It has a flexible data model for documents and graphs. It is a general purpose database and provides all features that are needed for a modern web application. Because of the web interface that it provides, the database is easy to use. Latest version (v3.0) of it was released on June 23rd. It comes with improved capabilities.  In this tutorial, we will understand how to install and use ArangoDB v3.0.2 on Ubuntu 16.04.

Installation

Before proceeding with installation, we need to setup the repository by downloading the public key(Release Key) from the  repositories, adding it and the repository.

NOTE:Please precede all commands with 'sudo' if you are not the root user.

Execute the following command:

$ wget https://www.arangodb.com/repositories/arangodb3/xUbuntu_16.04/Release.key

This will save the Release.key in the current directory. The output of this command will be as follows:

root@ubuntu:~# wget https://www.arangodb.com/repositories/arangodb3/xUbuntu_16.04/Release.key
--2016-07-13 13:47:53--

https://www.arangodb.com/repositories/arangodb3/xUbuntu_16.04/Release.key
Resolving www.arangodb.com (www.arangodb.com)... 85.214.140.94
Connecting to www.arangodb.com (www.arangodb.com)|85.214.140.94|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1003 [application/pgp-keys]
Saving to: ‘Release.key’

Release.key 100%[===================>] 1003 --.-KB/s in 0s

2016-07-13 13:47:55 (41.4 MB/s) - ‘Release.key’ saved [1003/1003]

Let us now add this key.

$ apt-key add Release.key

We can add the repository by using 'apt-add-repository' command. This requires installing 'software-properties-common'. If not already installed, install this first and then proceed to add the repository.

$ apt install software-properties-common

$ apt-add-repository 'deb https://www.arangodb.com/repositories/arangodb3/xUbuntu_16.04/ /'

$ apt-get update

Now we are ready to install ArangoDB3

$ apt-get-install arangodb3=3.0.2

While configuring the packages, it asks for entering a password for the database root user account. Once provided, it will go and setup the database completely.

Configuring packages

This command installs and starts the ArangoDB. We can verify if the database is running by executing the following command:

$ service arangodb status

Here is the output from the above command:

root@ubuntu:~# service arangodb status
● arangodb3.service - LSB: arangodb
Loaded: loaded (/etc/init.d/arangodb3; bad; vendor preset: enabled)
Active: active (running) since Wed 2016-07-13 13:59:40 UTC; 18min ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/arangodb3.service
├─14720 /usr/sbin/arangod --uid arangodb --gid arangodb --pid-file /var/run/arangodb/arangod.pid --temp.path /var/tmp/arangod --log.
└─14721 /usr/sbin/arangod --uid arangodb --gid arangodb --pid-file /var/run/arangodb/arangod.pid --temp.path /var/tmp/arangod --log.

Jul 13 13:59:37 ubuntu systemd[1]: Starting LSB: arangodb...
Jul 13 13:59:37 ubuntu arangodb3[14662]: * Starting arango database server arangod
Jul 13 13:59:40 ubuntu arangodb3[14662]: {startup} starting up in daemon mode
Jul 13 13:59:40 ubuntu arangodb3[14662]: ...done.
Jul 13 13:59:40 ubuntu systemd[1]: Started LSB: arangodb.
Jul 13 13:59:40 ubuntu arangodb3[14662]: changed working directory for child process to '/var/tmp'

Accessing ArangoDB using command line

ArangoDB ships 'arangosh' which is the command line interface to access the DB. We can perform all administrative tasks from this client itself.  This is invoked by executing the 'arangosh' command:

$ arangosh

When asked for a password, provide the one that was given at the time of installing the package.

ArangoDB CLI

If we need any help within the shell, we can execute the help() command within.

arangosh [_system]> db._help();

Creating a user

When the ArangoDB is installed first, it by default, creates a database '_system'  and user 'root'. We can either add users within this database or create our own database and add users to it. In order to add a user into the _system database, execute the following command:

arangosh [_system]> require("org/arangodb/users").save(userid, password);

It produces an output similar to what is shown below:

127.0.0.1:8529@_system> require("org/arangodb/users").save("user1", "userpwd1");

{
"user" : "user1",
"active" : true,
"extra" : {
},
"changePassword" : false,
"code" : 201
}

The  examples in the following picture show how to create a new database using arangosh and add a user to it.

Commands to create a db and users

As you can see, a new database by name 'sample' is created. We can switch to this DB using 'useDatabase' command and then create users within it.

Granting access to a user

By default, users will not have permissions to access any database. We can grant the access rights to one or more databases by using 'grantDatabase()' command. A user who has access to the _system() database is known as the superuser.

user.grantDatabase(user, db)

In the first example, lets give 'user1' permissions to access the _system() DB.

arangosh [_system]> require("org/arangodb/users").grantDatabase("user1","_system");

Revoking  a user

To revoke the access to a database for a user, we can use the 'revokeDatabase' command.

users.grantDatabase(user, database)

Example:

arangosh [_system]> require("org/arangodb/users").revokeDatabase("user1","_system");

A few other useful commands

 Replace - Looks up an existing ArangoDB user and replaces its user data

users.replace(user, password, active, extra)

Example:

arangosh [_system]> require("org/arangodb/users").replace("user1", "new_passwd");

This function will not work from the web interface.

Update - Update an existing ArangoDB user with a new password and other data

users.update(user, password, active, extra)

Example:

arangosh [_system]> require("org/arangodb/users").update("user1", "updated_passwd");

isValid - Verify whether a given combination of user and password is valid or not

users.isValid(user, password)

Example:

arangosh [_system]> require("org/arangodb/users").isValid("user1", "updated_passwd");

true

all - List all the existing users of the database

users.all()

Example:

arangosh [_system]> require("org/arangodb/users").all();

remove - Remove an existing user from the database

users.remove(user)

Example:

arangosh [_system]> require("org/arangodb/users").remove("user1");

Document - Fetch an existing user from the ArangoDB database

users.document(user)

Example:

arangosh [_system]> require("org/arangodb/users").document("user1");

This command fails if the user is not found in the database.

ArangoDB Web Interface

ArangoDB provides a built-in web interface for performing administrative tasks. Before accessing it, we need to set up the server's access point.

Configuration

Configuration files arangod.conf and arangosh.conf are located in '/etc/arangodb3'. They need to be edited to add the server's IP address against the line containing 'endpoint'.

root@ubuntu:~# vi /etc/arangodb3/arangod.conf

endpoint = tcp://139.162.53.68:8529

root@ubuntu:~# vi /etc/arangodb3/arangosh.conf

[server]
endpoint = tcp://139.162.53.68:8529
authentication = true

In the latest version, authentication is enabled by default. Hence, no need to change it.  Let us now restart the arangodb service.

service arangodb3 restart

Access

To access the database from your browser, point it to the following if you are on the local system :

http://localhost:8529

or provide the ip-address of the server and the port if you are accessing from a remote system's browser:

http://your-server-ip:8529

This will open up the login screen for the _system db by default.

ArangoDb login screen

If you want to switch to a different database, provide the database name in the URL as shown:

http://your-server-ip:8529/_db/sample

Once you login using username and password, you will see the below screen:

ArangoDB WebInterface - Dashboard

Database Management

If we go to the 'Databases' section, we will be able to see the databases that we created using the arangosh interface. To create a new database, click on 'Add Database'.  This pops up a screen asking for database name and the user. Enter these details and press the 'create' button.

Creating a new DB

Collections and Documents

Collections are like tables in an RDBMS. We can create documents in these collections and store the required data.

Creating collections

Go the 'Collections' section and click on 'Add Collection'. Provide the name of the new collection to be created and save.

New Collection

Creating Documents

The newly created collection will not have any document in it. Documents can be compared to rows in a table. To create a new document, click on the green colored '+' sign on the upper right hand corner of the screen. Provide a key if necessary and press on the 'create' button.

Create a new document

Adding Data to documents

We are now ready to add some data into the newly created document.  Open the document that was previously created and change the editor mode to 'Code'.

Changing editor mode

Now let us fill up the editor with some data (JSON object) for the document.

{
"tutorialName": "How to install ArangoDB3",
"platform": "Ubuntu16.04",
"documentType": "Tutorial",
"covers": [
"installation",
"shellinterface",
"webinterface"]
}

Save the data and change back the editor mode to Tree again for some human readable data format

Data in tree mode

ArangoDB Query Language(AQL)

ArangoDB ships with it, a query editor known as the AQL editor. With the help of this, we can send queries to get results from the configured database servers. It can be used for simple as well as complex queries. One can query across collections, iterate over graphs etc.

Query submission

As seen from the above image,  submitting the query 'Return Linux_Tutorial' and pressing the 'Execute' button gives an output similar to what is shown below:

Result of a Query

Conclusion

In this tutorial, we have learnt how to install the latest version of ArangoDB on Ubuntu 16.04 and a quick overview of its features including arangosh and the web interface. It combines the flexibility of document-type of databases and the power of graph databases. Being an open-source database with a flexible data model, it lets the user build high performance applications. Now that you know how to use it, go give it a try!

The post How to Install and Use Arango Database on Ubuntu16.04 appeared first on LinOxide.


Viewing all articles
Browse latest Browse all 1507