CentOS 6 – Cassandra
DevFrançaisLinuxTutorials
NetInstall minimal puis :
yum -y update yum -y install wget openssh-clients nmap
Ajoutons notre hostname à la fin du fichier host
vi /etc/hosts
Installation du jdk
wget -c https://blog.quidquid.fr/jdk/jdk-7u51-linux-x64.tar.gz tar zxf jdk-7u51-linux-x64.tar.gz rm -f jdk-7u51-linux-x64.tar.gz mv jdk1.7.0_51 /opt/ chown -R root:root /opt/jdk1.7.0_51 ln -s /opt/jdk1.7.0_51 /opt/jdk cat >> ~/.bashrc << "EOF" # ------------------------- export JAVA_HOME=/opt/jdk PATH=$PATH:$JAVA_HOME/bin EOF [/shell] Installation de cassandra: [shell] wget -c http://wwwftp.ciril.fr/pub/apache/cassandra/2.0.5/apache-cassandra-2.0.5-bin.tar.gz tar zxf apache-cassandra-2.0.5-bin.tar.gz mv apache-cassandra-2.0.5 /opt/ rm -f apache-cassandra-2.0.5-bin.tar.gz ln -s /opt/apache-cassandra-2.0.5 /opt/apache-cassandra groupadd cassandra useradd -g cassandra cassandra cat >> /home/cassandra/.bashrc << "EOF" # ------------------------- export JAVA_HOME=/opt/jdk PATH=$PATH:$JAVA_HOME/bin EOF mkdir /opt/apache-cassandra/log chown -R cassandra:cassandra /opt/apache-cassandra chown -R cassandra:cassandra /opt/apache-cassandra-2.0.5 [/shell] Création du launcher : [shell] cat >> /etc/init.d/cassandra << "EOF" #!/bin/bash # chkconfig: 2345 99 01 # Description: Cassandra Server. # Processname: cassandra # Config: $CASSANDRA_HOME/conf/cassandra.yaml # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network CASSANDRA_HOME=/opt/apache-cassandra prog="Cassandra" pidfile="/var/run/cassandra.pid" progbin="$CASSANDRA_HOME/bin" lock="/var/lock/subsys/cassandra" logfile="$CASSANDRA_HOME/log/service-cassandra.log" WriteLog() { echo "<code>date</code>: $@" >> $logfile } LogInfo() { echo "$@" WriteLog "INFO: $@" } LogWarning() { echo "$@" WriteLog "WARNING: $@" } start() { if [ -f $pidfile ] && checkpid <code>cat $pidfile</code>; 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=<code>cat "$pidfile" 2>/dev/null </code> 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 $? EOF
Affectation des droits
chmod a+x /etc/init.d/cassandra
On renomme notre cluster, qui par défaut est Test Cluster, en SANGOKU, dans le fichier de configuration :
sed -i 's:Test Cluster:SANGOKU:' /opt/apache-cassandra/conf/cassandra.yaml
Reste à démarrer cassandra :
/etc/init.d/cassandra start
Et un petit coup de chkconfig histoire de lancer le tout au demarrage:
chkconfig --level 3 cassandra on chkconfig --level 06 cassandra off
Leave a comment