[This blog was syndicated from http://blog.grallandco.com]
Introduction
When I was looking for a more effective way to create my cluster I asked some sysadmins which tools I should use to do it. The answer I got during OSDC was not Puppet, nor Chef, but was Ansible.
This article shows you how you can easily configure and create a Couchbase cluster deployed and many linux boxes…and the only thing you need on these boxes is an SSH Server!
Thanks to Jan-Piet Mens that was one of the person that convinced me to use Ansible and answered questions I had about Ansible.
You can watch the demonstration below, and/or look at all the details in the next paragraph.
Ansible
Ansible is an open-source software that allows administrator to configure and manage many computers over SSH.
I won't go in all the details about the installation, just follow the steps documented in the Getting Started Guide. As you can see from this guide, you just need Python and few other libraries and clone Ansible project from Github. So I am expecting that you have Ansible working with your various servers on which you want to deploy Couchbase.
Also for this first scripts I am using root on my server to do all the operations. So be sure you have register the root ssh keys to your administration server, from where you are running the Ansible scripts.
Create a Couchbase Cluster
So before going into the details of the Ansible script it is interesting to explain how you create a Couchbase Cluster. So here are the 5 steps to create and configure a cluster:
Install Couchbase on each nodes of the cluster, as documented here.
Take one of the node and “initialize” the cluster, using cluster-init command.
Add the other nodes to the cluster, using server-add command.
So the goal now is to create an Ansible Playbook that executes these steps for you.
Ansible Playbook for Couchbase
The first think you need is to have the list of hosts you want to target, so I have create a hosts file that contains all my server organized in 2 groups:
The group [couchbase-main] group is just one of the node that will drive the installation and configuration, as you probably already know, Couchbase does not have any master… All nodes in the cluster are identical.
To ease the configuration of the cluster, I have create another file that contains all parameters that must be sent to all the various commands. This file is located in the group_vars/all see the section Splitting Out Host and Group Specific Data in the documentation.
# Adminisrator user and password admin_user: Administrator admin_password: password
# ram quota for the cluster cluster_ram_quota: 1024
# bucket and replicas bucket_name: ansible bucket_ram_quota: 512 num_replicas: 2
Now we need to execute specific taks on the “main” server:
Initialization of the cluster using the Couchbase CLI, on line 06 and 07
Then the system needs to ask all other server to join the cluster. For this the system needs to get the various IP and for each IP address execute the add-server command with the IP address. As far as I know it is not possible to get the IP address from the main playbook YAML file, so I ask the system to generate a shell script to add each node and execute the script.
I am adding the -vv parameter to allow you to see more information about what's happening during the execution of the script.
This will execute all the commands described in the playbook, and after few seconds you will have a new cluster ready to be used! You can for example open a browser and go to the Couchase Administration Console and check that your cluster is configured as expected.
As you can see it is really easy and fast to create a new cluster using Ansible.
I have also create a script to uninstall properly the cluster.. just launch
Jennifer Garcia is a Senior Web Manager at Couchbase Inc. As the website manager, Jennifer has overall responsibility for the website properties including design, implementation, content, and performance.
I tried to use the recipe to install couchdb on EC2, there was a small modification I should add. the cluster-init command failed due to \’Connection refused\’ error. Apparently the server was not up yet so I added the a pause command for 30 senconds before the cluster-init and boom, it worked! The code: – name: Sleep for 30 seconds to finish installation pause: seconds=30
You can also check out following. Running multi-node cluster using Virtualbox/Centos (or ubuntu) instances using vagrant/ansible. Just works, assuming all parameters set properly. I was up and running in 20 mins . Make sure you are online while doing since it downloads bunch a stuff to make this happen.
This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
Thanks, DevOps Consult
rather than using a script template, you should use
with_items
ansible statement:– name: add nodes
shell: \”/opt/couchbase/bin/couchbase-cli server-add -c 127.0.0.1:8091 -u {{couchbase_admin}} -p {{couchbase_admin_password}} –server-add={{ hostvars[item][\’ansible_eth0\’][\’ipv4\’][\’address\’] }}:8091 –server-add-username={{couchbase_admin}} –server-add-password={{couchbase_admin_password}}\”
with_items: groups[\’couchbase-nodes\’]
this loops the ansible task. (Did you know ansible was awesome ? :) )
Thanks for this I will test and update my playbook…
I really like Ansible and your advice make it even better !
I tried to use the recipe to install couchdb on EC2, there was a small modification I should add. the cluster-init command failed due to \’Connection refused\’ error. Apparently the server was not up yet so I added the a pause command for 30 senconds before the cluster-init and boom, it worked!
The code:
– name: Sleep for 30 seconds to finish installation
pause: seconds=30
what a good night\’s sleep can do :)
You can also check out following. Running multi-node cluster using Virtualbox/Centos (or ubuntu) instances using vagrant/ansible. Just works, assuming all parameters set properly. I was up and running in 20 mins . Make sure you are online while doing since it downloads bunch a stuff to make this happen.
https://github.com/couchbasela…
This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
Thanks,
DevOps Consult