Create a Cassandra cluster with OpsCenter on Amazon EC2

Today I played a little with Cassandra on Amazon EC2. It was a very user friendly and pleasant experience to deploy a cluster with 2 nodes in one region using DataStax OpsCenter.

First I started a m1.small instance in Amazon EC2 where I installed OpsCenter. For this I chose Centos 6, the official AMI. Before starting to install OpsCenter, we need to configure the firewall in order to be able to access it. In AWS console, under the Security group, there is “CentOS 6 -x86_64- – with Updates-6 – 2014-09-29-AutogenByAWSMP-“. We need to righ-click on it and Edit inbound rules. Here we add a new Custom TCP Rule with port 8888 and the Source IP: My IP.

Anyway, I noticed that the instance has also an iptables firewall and the port 8888 is not open. So, on the instance I did:

Now, we can install OpsCenter. All you need to do is to follow the installation guide for RPM package from DataStax:

1. Edit the file:

2. Add the repository for OpsCenter

3. Install and start OpsCenter

After the installation is finished and the service started, write in your browser: http://<YOUR_INSTANCE_IP>:8888 and you will see this nice screen.

Welcome to DataStax OpsCenter
image-154

From now on, it is pretty easy to setup a cluster with multiple nodes.

Just click “Create Brand New Cluster” and follow the steps.

You will need to add some information as in the image below:

create-cluster
image-155

  • The cluster Name
  • Your DataStax Credentials. If you do not know what these are, then you need to go to DataStax Registration page, fill your data and click “Download Now”. Don’t worry, nothing will be downloaded, but you will get an email with your username and password. These are your credentials you need to put in the form from OpsCenter.
  • The total number of nodes to be created (and installed with Cassandra) – be aware,  the current instance where OpsCenter is running is not counted. I created 2 nodes initially and I added another one later on.
  • The Amazon EC2 Credentials – these are needed because OpsCenter will launch the instances for you. You need only to select the Availability Zone and the Size of the instances.

The job is almost done. Now you need to click Build Cluster and wait while all the necessary software is installed.

cassandra-installing
image-156

After few minutes, you will have a Cassandra cluster with 2 nodes.

In the next tutorial I will describe how to add an extra node through OpsCenter to the current cluster.

Good luck!

Install SSL certificate for Nginx

Recently I bought an SSL certificate for this blog from MegaSSLStore. My website is hosted on a FreeBSD machine and served by Nginx web server. In order to install the certificate on this machine, I downloaded from MegaSSLStore the certificate and CSR+private key and I copied them on my server in /usr/local/etc/nginx/ssl

Because I have an .crt certificate and also a ca-bundle I need to combine these two files in one certificate:

After this, I changed the nginx website configuration file, in order to redirect all the traffic that is coming on http (port 80) on https (port 443).

In my website .conf file, I added a new server section in which I specified to redirect all the traffic that comes on port 80 to https, using the http response code 301 (Moved Permanently). Also in the old server section I removed the “listen 80″ directive and I added “listen 443 ssl”.

The next step is to add the certificates into the configuration file. So, again in the nginx configuration of the website:

If you use the a default nginx config file, probably you will have a line like:

I replaced this line with:

in order to avoid some vulnerabilities old versions of SSL and I removed the old line ‘ssl_ciphers’ that was containing some weak ciphers and I replaced with:

After this I reloaded the nginx config file with:

In my case, I was using a CDN to deliver some assets (js, css files or images), but because it was over http I disabled it in order to not have mixed content on the same page, until I will add the certificates also to the CDN subdomain.

Monitor an error log with python and RabbitMQ

Nowadays there are many professional solutions to monitor your application for the errors. Some web frameworks have even build-in tools or support plugins to catch the programming exceptions and act accordingly.

Anyway, I wanted just to build a simple proof of concept how to monitor the web server error file and, when an event occurs and the file is changed, the monitoring script should send out an email. To monitor the log file I used pyinotify python module. This is an implementation on top of inotify, offering an easy interface to interact with the changes of the filesystem.

Continue reading

git tags use

Today I had to read about git tags in order to be able to explain better why somebody would use tags and for what. The old (and still good) git workflow explains very well how to develop using branches but doesn’t explain too well why we create the tags and how should be used on production. It just saying “that commit on master must be tagged for easy future reference to this historical version”. If you followed that guide and now you are ready to go live with your code changes, you maybe wonder what should you do with the tag? Why did you create it. Some people would say, just leave it there, maybe somebody, in a shiny day will take a look to it. Just go to production and do git pull origin master. But I don’t this this is the purpose of the tag.

Continue reading

Switch between branches using Nginx

For some of my projects, most of the time I use two branches: master and dev and I work mostly in dev. If I need to send the url to some clients with some dev/beta features I should create another (sub)domain like dev.myproject.com and sometimes, if I forget to change some configurations about the domain name (specially with some “very intelligent” CMSes that keeps the configuration in the database) I will get an email back saying “the new feature is not working” :)

Continue reading

How to use python sched in a daemon process

Let’s assume we want to download a file (or to do some tasks) to every 5 seconds, but the condition is to not do the same task twice or more times at the same moment, even if takes more than 5 seconds. For example, we have a to download a file and this will take 8 seconds. Also, if takes more than 5 seconds, it should not wait until the next iteration, to start again (3 seconds more), but will start the download immediately.

So, the traditional cronjob/lock file combination was not suitable for my case.

Continue reading

Crashing Google Chrome on Google website

Used version of Google Chrome Version 31.0.1650.63

OS Version: Ubuntu 12.04.3 LTS, Linux work 3.2.0-57-generic #87-Ubuntu SMP Tue Nov 12 21:35:10 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

Go on Google Trends website http://www.google.com/trends/topcharts?zg=full

Click View #my2013 Gallery

Click any picture

Click the browser’s back button

Click again the browser’s back button

Crashed… or it will take between 20 seconds and 1-2 minutes to refresh that page.