#编写hive脚本
[root@singlelucky ~]# ls
bak kb12 script test2.log text.log
[root@singlelucky ~]# cd script
[root@singlelucky script]# ls
ALLOW_RM_SRC_LOG cha01 cha01.sh cha02.sh.bak deploy.sh ls.log my.cnf mysql.cnf
[root@singlelucky script]# mv mysql.cnf start.cnf
[root@singlelucky script]# ls
ALLOW_RM_SRC_LOG cha01 cha01.sh cha02.sh.bak deploy.sh ls.log my.cnf start.cnf
[root@singlelucky script]# touch start.sh
[root@singlelucky script]# ls
ALLOW_RM_SRC_LOG cha01 cha01.sh cha02.sh.bak deploy.sh ls.log my.cnf start.cnf start.sh
#修改权限启动start.sh
[root@singlelucky script]# chmod u+x start.sh
[root@singlelucky script]# ls
ALLOW_RM_SRC_LOG cha01 cha01.sh cha02.sh.bak deploy.sh ls.log my.cnf start.cnf start.sh
[root@singlelucky script]# cat start.cnf
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
#删除start.cnf里面内容
[root@singlelucky script]# sed -in '1,$d' start.cnf
[root@singlelucky script]# cat start.cnf
#修改start.cnf,测试hive启动
[root@singlelucky ~]# cd script
[root@singlelucky script]# ls
ALLOW_RM_SRC_LOG cha01 cha01.sh cha02.sh.bak deploy.sh ls.log my.cnf start.cnfn start.sh
[root@singlelucky script]# rm -rf start.cnfn
[root@singlelucky script]# ls
ALLOW_RM_SRC_LOG cha01 cha01.sh cha02.sh.bak deploy.sh ls.log my.cnf start.cnf start.sh
[root@singlelucky script]# vim start.cnf
hadoop->NameNode_SecondaryNameNode_DataNode_ResourceManager_NodeManager;start-dfs.sh_start-yarn.sh
hive->HiveMetaStore_HiveServer2;nohup#hive#--service#metastore>/dev/null#2>&1#&_nohup#hive#--service#hiveserver2>/dev/null#2>&1#&
#配置hive启动脚本
[root@singlelucky script]# vim start.sh # sz start.sh sz--输出
root@singlelucky script]# ./start.sh
#!/bin/bash
source /etc/profile
# 一键启动配置文件
CNF_FILE='start.cnf'
# 验证配置文件(必须存在且为文件)
if [ ! -e $CNF_FILE -o -d $CNF_FILE ]
then
echo $CNF_FILE" unavailable or directory, script will exit"
exit 0
fi
# 将配置文件内容读入变量并转为列表
CNF_LINES=(`cat start.cnf`)
# 循环按行输出配置信息,将第一项作为内容提示供用户选择
count=0
for item in ${CNF_LINES[@]}
do
((count++))
arr=(${item/->/ })
echo $count"、"${arr[0]}
done
# 用户选择启动服务编号(向前启动所有服务)
read -p 'please input you choice : ' choice
# 验证用户输入(必须为小于等于配置文件行数的整数)
if [[ $choice =~ ^[0-9]+$ ]]
then
if [ $choice -gt $count -o $choice -lt 1 ]
then
echo "choice must be between 1 and $count,script will exit"
exit 0
fi
else
echo 'choice must be a num, script will exit'
exit 0
fi
# 自定义函数检查指定参数的服务是否完好,若有残留杀死进程
function killOnLeft(){
SIGN=$1
SERS=$2
SERS=(${SERS
PIDS=()
count=0
for item in ${SERS[@]}
do
# jps配合管道检查指定服务项是否存在
RST=`jps -ml|grep $item`
if [[ $RST ]]
then
RST=($RST)
PIDS[$count]=${RST[0]}
((count++))
fi
done
if [ $count -lt ${#SERS[@]} ]
then
# 若存在不完整的残留kill进程
if [ $count -gt 0 ]
then
for pid in ${PIDS[@]}
do
RST=`kill -9 $pid`
done
echo "$SIGN has service left and killed"
else
echo "$SIGN has no service left"
fi
echo 'no'
else
echo "$SIGN is running"
echo "ok"
fi
}
# 自定义函数调用参数命令集启动相应服务
function startSers(){
SIGN=$1
SERS=$2
SERS=${SERS
for cmd in $SERS
do
RST=`eval ${cmd
done
echo $SIGN" has been started"
}
# 循环执行用户选择的配置文件中命令行
count=0
while (( $count<$choice ))
do
LINE=${CNF_LINES[$count]}
LINE=(${LINE
SIGN=${LINE[0]}
LINE=${LINE[1]}
LINE=(${LINE
SERS=${LINE[0]}
CMDS=${LINE[1]}
RST=`killOnLeft $SIGN $SERS`
echo $RST
if [[ $RST =~ no$ ]]
then
RST=`startSers $SIGN $CMDS`
echo $RST
fi
((count++))
done
#修改start.cnf,测试hive关闭
[root@singlelucky script]# touch stop.sh
[root@singlelucky script]# chmod u+x stop.sh
[root@singlelucky script]# ls
ALLOW_RM_SRC_LOG cha01 cha01.sh cha02.sh.bak deploy.sh ls.log my.cnf start.cnf start.sh stop.cnf stop.sh
[root@singlelucky script]# vim stop.cnf
hive->KILL->HiveMetaStore,HiveServer2
hadoop->STOP->NameNode,SecondaryNameNode,DataNode@stop-dfs.sh;ResourceManager,NodeManager@stop-yarn.sh
#查找hive log
jps -ml|grep -w HiveMetaStore|awk {'print $1'} #指定检查
[root@singlelucky input]# find / -name 'hive.log'
/tmp/root/hive.log
[root@singlelucky input]# tail -50 /tmp/root/hive.log
修改日志方式
重命名
mv /opt/software/hive312/conf/hive-log4j2.properties.template /opt/software/hive312/conf/hive-log4j2.properties
vim /opt/software/hive312/conf/hive-log4j2.properties
property.hive.log.level = ERROR #只显示日志出现错误的地方
[root@singlelucky conf]# vim hive-site.xml #去除HIVE里面的INFO信息
<!--配置取消 beeline 登录 info 信息 -->
<property>
<name>hive.server2.logging.operation.enabled</name>
<value>false</value>
</property>
#配置hive关闭脚本
[root@singlelucky script]# vim stop.sh # sz start.sh sz--输出
#!/bin/bash
source /etc/profile
CNF_FILE="stop.cnf"
CNF_LINES=(`cat $CNF_FILE`)
COUNT=0
for item in ${CNF_LINES[@]}
do
((COUNT++))
item=(${item
echo "$COUNT、${item[0]}"
done
read -p 'please make a choice : ' choice
# 验证用户输入(必须为小于等于配置文件行数的整数)
if [[ $choice =~ ^[0-9]+$ ]]
then
if [ $choice -gt $COUNT -o $choice -lt 1 ]
then
echo "choice must be between 1 and $COUNT,script will exit"
exit 0
fi
else
echo 'choice must be a num,script will exit'
exit 0
fi
#自定义函数调用服务自带脚本关闭服务
function stopSers(){
LINE=$1
LINE=(${LINE
SERS=${LINE[0]}
SERS=${SERS
COUNT=0
for item in $SERS
do
RST=`jps -ml|grep -w $item`
if [[ $RST ]]
then
COUNT=1
break
fi
done
if [ $COUNT -eq 1 ]
then
RST=`${LINE[1]}`
echo "STOPPED"
else
echo "NONE"
fi
}
#自定义函数通过系统通用函数kill关闭服务
function killSers(){
LINE=$1
LINE=${LINE
COUNT=0
for item in $LINE
do
PID=`jps -ml|grep -w $item|awk {'print $1'}`
if [[ $PID ]]
then
PID=`kill -9 $PID`
((COUNT++))
fi
done
if [ $COUNT -gt 0 ]
then
echo "STOPPED"
else
echo "NONE"
fi
}
#自定义函数根据参数类型和操作字符串关闭服务
function stopByLine(){
SIGN=$1
TYPE=$2
LINE=$3
case $TYPE in
"STOP")
LINE=${LINE
for item in $LINE
do
RST=`stopSers $item`
item=(${item
item=${item[0]}
case $RST in
"STOPPED")
echo 'services_[_'$item'_]_stopped'
;;
"NONE")
echo 'no_servies_[_'$item'_]_existed'
;;
esac
done
;;
"KILL")
RST=`killSers $LINE`
case $RST in
"STOPPED")
echo 'services_[_'$LINE'_]_stopped'
;;
"NONE")
echo 'no_services_[_'$LINE'_]_existed'
;;
esac
;;
esac
}
#根据用户的选择向后关闭服务
COUNT=0
while (( $COUNT<$choice ))
do
LINE=${CNF_LINES[$COUNT]}
LINE=(${LINE
SIGN=${LINE[0]}
TYPE=${LINE[1]}
LINE=${LINE[2]}
RST=`stopByLine $SIGN $TYPE $LINE`
for item in $RST
do
echo ${item
done
((COUNT++))
done
|