将Hive Thrift server 添加到服务后台运行

来源:互联网 发布:大气环境防护距离软件 编辑:程序博客网 时间:2024/05/29 17:33

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

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

 

  1. #!/bin/bash 
  2. # init script for Hive Thrift Interface. 
  3. # chkconfig: 2345 90 10 
  4. # description: Hive Thrift Interface 
  5.  
  6. # Source function library. 
  7. . /etc/rc.d/init.d/functions 
  8.  
  9. # Paths to configuration, binaries, etc 
  10. HIVE_BIN=/usr/bin/hive 
  11. HIVE_ARGS="--service hiveserver" 
  12. HIVE_LOG=/var/log/hive-thrift.log 
  13. HIVE_USER="hadoop" 
  14. ANT_LIB=/usr/share/java 
  15.  
  16. if [ ! -f $HIVE_BIN ]; then 
  17.   echo "File not found: $HIVE_BIN" 
  18.   exit 1 
  19. fi 
  20.  
  21. # pid file for /sbin/runuser 
  22. pidfile=${PIDFILE-/var/run/hive-thrift.pid} 
  23. # pid file for the java child process. 
  24. pidfile_java=${PIDFILE_JAVA-/var/run/hive-thrift-java.pid} 
  25. RETVAL=0 
  26.  
  27. start() { 
  28.   # check to see if hive is already running by looking at the pid file and grepping 
  29.   # the process table
  30.   if [ -f $pidfile_java ] && checkpid `cat $pidfile_java`; then 
  31.     echo "hive-thrift is already running" 
  32.     exit 0 
  33.   fi 
  34.   echo -n $"Starting $prog: " 
  35.   /sbin/runuser -s /bin/sh -c "$HIVE_BIN $HIVE_ARGS" $HIVE_USER >> $HIVE_LOG 2>&1 & 
  36.   runuser_pid=$! 
  37.   echo $runuser_pid > $pidfile 
  38.   # sleep so the process can make its way to the process table
  39.   usleep 500000 
  40.   # get the child Java process that /usr/bin/hive started. 
  41.   java_pid=$(ps -eo pid,ppid,fname | awk "{ if (\$2 == $runuser_pid && \$3 ~ /java/) { print \$1 } }"
  42.   echo $java_pid > $pidfile_java 
  43.   disown -ar 
  44.   # print status information. 
  45.   ps aux | grep $java_pid &> /dev/null && echo_success || echo_failure 
  46.   RETVAL=$? 
  47.   echo 
  48.   return $RETVAL 
  49.  
  50. stop() { 
  51.   # check if the process is already stopped by seeing if the pid file exists. 
  52.   if [ ! -f $pidfile_java ]; then 
  53.     echo "hive-thrift is already stopped" 
  54.     exit 0 
  55.   fi 
  56.   echo -n $"Stopping $prog: " 
  57.   if kill `cat $pidfile` && kill `cat $pidfile_java`; then 
  58.     RETVAL=0 
  59.     echo_success 
  60.   else 
  61.     RETVAL=1 
  62.     echo_failure 
  63.   fi 
  64.   echo 
  65.   [ $RETVAL = 0 ] && rm -f ${pidfile} ${pidfile_java} 
  66.  
  67. status_fn() { 
  68.   if [ -f $pidfile_java ] && checkpid `cat $pidfile_java`; then 
  69.     echo "hive-thrift is running" 
  70.     exit 0 
  71.   else 
  72.     echo "hive-thrift is stopped" 
  73.     exit 1 
  74.   fi 
  75.  
  76. case "$1" in 
  77.   start) 
  78.     start 
  79.     ;; 
  80.   stop) 
  81.     stop 
  82.     ;; 
  83.   status) 
  84.     status_fn 
  85.     ;; 
  86.   restart) 
  87.     stop 
  88.     start 
  89.     ;; 
  90.   *) 
  91.     echo $"Usage: $prog {start|stop|restart|status}" 
  92.     RETVAL=3 
  93. esac 
  94.  
  95. 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


原创粉丝点击