Archive for the ‘Just Develop It’ Category
Without an existing cassandra service script, I decided to go ahead and create one, to make things a little easier to manage, and to make the whole experience a little more user friendly
The script includes a few nodetool basics, such as repair, cleanup, info, netstats etc. And will log the start and end times in its own log for repair and cleanup, allowing you to see how long the process takes without having the trawl through all the cassandra logs to find a start and end time (very useful for us when it takes over 5 hours to complete a repair).
Here is the script, simply copy the content into /etc/init.d/cassandra and make it executable
#!/bin/bash
#
# Author: Brooke Bryan
#
#
# Description: Cassandra Server.
# Processname: cassandra
# Config: /usr/local/share/cassandra/conf/cassandra.yaml
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
prog="Cassandra"
pidfile="/var/run/cassandra.pid"
progbin="/usr/local/share/cassandra/bin"
lock="/var/lock/subsys/cassandra"
logfile="/var/log/cassandra/service.log"
WriteLog()
{
echo "`date`: $@" >> $logfile
}
LogInfo()
{
echo "$@"
WriteLog "INFO: $@"
}
LogWarning()
{
echo "$@"
WriteLog "WARNING: $@"
}
start()
{
if [ -f $pidfile ] && checkpid `cat $pidfile`; then
action "$prog is already running." /bin/false
exit 0
fi
WriteLog "Starting $prog"
daemon "$progbin/cassandra" -p $pidfile >> $logfile 2>&1
usleep 500000
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
touch "$lock"
action "Starting $prog" /bin/true
else
action "Starting $prog" /bin/false
fi
WriteLog "Started $prog"
return $RETVAL
}
stop()
{
$progbin/nodetool -h localhost disablethrift
$progbin/nodetool -h localhost disablegossip
$progbin/nodetool -h localhost drain
WriteLog "Stopping $prog"
CASSIEPID=`cat "$pidfile" 2>/dev/null `
if [ -n "$CASSIEPID" ]; then
/bin/kill "$CASSIEPID" >/dev/null 2>&1
ret=$?
if [ $ret -eq 0 ]; then
STOPTIMEOUT=60
while [ $STOPTIMEOUT -gt 0 ]; do
/bin/kill -0 "$CASSIEPID" >/dev/null 2>&1 || break
sleep 1
let STOPTIMEOUT=${STOPTIMEOUT}-1
done
if [ $STOPTIMEOUT -eq 0 ]; then
echo "Timeout error occurred trying to stop $prog Daemon"
ret=1
action $"Stopping $prog: " /bin/false
LogInfo "Timeout error occurred trying to stop $prog Daemon pid($CASSIEPID)"
else
rm -f "$lock"
action $"Stopping $prog: " /bin/true
WriteLog "INFO: $prog Daemon Stopped pid($CASSIEPID)"
fi
else
action $"Stopping $prog: " /bin/false
WriteLog "WARNING: $prog Daemon Stop Failed pid($CASSIEPID)"
fi
else
ret=1
action $"Stopping $prog: " /bin/false
fi
return $ret
}
restart()
{
LogInfo "Restart Initiated"
stop
start
}
ring()
{
$progbin/nodetool -h localhost ring
}
info()
{
$progbin/nodetool -h localhost info
}
netstats()
{
$progbin/nodetool -h localhost netstats
}
repair()
{
LogInfo "Starting Repair"
$progbin/nodetool -h localhost repair
LogInfo "Completed Repair"
}
cleanup()
{
LogInfo "Starting Cleanup"
$progbin/nodetool -h localhost cleanup
LogInfo "Completed Cleanup"
}
version()
{
$progbin/nodetool -h localhost version
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status cassandra
;;
restart)
restart
;;
ring)
ring
;;
info)
info
;;
netstats)
netstats
;;
repair)
repair
;;
cleanup)
cleanup
;;
version)
version
;;
*)
echo $"Usage: $0 {start|stop|status|restart|ring|info|netstats|repair|cleanup|version}"
exit 1
esac
exit $?
Just a quick post on how-to install cassandra on Centos 5, and getting the required bits on to stop all the errors you will see, such as JNA and MX4J missing.
First you need to get all the required modules from yum, to prepare the server.
yum -y install gcc-c++ make cmake python-devel bzip2-devel zlib-devel
yum -y install log4cpp-devel git git-core cronolog google-perftools-devel
yum -y install readline-devel ncurses-devel libtool autoconf expat
yum -y install libevent-devel flex byacc expat-devel
# Perl Modules for Thrift Install
yum -y install perl-Bit-Vector perl-Class-Accessor
# Java Install
yum -y remove jpackage-utils
wget http://dev.centos.org/centos/5/testing/x86_64/RPMS/jpackage-utils-1.7.5-1jpp.1.el5.centos.noarch.rpm
rpm -ivh jpackage-utils-1.7.5-1jpp.1.el5.centos.noarch.rpm
yum -y install xml-commons-apis xml-commons-apis-javadoc ant
yum -y install java
yum -y install log4j jakarta-commons-logging jakarta-commons-lang
yum -y install java-1.4.2-gcj-compat java-1.4.2-gcj-compat-devel
Next you will want to download the latest version of cassandra available at http://cassandra.apache.org/download/
I have chosen to install cassandra in the following location: /usr/local/share/cassandra
wget http://mirror.ox.ac.uk/sites/rsync.apache.org//cassandra/0.8.4/apache-cassandra-0.8.4-bin.tar.gz
tar -xvf apache-cassandra-0.8.4-bin.tar.gz
mkdir /usr/local/share/cassandra/
cp ~/apache-cassandra-0.8.4/* /usr/local/share/cassandra -R -f;
cd /usr/local/share/cassandra
Installing JNA is done as follows:
wget “https://github.com/twall/jna/raw/3.3.0/jnalib/dist/jna.jar” –no-check-certificate -O /usr/local/share/cassandra/lib/jna.jar
chmod 755 /usr/local/share/cassandra/lib/jna.jar
MX4J is installed with:
wget “http://downloads.sourceforge.net/project/mx4j/MX4J%20Binary/3.0.2/mx4j-3.0.2.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmx4j%2Ffiles%2FMX4J%2520Binary%2F3.0.2%2F&ts=1314263784&use_mirror=freefr”
tar zxvf mx4j-3.0.2.tar.gz mx4j-3.0.2/lib/mx4j-tools.jar
cp mx4j-3.0.2/lib/mx4j-tools.jar /usr/local/share/cassandra/lib/
chmod 755 /usr/local/share/cassandra/lib/mx4j-tools.jar
Switching to Sun Java
You will need to download the latest JDK from SUN, and can switch from OpenJDK with the following
rpm /root/jdk-7-linux-x64.rpm -ivh
/usr/sbin/alternatives –install /usr/bin/java java /usr/java/jdk1.7.0/bin/java 2 && /usr/sbin/alternatives –config java
Just enter the number of the new JDK in the selection above, and hit enter (on a fresh install, its usually #3)
Finishing up.
After you have everything above done, you should just be able to edit the config file /usr/local/share/cassandra/conf/cassandra.yaml, and then run cassandra /usr/local/share/cassandra/bin/cassandra
If you are running a cluster setup with cassandra, you can use a token calculator such as http://blog.milford.io/cassandra-token-calculator/ which will evenly spread the data across your nodes.
Also be sure to set your commit log and data directory on different disks.
The best option I have found is having the commitlog and OS on an SSD drive, and the data stored on a Raid 0 disk array with SAS drives. You want to make sure you have at least double the space available on disk as what you will be consuming with your nodes.
A few weeks back Jordan (designer @ Just Develop It) brought in his rubiks cube into the office and we were all amazed that he could complete the cube. The fact he could do it in under 5 minutes just added to the amazement. Between writing code and sleeping, Rich and myself found ourselves trying to solve the cube wondering what logic we could apply to come to a solution. After about a week not being able to complete more than the first 2 layers I cracked and looked around youtube.com for a way to complete the cube.
Much to my suprise, there was a logical way to solve the cube based on a few algorithms. Easy when you know how
So, the youtube video I found was by pogobat and made the cube easy to understand. You can see the video here: http://uk.youtube.com/watch?v=HsQIoPyfQzM. The algorithms for the cube are as follows:
- Fi U Li Ui
- Ri Di R D
- U R Ui Ri Ui Fi U F
- Ui Li U L U F Ui Fi
- F R U Ri Ui Fi
- R U Ri U R U U Ri
- U R Ui Li U Ri Ui L
- Ri Di R D
Ok, the letters above dont mean very much unless you can watched the video. You always need to hold the cube in the same position for any of this to work
F = The face closest to you (Front)
U = The face on the top (Up)
L = The face in your left hand (Left)
R = The face in your right hand (Right)
D = The face on the bottom of the cube (Down)
There is also i. This stands for ‘inverted’ or ‘counter clockwise’
If you see Ri, you should turn the right face counter clockwise. Should you see R you should turn the right face clockwise. Be sure to only move that one face and not rotate the cube, else it will all end in disaster
Once I got to grips with the algorithms, everything slotted into place and I could complete the cube serveral times in one night. Its a very impressive skill to learn.
Get yourself onto youtube.com and watch the video linked above and learn the cube for yourself
After adding the status.justuptime.com feature last week, we in the JDI office have taken full advantage of the system and have it on our main development screen and I even have it on my docked iPhone (sorta like a third screen
).
Everyone in the office is able to keep an eye on all of our servers and someone can quickly jump onto fix any problems that come up. One of our servers was seen to be down earlier so I took a photo, the server was back up and running within 2 minutes of going down thanks to the quick response system we have setup at Just Host so all is good
.
Why not get your website or servers into JustUptime.com and make life easy for yourself. Automate the way you monitor your uptime and get the reports you need to keep your eye on the ball.
Being the first friday in the month, I thought I should introduct a new item to the development room. We now have the ‘Friday Feature’ where we work on a ‘nice to have’ feature for one of our products. These features will generally be quick bits which add some ‘cool’ to our products.
Just Uptime was the first product to have the JDIFF, and I thought an iPhone site to check the status of all your checks within the system would be pretty cool. Any Just Uptime user is able to login to the new service which can be found at http://status.justuptime.com, this page can be viewed from any mobile device as well as your web browser, however, it was designed for the iPhone.
The service puts all checks found to be down at the top of the list making it easier for you to spot any problems as and when they come up and the page auto refreshes every 60 seconds.
I took some screenshots of the system so you can see it in action just below.
At Just Develop It we are always investing in new businesses and developing new products.

The picture above is a photo of the whiteboard in my office with a list of all our current JDI projects. The 2 lines with something missing are simply new projects which i decided to hide until we announce them















