配置Cassandra开机启动(CentOS 7)

配置环境:centOS 7

 

1. 编写开机启动脚本
[root@cassandra-01 ~]# cd /etc/rc.d/init.d/
[root@cassandra-01 init.d]# vi cassandra
写入以下内容并保存关闭

#!/bin/sh
# chkconfig: 2345 60 60
# description: service for cassandra 3.11.4
# processname: cassandra

CASSANDRA_DIR="/usr/local/apache-cassandra-3.11.4"

case "$1" in
start)
echo "Starting cassandra"
su - cassandra -c nohup -c "$CASSANDRA_DIR/bin/cassandra" >> $CASSANDRA_DIR/logs/system.log 2>&1 &
echo "Cassandra started"
;;
stop)
echo "Stopping cassandra"
PID_COUNT=`ps aux |grep CassandraDaemon |grep -v grep | wc -l`
PID=`ps aux |grep CassandraDaemon |grep -v grep | awk {'print $2'}`
if [ $PID_COUNT -gt 0 ];then
echo "Try stop cassandra"
kill -9 $PID
echo "Kill cassandra SUCCESS!"
else
echo "There is no cassandra!"
fi
;;
restart)
echo "Restarting cassandra"
$0 stop
$0 start
;;
status)
-c "$CASSANDRA_DIR/bin/nodetool status"
;;
*)
echo "Usage:$0 {start|stop|restart|status}"
exit 1
esac


赋予权限
[root@cassandra-01 init.d]# chmod 755 cassandra


2. 配置开机自启动
加入系统服务

[root@cassandra-01 init.d]# chkconfig --add cassandra
设置开机自启动

[root@cassandra-01 init.d]# chkconfig cassandra on


3. 服务启动停止
[root@cassandra-01 init.d]# service cassandra start
[root@cassandra-01 init.d]# service cassandra stop
[root@cassandra-01 init.d]# service cassandra restart

posted @ 2019-08-07 09:52  SoyWang  阅读(919)  评论(0编辑  收藏  举报