HIVE Service自动启动

 

1.  将hive 的metastore用mysql连接储存

2  在/etc/init.d/文件夹中编辑文件hive-thrift

#!/bin/bash
# init script for Hive Thrift Interface.
#
# chkconfig: 2345 90 10
# description: Hive Thrift Interface

# Source function library.
. /etc/rc.d/init.d/functions

# Paths to configuration, binaries, etc
HIVE_BIN=/usr/bin/hive
HIVE_ARGS="--service hiveserver"
HIVE_LOG=/var/log/hive-thrift.log
HIVE_USER="hadoop"
ANT_LIB=/usr/share/java

if [ ! -f $HIVE_BIN ]; then
  echo "File not found: $HIVE_BIN"
  exit 1
fi

# pid file for /sbin/runuser
pidfile=${PIDFILE-/var/run/hive-thrift.pid}
# pid file for the java child process.
pidfile_java=${PIDFILE_JAVA-/var/run/hive-thrift-java.pid}
RETVAL=0

start() {
  # check to see if hive is already running by looking at the pid file and grepping
  # the process table.
  if [ -f $pidfile_java ] && checkpid `cat $pidfile_java`; then
    echo "hive-thrift is already running"
    exit 0
  fi
  echo -n {1}quot;Starting $prog: "
  /sbin/runuser -s /bin/sh -c "$HIVE_BIN $HIVE_ARGS" $HIVE_USER >> $HIVE_LOG 2>&1 &
  runuser_pid=$!
  echo $runuser_pid > $pidfile
  # sleep so the process can make its way to the process table.
  usleep 500000
  # get the child Java process that /usr/bin/hive started.
  java_pid=$(ps -eo pid,ppid,fname | awk "{ if (\$2 == $runuser_pid && \$3 ~ /java/) { print \$1 } }")
  echo $java_pid > $pidfile_java
  disown -ar
  # print status information.
  ps aux | grep $java_pid &> /dev/null && echo_success || echo_failure
  RETVAL=$?
  echo
  return $RETVAL
}

stop() {
  # check if the process is already stopped by seeing if the pid file exists.
  if [ ! -f $pidfile_java ]; then
    echo "hive-thrift is already stopped"
    exit 0
  fi
  echo -n {1}quot;Stopping $prog: "
  if kill `cat $pidfile` && kill `cat $pidfile_java`; then
    RETVAL=0
    echo_success
  else
    RETVAL=1
    echo_failure
  fi
  echo
  [ $RETVAL = 0 ] && rm -f ${pidfile} ${pidfile_java}
}

status_fn() {
  if [ -f $pidfile_java ] && checkpid `cat $pidfile_java`; then
    echo "hive-thrift is running"
    exit 0
  else
    echo "hive-thrift is stopped"
    exit 1
  fi
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status_fn
    ;;
  restart)
    stop
    start
    ;;
  *)
    echo {1}quot;Usage: $prog {start|stop|restart|status}"
    RETVAL=3
esac

exit $RETVAL


新建文件并对文件添加权限

touch /var/run/hive-thrift.pid
touch /var/log/hive-thrift.log
touch /var/run/hive-thrift-java.pid

chown hadoop:hadoop /var/run/hive-thrift.pid
chown hadoop:hadoop /var/log/hive-thrift.log
chown hadoop:hadoop /var/run/hive-thrift-java.pid

将hive-thrift添加到服务中并设置为开机启动

chmod +x /etc/init.d/hive-thrift
chkconfig --add hive-thrift
chkconfig hive-thrift on
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值