启动metastore和hiveserver2脚本
前台启动的方式导致需要打开多个shell窗口,可以使用如下方式后台方式启动
nohup: 放在命令开头,表示不挂起,也就是关闭终端进程也继续保持运行状态
2>&1 : 表示将错误重定向到标准输出上
&: 放在命令结尾,表示后台运行
一般会组合使用:nohup [xxx命令操作] > file 2>&1 & ,表示将xxx命令运行的结果输出到file中,并保持命令启动的进程在后台运行。
nohup hive --service metastore 2>&1 &
nohup hive --service hiveserver2 2>&1 &
为了方便使用,可以直接编写脚本来管理服务的启动和关闭。
#!/bin/bash
HIVE_LOG_DIR=$HIVE_HOME/logs
mkdir -p KaTeX parse error: Expected 'EOF', got '#' at position 14: HIVE_LOG_DIR #̲检查进程是否运行正常,参数1为…(ps -ef 2>/dev/null | grep -v grep | grep -i $1 | awk ‘{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') ppid=(netstat -nltp 2>/dev/null | grep $2 | awk ‘{print $7}’ | cut -d ‘/’ -f 1)
echo
p
i
d
[
[
"
pid [[ "
pid[["pid" =~ “KaTeX parse error: Expected 'EOF', got '&' at position 10: ppid" ]] &̲& [ "ppid” ] && return 0 || return 1
}
function hive_start()
{
metapid=
(
c
h
e
c
k
p
r
o
c
e
s
s
H
i
v
e
M
e
t
a
s
t
o
r
e
9083
)
c
m
d
=
"
n
o
h
u
p
h
i
v
e
−
−
s
e
r
v
i
c
e
m
e
t
a
s
t
o
r
e
>
(check_process HiveMetastore 9083) cmd="nohup hive --service metastore >
(checkprocessHiveMetastore9083)cmd="nohuphive−−servicemetastore>HIVE_LOG_DIR/metastore.log 2>&1 &"
cmd=KaTeX parse error: Expected 'EOF', got '&' at position 57: …t >/dev/null 2>&̲1" [ -z "metapid" ] && eval
c
m
d
∣
∣
e
c
h
o
"
M
e
t
a
s
t
r
o
e
服
务
已
启
动
"
s
e
r
v
e
r
2
p
i
d
=
cmd || echo "Metastroe服务已启动" server2pid=
cmd∣∣echo"Metastroe服务已启动"server2pid=(check_process HiveServer210000)
cmd=“nohup hive --service hiveserver2 >KaTeX parse error: Expected 'EOF', got '&' at position 32: …eServer2.log 2>&̲1 &" [ -z "server2pid” ] && eval KaTeX parse error: Expected 'EOF', got '}' at position 32: …eServer2服务已启动" }̲ function hive_…(check_process HiveMetastore 9083)
[ “$metapid” ] && kill
m
e
t
a
p
i
d
∣
∣
e
c
h
o
"
M
e
t
a
s
t
o
r
e
服
务
未
启
动
"
s
e
r
v
e
r
2
p
i
d
=
metapid || echo "Metastore服务未启动" server2pid=
metapid∣∣echo"Metastore服务未启动"server2pid=(check_process HiveServer2 10000)
[ “$server2pid” ] && kill $server2pid || echo “HiveServer2服务未启动”
}
case KaTeX parse error: Expected 'EOF', got '&' at position 183: …083 >/dev/null &̲& echo "Metasto…(basename $0)’ start|stop|restart|status’
;;
esac
最后增加执行权限,运行脚本就可以啦。
共有条评论 网友评论