OpenSource For You

DevOps Series Ansible Deployment of the Aerospike NoSQL Database

In this 13th article in the DevOps series, we will install and set up an Aerospike NoSQL database cluster.

- By: Shakthi Kannan The author is a free software enthusiast and blogs at shakthimaa­n.com.

Aerospike is a free and open source, distribute­d NoSQL database written in C. It is primarily designed for high throughput and low latency applicatio­ns. It is a key-value store optimised for Flash storage devices and runs on *nix platforms. It can also be used as an in-memory database residing entirely on RAM. Following the CAP (Consistenc­y, High Availabili­ty, Partition Tolerance) theorem, at present, the database can be operated in AP mode. The database functions in three layers — the data storage layer, the clustering and distributi­on layer, and the client layer. As in many distribute­d databases, the server supports rolling upgrades and failover mechanisms in the cluster.

A number of client libraries for various programmin­g language environmen­ts like C, Java, Go, Python, Node.js, etc, are available to create applicatio­ns that can communicat­e with the Aerospike server. The basic data types that are supported are integer, string, bytes, double, list, map, GeoJSON and blobs (language serialised). Support for user defined functions (UDF) also exists, using the Lua programmin­g language. The Aerospike tooling ecosystem has a number of connectors for the Spring framework, Hadoop, Kafka, etc. The Aerospike Management Console (AMC) is a Web-based applicatio­n used to monitor the Aerospike cluster. The Aerospike server was first launched in 2012, and is released under the Affero General Public License.

GNU/Linux

A host system running Ubuntu 16.04.3 LTS (Xenial) with Vagrant and VirtualBox is used to launch three CentOS

6.9 virtual machines, on which the Aerospike server will be installed and set up. The Vagrant file to launch the three nodes is shown below:

BOX_IMAGE = “bento/centos-6.9” NODE_COUNT = 3 Vagrant.configure(“2”) do |config|

(1..NODE_COUNT).each do |i|

# Create Aerospike server node config.vm.define “as#{i}” do |node| node.vm.box = BOX_IMAGE node.ssh.forward_agent = true # https://github.com/mitchellh/vagrant/issues/4967 node.ssh.insert_key = false node.ssh.username = ‘vagrant’ node.ssh.password = ‘vagrant’ node.vm.network :private_network, ip: “10.0.0.#{i + 10}” node.vm.hostname = “as#{i}” node.vm.provider “virtualbox” do |vb| vb.name = “Aerospikes­erver#{i}” vb.memory = “2048” end end end end

The three instances are named ‘as1’, ‘as2’ and ‘as3’, and are assigned private IP addresses that can be accessed from the host system. The machines are brought up using the following command:

$ vagrant up

The version of Ansible used on the host system is 2.2.0.0. A project directory structure is created to store the Ansible playbooks and inventory, as follows:

ansible/inventory/vbox/ /playbooks/configurat­ion/

An ‘inventory’ file is created inside the inventory/vbox

folder, which contains access informatio­n for each node:

[nodes] as1 ansible_host=10.0.0.11 ansible_connection=ssh ansible_ user=vagrant ansible_ssh_private_key_file=~/.vagrant.d/ insecure_private_key as2 ansible_host=10.0.0.12 ansible_connection=ssh ansible_ user=vagrant ansible_ssh_private_key_file=~/.vagrant.d/ insecure_private_key as3 ansible_host=10.0.0.13 ansible_connection=ssh ansible_ user=vagrant ansible_ssh_private_key_file=~/.vagrant.d/ insecure_private_key

We also create ‘inventory/vbox/group_vars/all/all.yml’ with the following variables:

--aerospike_edition: “community” aerospike_version: “latest”

amc_version: 3.6.13

Installing Aerospike

The entire set of playbooks is available in the playbooks/ configurat­ion/aerospike.yml file. The first step is to install the Aerospike server on all the three nodes using Ansible, as shown below:

--name: Configure Aerospike cluster node hosts: nodes become: yes become_method: sudo gather_facts: true tags: [server]

tasks:

name: Create downloads directory file: path=”/home/{{ ansible_user }}/downloads” state=directory

name: Create installs directory file: path=”/home/{{ ansible_user }}/installs” state=directory

name: Download Aerospike community server (RPM) get_url: url=”http://aerospike.com/download/server/{{ aerospike_version }}/artifact/el6” dest=”/home/{{ ansible_ user }}/downloads/” register: __community_server_file

set_fact: server_version: “{{ __community_server_file.dest | basename }}” name: Extract Aerospike server command: tar xzvf “/home/{{ ansible_user }}/downloads/{{ server_version }}” C installs

name: Yum update yum: name=* update_cache=yes state=present

name: Install RPM dependenci­es become: yes become_method: sudo yum: name: “{{ item }}” state: latest with_items:

python

libselinux­python

name: Run asinstall shell: cd “/home/{{ ansible_user }}/installs/{{ server_ version | regex_replace(‘\.tgz’, ‘’) }}” && sudo ./asinstall

name: Start Aerospike server (RPM) shell: sudo service aerospike start

name: Wait for server to be up and running wait_for: port: 3000 delay: 5 state: started

The ‘downloads’ and ‘installs’ directorie­s are first created. The Aerospike server package for CentOS 6 is then downloaded and extracted. The YUM update command is used to update the software repository, following which the dependenci­es and the Aerospike server are installed. The database server is then started, and the playbook waits for the server to listen on port 3000. The above playbook can be run as follows:

$ ansiblepla­ybook i inventory/vbox/inventory playbooks/ configurat­ion/aerospike.yml tags server

Setting up a multicast cluster

The Aerospike cluster can be set up either in multi-cast or mesh mode. The following playbook configures the cluster in multicast mode:

name: Create multicast cluster hosts: nodes gather_facts: true sudo: yes tags: [multicast]

vars:

ip_address: “{{ ansible_eth1[‘ipv4’][‘address’] }}” line_address: “address {{ ip_address }}”

tasks:

name: Stop aerospike server command: service aerospike stop

name: Specify multicast configurat­ion file parameters lineinfile: dest: /etc/aerospike/aerospike.conf insertafte­r: “{{ item.insertafte­r }}” line: “{{ item.line }}” state: present with_items:

{ insertafte­r: ‘protofdmax 15000’, line: “nodeidinte­rface eth1” }

{ insertafte­r: ‘port 9918’, line: “{{ line_address }}” }

{ insertafte­r: ‘fabric’, line: “{{ line_address }} # Multicast: Specify private IP address” }

name: Update network service address replace: name: /etc/aerospike/aerospike.conf regexp: ‘address any’ replace: “address {{ ansible_eth1[‘ipv4’][‘address’] }}”

name: Start aerospike server command: service aerospike start

The above playbook can be executed using the following command:

$ ansiblepla­ybook i inventory/vbox/inventory playbooks/ configurat­ion/aerospike.yml tags multicast

You can verify the multi-cast cluster setup by logging into one of the virtual machines, and using the Aerospike Admin (asadm) tool as illustrate­d below:

[vagrant@as1 ~]$ asadm

Aerospike Interactiv­e Shell, version 0.1.15

Found 3 nodes

Online: 10.0.0.11:3000, 10.0.0.13:3000, 10.0.0.12:3000

Admin> exit [vagrant@as1 ~]$

Installing the Aerospike Management Console

The Aerospike Management Console (AMC) dashboard provides a graphical user interface (GUI) for the Aerospike server. Its installati­on playbook is as follows: name: Install Aerospike Management Console hosts: nodes become: yes become_method: sudo gather_facts: true tags: [amc]

tasks:

name: Download AMC Community RPM package get_url: url=”http://www.aerospike.com/download/amc/{{ amc_version }}/artifact/el6” dest=”/home/{{ ansible_user }}/ downloads/” register: __community_amc_file

set_fact: amc_file: “{{ __community_amc_file.dest }}”

name: Install RPM dependenci­es yum: name: “{{ item }}” state: latest with_items:

- gcc

pythondeve­l

name: Install RPM amc

command: rpm ivh “{{ amc_file }}” name: Start AMC server (RPM)

shell: sudo service amc start

The invocation of the above playbook and a sample execution run is shown below:

$ ansiblepla­ybook i inventory/vbox/inventory playbooks/ configurat­ion/aerospike.yml tags amc

PLAY [Configure Aerospike cluster node] ********************** TASK [setup] ************************************************ ok: [as2] ok: [as1] ok: [as3]

PLAY [Create multicast cluster] *****************************

TASK [setup] ************************************************ ok: [as1] ok: [as2] ok: [as3]

PLAY [Install Aerospike Management Console] ***************** TASK [setup] ************************************************ ok: [as1] ok: [as2] ok: [as3]

TASK [Download AMC Community RPM package] ******************* changed: [as2] changed: [as1] changed: [as3]

TASK [set_fact] ********************************************* ok: [as1] ok: [as2] ok: [as3]

TASK [Install RPM dependenci­es] ***************************** changed: [as1] => (item=[u’gcc’, u’pythondeve­l’]) changed: [as2] => (item=[u’gcc’, u’pythondeve­l’]) changed: [as3] => (item=[u’gcc’, u’pythondeve­l’])

TASK [Install RPM amc] ************************************** changed: [as1] changed: [as2] changed: [as3]

TASK [Start AMC server (RPM)] ******************************* changed: [as1] changed: [as2] changed: [as3]

PLAY RECAP ************************************************** as1 : ok=8 changed=4 unreachabl­e=0 failed=0 as2 : ok=8 changed=4 unreachabl­e=0 failed=0 as3 : ok=8 changed=4 unreachabl­e=0 failed=0

You can now open http://10.0.0.1:8081 in a browser on the host system, and you will be prompted with a modal window, as shown in Figure 1.

You can input ‘localhost’ for the ‘Host Name’, and the AMC dashboard opens as shown in Figure 2.

Uninstalli­ng Aerospike

An uninstall playbook is written to stop the services, and uninstalls both the Aerospike Management Console (AMC) and the Aerospike server, as follows: name: Uninstall hosts: nodes become: yes become_method: sudo gather_facts: true tags: [uninstall]

tasks:

name: Stop AMC server service: name: amc state: stopped name: Uninstall RPM AMC command: yum remove aerospikea­mc* y

name: Stop server command: service aerospike stop

name: Uninstall server shell: yum remove aerospike* y

The above playbook can be run using the following command:

$ ansiblepla­ybook i inventory/vbox/inventory playbooks/ configurat­ion/aerospike.yml tags uninstall

You can read the documentat­ion at https://www.aerospike. com/docs/ to learn more about Aerospike.

 ??  ??
 ??  ?? Figure 2: AMC dashboard
Figure 2: AMC dashboard
 ??  ?? Figure 1: AMC modal window
Figure 1: AMC modal window

Newspapers in English

Newspapers from India