shell 命令
单节点的任务:
#!/bin/bash
# 指定目录
con_home=/app/confluent-6.0.0
#命令提示
usage="Usage: $0 (start|stop|status|restart)"
if [ # -lt 1 ]; then echousage
exit 1
fi
#判断用户
if [ `whoami` = "root" ];then
var_user="root"
elif [ `whoami` = "hive" ];then
var_user="hive"
else
echo "please login in with root or hive user"
exit 1
fi
#定义启动函数,需要三个参数,用户 confluent的根目录
func_start(){
cd 2 #删除日志文件 rm -rf 2/log
mkdir -p 2/log touch 2/log/schema.log
touch 2/log/kafka-connector.log chown hive 2/log -R
if [ 1 = "root" ];then echo "schema-registry is starting..." su hive -c "nohup sh bin/schema-registry-start etc/schema-registry/schema-registry.properties >>2/log/schema.log &"
echo "kafka-connector is starting..."
su hive -c "nohup sh bin/connect-distributed etc/schema-registry/connect-avro-distributed.properties >>2/log/kafka-connector.log &" else echo "schema-registry is starting..." nohup sh bin/schema-registry-start etc/schema-registry/schema-registry.properties>>2/log/schema.log
echo "kafka-connector is starting..."
nohup sh bin/connect-distributed etc/schema-registry/connect-avro-distributed.properties>>2/log/kafka-connector.log fi echo "please check 2/log/schema.log and $2/log/kafka-connector.log for errors"
}
#定义停止函数 需要一个参数 confluent的根目录
func_stop(){
echo "if take an error,that is no problem, please run command to check: ps -ef | grep 1" PID=(ps -ef | grep 1 | awk '{print $2}') for pid in PID
do
kill -9 $pid
done
}
#定义状态查看函数
func_status(){
PID=(ps -ef | grep 1 | awk '{print 2}') if [ {#PID} -gt 10 ];then
echo "running"
else
echo "an error happend,please run command to check: ps -ef | grep $1"
fi
}
#重启
func_restart(){
func_stop 2 func_start 1 2 3
}
#启动的命令,支持start, stop , status
case $1 in
(start)
func_start var_user con_home $log_file
;;
(stop)
func_stop $con_home
;;
(status)
func_status con_home ;; (restart) func_restart var_user con_home log_file
;;
(*)
echo $usage
exit 1
;;
esac
集群启动:
hosts_all="cluster1,cluster2,cluster3"
hosts=({hosts_all//,/ }) for host in {hosts[@]}
do
ehcho "it is connectting remote host for starting...“ ssh host "ls /soft"
done
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· C# 13 中的新增功能实操
· 万字长文详解Text-to-SQL
· Ollama本地部署大模型总结
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(4)
· 卧槽!C 语言宏定义原来可以玩出这些花样?高手必看!