Tuesday, September 18, 2012

Install Apache Cassandra on CentOS


Install Apache Cassandra on CentOS:
1. Download cassandra:
# cd /opt
#wget ftp://apache.sunsite.ualberta.ca/pub/apache/cassandra/1.1.5/apache-cassandra-1.1.5-bin.tar.gz 
2.Create dirctories for the following keywords in cassandra.yaml file :
data_file_directories
commitlog_directory
saved_caches_directory
# sudo mkdir -p /var/lib/cassandra/data
# sudo mkdir -p /var/log/cassandra
# sudo mkdir -p /var/lib/cassandra/saved_caches
It is better to use separate disks for commitlog and data
# sudo mkdir -p /dev/shm/cassandra/commitlog
modify configuration file(cassandra.yaml), make sure the directories you just created match with the path in the configuration file.
Edit the log4j-server.properties, make sure the path is correct as created from above commands.
log4j.appender.R.File=/var/log/cassandra/system.log


3. Create softlink
# ln -s apache-cassandra-1.1.5 /opt/cassandra
4. Make cassandra as a service,
# sudo vim /etc/init.d/cassandra
and copy&paste the following script into /etc/init.d/cassandra
-------------------------------------------------------

#!/bin/bash
# init script for Cassandra.
# chkconfig: 2345 90 10
# description: Cassandra
# script slightly modified from
# http://blog.milford.io/2010/06/installing-apache-cassandra-on-centos/

. /etc/rc.d/init.d/functions

CASS_HOME=/opt/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 >> $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
------------------------------------------------------
//end of service script
start or stop cassandra service
# sudo chmod +x /etc/init.d/cassandra
# sudo service cassandra start
# sudo service cassandra stop
bring cassandra alive when reboot:
# sudo chmod +x /etc/init.d/cassandra
# sudo chkconfig --add cassandra
# sudo chkconfig cassandra on

REFERENCE:




12 comments:

  1. Önemli giriş adreslerine buradan ulaşabilirsiniz.
    betturkey giriş
    betpark giriş
    WZBM47

    ReplyDelete