json文件offset-json-file.json
{
"partitions": [
{
"topic": "topic_name",
"partition": 0,
"offset": 1024
}
],
"version": 1
}
kafka-delete-records --bootstrap-server xxxxxx:9092
--offset-json-file offset-json-file.json
查看Broker磁盘信息
查询指定topic磁盘信息
kafka-log-dirs --bootstrap-server xxxxxx:9090
--describe --topic-list topic1,topic2
查询指定Broker磁盘信息
kafka-log-dirs --bootstrap-server xxxxxx:9090
--describe --topic-list topic1 --broker-list 0
Hive
启动类
功能说明 | 命令 |
启动hiveserver2服务 | bin/hiveserver2 |
启动beeline | bin/beeline |
连接hiveserver2 | beeline> !connect jdbc:hive2://hadoop102:10000 |
metastroe服务 | bin/hive --service metastore |
hive 启动元数据服务(metastore和hiveserver2)和优雅关闭脚本
启动: hive.sh start
关闭: hive.sh stop
重启: hive.sh restart
状态: hive.sh status
脚本如下
#!/bin/bash
HIVE_LOG_DIR=$HIVE_HOME/logs
mkdir -p $HIVE_LOG_DIR
#检查进程是否运行正常,参数1为进程名,参数2为进程端口
function check_process()
{
pid=$(ps -ef 2>/dev/null | grep -v grep | grep -i $1 | awk '{print $2}')
ppid=$(netstat -nltp 2>/dev/null | grep $2 | awk '{print $7}' | cut -d '/' -f 1)
echo $pid
[[ "$pid" =~ "$ppid" ]] && [ "$ppid" ] && return 0 || return 1
}
function hive_start()
{
metapid=$(check_process HiveMetastore 9083)
cmd="nohup hive --service metastore >$HIVE_LOG_DIR/metastore.log 2>&1 &"
cmd=$cmd" sleep4; hdfs dfsadmin -safemode wait >/dev/null 2>&1"
[ -z "$metapid" ] && eval $cmd || echo "Metastroe服务已启动"
server2pid=$(check_process HiveServer2 10000)
cmd="nohup hive --service hiveserver2 >$HIVE_LOG_DIR/hiveServer2.log 2>&1 &"
[ -z "$server2pid" ] && eval $cmd || echo "HiveServer2服务已启动"
}
function hive_stop()
{
metapid=$(check_process HiveMetastore 9083)
[ "$metapid" ] && kill $metapid || echo "Metastore服务未启动"
server2pid=$(check_process HiveServer2 10000)
[ "$server2pid" ] && kill $server2pid || echo "HiveServer2服务未启动"
}
case $1 in
"start")
hive_start
;;
"stop")
hive_stop
;;
"restart")
hive_stop
sleep 2
hive_start
;;
"status")
check_process HiveMetastore 9083 >/dev/null && echo "Metastore服务运行正常" || echo "Metastore服务运行异常"
check_process HiveServer2 10000 >/dev/null && echo "HiveServer2服务运行正常" || echo "HiveServer2服务运行异常"
;;
*)
echo Invalid Args!
echo 'Usage: '$(basename $0)' start|stop|restart|status'
;;
esac
常用交互命令
功能说明 | 命令 |
不进入hive的交互窗口执行sql | bin/hive -e "sql语句" |
执行脚本中sql语句 | bin/hive -f hive.sql |
退出hive窗口 | exit 或 quit |
命令窗口中查看hdfs文件系统 | dfs -ls / |
命令窗口中查看hdfs文件系统 | ! ls /data/h |