zoukankan      html  css  js  c++  java
  • shell 命令

    单节点的任务:

    #!/bin/bash

    # 指定目录
    con_home=/app/confluent-6.0.0

    #命令提示
    usage="Usage: $0 (start|stop|status|restart)"

    if [ $# -lt 1 ]; then
    echo $usage
    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

  • 相关阅读:
    338. 比特位计数
    300.最长上升子序列
    git 钩子服务代码
    thinkphp5.1 封装文件上传模块
    Theano 基础
    使用anaconda和pycharm搭建多python本版的开发环境
    GIT常用命令
    Thinkphp 获取数据表随机值
    在Windows中利用.bat提交git代码到不同分支
    Windows .bat 常量
  • 原文地址:https://www.cnblogs.com/wind-man/p/13755364.html
Copyright © 2011-2022 走看看