在 OpenSuse 上将 Cassandra 作为服务运行

Posted

技术标签:

【中文标题】在 OpenSuse 上将 Cassandra 作为服务运行【英文标题】:Running Cassandra as a service on OpenSuse 【发布时间】:2015-11-17 08:09:38 【问题描述】:

我正在尝试在 OpenSuse (Leap 42.1) 上将 Cassandra 作为服务运行。

我尝试使用 apache-cassandra-2.1.11-bin.tar.gz 进行安装,然后从 https://gist.github.com/sgomezvillamor/5458309 复制 /etc/init.d/cassandra。然而,启动脚本并不是为 OpenSuse 设计的,正如 system.log 所说:

/etc/init.d/cassandra:第 30 行:守护进程:找不到命令。

如果有一个安装程序可以正确创建脚本,问题就不会存在,就像其他一些操作系统一样。在搜索安装包时,我找到了http://www.datastax.com/dev/blog/announcing-rpms-cassandra,并尝试在 rpm.riptano.com 中查找 rpm,但我无法确定哪个可以在 OpenSuse 中使用。

哪些软件包适用于 OpenSuse?或者,我应该如何修改 Suse 的启动脚本?

【问题讨论】:

【参考方案1】:

我会检查这些适用于 Cassandra 2.1 的说明:Installing DataStax Community 2.1 on RHEL-based systems。

我不确定这是否会让你在 OpenSUSE 系统上达到 100%,但应该会让你非常接近。

【讨论】:

【参考方案2】:

我让它与 /etc/init.d/cassandra 文件一起使用:

#!/bin/bash
#
# /etc/init.d/cassandra
#
# Startup script for Cassandra
# 
# chkconfig: 2345 20 80
# description: Starts and stops Cassandra

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

export CASSANDRA_HOME=/opt/apache-cassandra-2.1.11
export CASSANDRA_CONF=$CASSANDRA_HOME/conf
export CASSANDRA_INCLUDE=$CASSANDRA_HOME/bin/cassandra.in.sh
#export CASSANDRA_OWNR=cassandra
export CASSANDRA_OWNR=root
#NAME="cassandra"
NAME="root"
log_file=/srv/cassandra/log/cassandra.log
pid_file=/var/run/cassandra/cassandra.pid
lock_file=/var/lock/subsys/$NAME
CASSANDRA_PROG=/opt/apache-cassandra-2.1.11/bin/cassandra

# The first existing directory is used for JAVA_HOME if needed.
JVM_SEARCH_DIRS="/usr/lib/jvm/jre /usr/lib/jvm/jre-1.7.* /usr/lib/jvm/java-1.7.*/jre"

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# If JAVA_HOME has not been set, try to determine it.
if [ -z "$JAVA_HOME" ]; then
    # If java is in PATH, use a JAVA_HOME that corresponds to that. This is
    # both consistent with how the upstream startup script works, and with
    # the use of alternatives to set a system JVM (as is done on Debian and
    # Red Hat derivatives).
    java="`/usr/bin/which java 2>/dev/null`"
    if [ -n "$java" ]; then
        java=`readlink --canonicalize "$java"`
        JAVA_HOME=`dirname "\`dirname \$java\`"`
    else
        # No JAVA_HOME set and no java found in PATH; search for a JVM.
        for jdir in $JVM_SEARCH_DIRS; do
            if [ -x "$jdir/bin/java" ]; then
                JAVA_HOME="$jdir"
                break
            fi
        done
        # if JAVA_HOME is still empty here, punt.
    fi
fi
JAVA="$JAVA_HOME/bin/java"
export JAVA_HOME JAVA

case "$1" in
    start)
        # Cassandra startup
        echo -n "Starting Cassandra: "
        su $CASSANDRA_OWNR -c "$CASSANDRA_PROG -p $pid_file" > $log_file 2>&1
        retval=$?
        [ $retval -eq 0 ] && touch $lock_file
        echo "OK"
        ;;
    stop)
        # Cassandra shutdown
        echo -n "Shutdown Cassandra: "
        su $CASSANDRA_OWNR -c "kill `cat $pid_file`"
        retval=$?
        [ $retval -eq 0 ] && rm -f $lock_file
        for t in `seq 40`; do $0 status > /dev/null 2>&1 && sleep 0.5 || break; done
        # Adding a sleep here to give jmx time to wind down (CASSANDRA-4483). Not ideal...
        # Adam Holmberg suggests this, but that would break if the jmx port is changed
        # for t in `seq 40`; do netstat -tnlp | grep "0.0.0.0:7199" > /dev/null 2>&1 && sleep 0.1 || break; done
        sleep 5
        STATUS=`$0 status`
        if [[ $STATUS == "$NAME is stopped" ]]; then
            echo "OK"
        else
            echo "ERROR: could not stop $NAME:  $STATUS"
            exit 1
        fi
        ;;
    reload|restart)
        $0 stop
        $0 start
        ;;
    status)
        status -p $pid_file cassandra
        exit $?
        ;;
    *)
        echo "Usage: `basename $0` start|stop|status|restart|reload"
        exit 1
esac

exit 0

【讨论】:

以上是关于在 OpenSuse 上将 Cassandra 作为服务运行的主要内容,如果未能解决你的问题,请参考以下文章

Cassandra 内存配置

Apache Spark 如何在内存中工作?

使用node.js批量插入不在Cassandra中工作

在 Raspberry Pi 上安装新的 Linux 发行版

openSUSE 连接 Canon PIXMA MG3180 打印机

如何在 Windows 上将 OpenCV 库正确链接到 Eclipse?