Mongodb. NoSQL data bases replication.

(versión español)

The subject that concerns us today is MongoDB. It is a NoSQL database that is based on a model document oriented.
Today we’ll explain how to install it and how to enable replication of data across multiple servers.

Mongodb installation.

Although each distribution has its own packages ready to be installed with the appropriate package manager, it is best to install the packages from 10gen, which are MongoDB developers.

Installing on Ubuntu.

To import the 10gen GPG public key, run the following:
$ sudo apt-key adv –keyserver keyserver.ubuntu.com –recv 7F0CEB10

Create the /etc/apt/sources.list.d/10gen.list file and include the following line to the 10gen repository.
:$ deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen

Upgrade the repository with:
$: sudo apt-get update

And install the package:
:$ sudo apt-get install mongodb-10gen

You can start the daemon with the command:
:$ service mongodb start

Installing on Cenos.

Create the /etc/yum.repos.d/10gen.repo file. To store information about the repository, add the following lines:
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0
enabled=1

If your operating system is 64-bit, add these lines:
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
enabled=1

To install MongoDB, run this command:
:$ yum install mongo-10gen mongo-10gen-server

You can start the daemon with the command:
:$ service mongodb start

Configuring replication.

The configuration file of Mongodb is in the path /etc/mongodb.conf (in Ubuntu) or /etc/ mongod.conf (in Centos).

In this practical example, we will implement a replication system of three Mongodb servers using the method «Replica set». This method consists of an asynchronous type of «master/slave» replication, which allows automatic failover and recovery of member nodes in the system.

Servidor 1:
Hostname: mongo_server1.domain.com

Servidor 2
Hostname: mongo_server2.domain.com

Servidor 3
Hosname: mongo_server3.domain.com

Edit the /etc/mongodb.conf (Ubuntu) or /etc/mongod.conf (Centos), and change or add the following lines to make it like this:

port = 27017
bind_ip = 10.8.0.10
fork = true
replSet = rs0

To add a bit of security, you can force MongoDB to listen in an specific interface, and not in all (as the default). To do this add to the configuration file the following line:

bind_ip = 192.168.2.5
In this directive put the ip of the network interface for which you want to listen to the MongoDB daemon.

Restart MongoDB in each of the servers.

Now go to the «mongo_server1.dominio.com» server and run this command:
:$ mongo

With this command you enter MongoDB console. Now we have to start replication with the following command:
MongoDB shell version: 2.2.0
connecting to: test
> rs.initiate();

At this time «mongo_server1» is the primary server.

Then add the other 2 servers:
MongoDB shell version: 2.2.0
connecting to: test
> rs.add(«mongo_server2.domino.com»);
> rs.add(«mongo_server3.dominio.com»);

You can check the status of data replication system with rs.status() command.

For production environments with a replica set of 2 members, which is not recommended, or with an even number of them, you must create an arbiter.

Arbiters are mongod instances that do not receive a copy of the data. They are only participating in the elections, when the primary server goes down, to choose a new primary.

An arbiter do not manage copies of data, so it does not need a lot of resources and require no additional hardware. So you can install the arbiter on any other server you want, but never in the primary or the secondary.
To create an arbiter, connect to the primary Mongodb server shell, as you did above and run this:
MongoDB shell version: 2.2.0
connecting to: test
> rs.addArb(«[hostname]:[port]»)

As that is used to add nodes to the replication system are the hostnames, each server in the group must be able to get the ip of the other two, so you should use a DNS server to resolve the IP of each server or use the /etc/hosts file.

Install your own virtual machine

(versión en español)

This article opens a section dedicated to virtualization of a server to host virtual machines. Now is very popular in the world of hosting to use a virtual machine as a virtual private server (VPS). Thus, from a server with high processing power, memory, hard disk, multiple virtual private servers can be created.

In this first article I will try libvirt with kvm hypervisor,

Sigue leyendo