Cassandra DB is needed for capturing and storing vCloud Director metrics data so that it can be displayed in portal to end users so that users are aware of VM resource utilization etc.
Prior to vCD v9.0, we needed kairosdb + cassandra together for capturing and storing the metrics data, but things have changed now. VMware has removed the requirement of kairosdb and now metrics data can be sent straight to cassandra database. This metric data in turn can be viewed in tenant UI.
As per vCD 9.0 documentation
Cassandra is an open source database that you can use to provide the backing store for a scalable, high-performance solution for collecting time series data like virtual machine metrics. If you want vCloud Director to support retrieval of historic metrics from virtual machines, you must install and configure a Cassandra cluster and use the cell-management-tool to connect the cluster to vCloud Director. Retrieval of current metrics does not require optional database software.
If you are new to Cassandra, then In past I have wrote some blog posts about cassandra architecture and how it works. Feel free to read those posts from below links:
2: Understanding Cassandra Read/Write Mechanism
3: Installing Cassandra on RHEL6
In production you may want a Cassandra cluster with minimum 3-4 nodes, but in lab environment 1 or two nodes is sufficient. In my lab I am running only two node. I am configuring Cassandra on my CentOS 6 box.
vCD 9.0 needs Cassandra version 2.2.6 which can be downloaded from here
Before installing cassandra, we need to install jdk 1.7 or later and set the JAVA_HOME variable. Instructions for this is covered in blog link given above. Although the same blog have steps for installing cassandra, I am including the steps here as well.
Follow below steps for a successful installation of cassandra.
1: Create cassandra user with sudo permissions.
You can use below script which will create a user on server with sudo permissions.
1 2 3 4 5 |
# wget https://raw.githubusercontent.com/zubayr/create_user_script/master/create_user_script.sh # chmod 777 create_user_script.sh # sh create_user_script.sh -s cassandra |
2: Verify presence of cassandra user/group
1 2 3 4 5 |
[root@cassdb01 ~]# cat /etc/passwd | grep cassandra cassandra:x:501:501::/home/cassandra:/bin/bash [root@cassdb01 ~]# cat /etc/group | grep cassandra cassandra:x:501: |
3: Extract cassandra zip file and setup cassandra directory structure
1 2 3 4 5 6 7 8 9 |
# cp /root/apache-cassandra-2.2.6-bin.tar.gz /opt/ # cd /opt; # tar -zxvf apache-cassandra-2.2.6-bin.tar.gz # ln -s /opt/apache-cassandra-2.6 /opt/apache-cassandra # mkdir -p /var/lib/cassandra/{data,commitlog};mkdir -p /var/log/cassandra |
4: Set ownership of directories to cassandra
1 2 3 |
# chown cassandra:cassandra -R /opt/apache-cassandra;chown cassandra:cassandra -R /opt/apache-cassandra-2.6 # chown -R cassandra:cassandra /var/lib/cassandra/data;chown -R cassandra:cassandra /var/log/cassandra/;chown -R cassandra:cassandra /var/lib/cassandra/commitlog |
5: Create script for installing cassandra as a service
Create a file named cassandra with below contents:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
#!/bin/bash # init script for Cassandra. # chkconfig: 2345 90 10 # description: Cassandra . /etc/rc.d/init.d/functions CASS_HOME=/opt/apache-cassandra CASS_BIN=$CASS_HOME/bin/cassandra CASS_LOG=/var/log/cassandra/system.log CASS_USER="root" CASS_PID=/var/run/cassandra.pid if [ ! -f $CASS_BIN ]; then echo "File not found: $CASS_BIN" exit 1 fi RETVAL=0 start() { if [ -f $CASS_PID ] && checkpid `cat $CASS_PID`; then echo "Cassandra is already running." exit 0 fi echo -n $"Starting $prog: " daemon --user $CASS_USER $CASS_BIN -p $CASS_PID -R >> $CASS_LOG 2>&1 usleep 500000 RETVAL=$? if [ "$RETVAL" = "0" ]; then echo_success else echo_failure fi echo return $RETVAL } stop() { # check if the process is already stopped by seeing if the pid file exists. if [ ! -f $CASS_PID ]; then echo "Cassandra is already stopped." exit 0 fi echo -n $"Stopping $prog: " if kill `cat $CASS_PID`; then RETVAL=0 echo_success else RETVAL=1 echo_failure fi echo [ $RETVAL = 0 ] } status_fn() { if [ -f $CASS_PID ] && checkpid `cat $CASS_PID`; then echo "Cassandra is running." exit 0 else echo "Cassandra is stopped." exit 1 fi } case "$1" in start) start ;; stop) stop ;; status) status_fn ;; restart) stop usleep 500000 start ;; *) echo $"Usage: $prog {start|stop|restart|status}" RETVAL=3 esac exit $RETVAL |
6: Add cassandra to chkconfig
1 2 3 4 5 |
# cp /root/cassandra /etc/init.d # chkconfig --add cassandra # chkconfig cassandra on |
7: Modify cassandra.yaml file as shown below
1 2 3 4 5 6 7 8 9 10 11 |
# echo auto_bootstrap: true >> /opt/apache-cassandra/conf/cassandra.yaml # echo data_file_directories: /var/lib/cassandra/data >> /opt/apache-cassandra/conf/cassandra.yaml # echo commitlog_directory: /var/lib/cassandra/commitlog >> /opt/apache-cassandra/conf/cassandra.yaml # NODEIP=$(/sbin/ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}') # sed -i "s/listen_address: localhost/listen_address: ${NODEIP}/g" /opt/apache-cassandra/conf/cassandra.yaml # sed -i "s/rpc_address: localhost/rpc_address: ${NODEIP}/g" /opt/apache-cassandra/conf/cassandra.yaml |
8: Start Cassandra service
1 2 3 4 5 |
[root@cassdb-mgmt-a init.d]# service cassandra start Starting : [ OK ] [root@cassdb-mgmt-a init.d]# service cassandra status Cassandra is running. |
Now cassandra node is configured. Next is to configure vCD to send metrics data to cassandra. We will discuss this in Next post.
I hope you find this post informational. Feel free to share this on social media if it is worth sharing. Be sociable 🙂