栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Linux集群常用脚本(个人总结)

Linux集群常用脚本(个人总结)

    声明: 1. 本文为我的个人复习总结, 并非那种从零基础开始普及知识 内容详细全面, 言辞官方的文章
              2. 由于是个人总结, 所以用最精简的话语来写文章
              3. 若有错误不当之处, 请指出

常用脚本编写汇总 自定义脚本放在~/bin下,并把这个目录配到PATH中去
mkdir ~/bin
vim  /etc/profile
#添加~/bin到PATH
PATH=$PATH:~/bin
source  /etc/profile

三台机器都配置一下上述命令

脚本编写后都赋予可执行权限, chmod +x 脚本

集群分发文件脚本xsync.sh
#!/bin/bash

#集群分发文件
#1. 判断参数个数
if [ $# -lt 1 ]
then
  echo Not Enough Arguement!
  exit;
fi
#2. 遍历集群所有机器
for host in hadoop102 hadoop103 hadoop104
do
  echo ====================  $host  ====================
  #3. 遍历所有目录,挨个发送
  for file in $@
  do
    #4 判断文件是否存在
    if [ -e $file ]
    then
      #5. 获取父目录
      pdir=$(cd -P $(dirname $file); pwd)
      #6. 获取当前文件的名称
      fname=$(basename $file)
      ssh $host "mkdir -p $pdir"
      rsync -av $pdir/$fname $host:$pdir
    else
      echo $file does not exists!
    fi
  done
done
集群分发命令脚本all
#!/bin/bash

#集群分发命令
for i in hadoop102 hadoop103 hadoop104
do
    echo --------- $i ----------
    ssh $i "$*"
done
ZooKeeper [启动/停止/查看状态] 脚本zk.sh
#!/bin/bash

#ZooKeeper [启动/停止/查看状态]
commandPath=$ZOOKEEPER_HOME/bin
case $1 in
	"start"){
		all $commandPath/zkServer.sh start
	};;
	"stop"){
		all $commandPath/zkServer.sh stop
	};;
	"status"){
		all $commandPath/zkServer.sh status
	};;
	"cli"){
		all $commandPath/zkCli.sh
	};;


    "1"){
		all $commandPath/zkServer.sh start
	};;
	"0"){
		all $commandPath/zkServer.sh stop
	};;
    *)
    echo "非法参数!"
    ;;
esac

Hive后台启动metastore和hiveserver2服务脚本 hive.sh
#!/bin/bash

#Hive [启动/停止/查看状态]
HIVE_LOG_DIR=$HIVE_HOME/logs
if [ ! -d $HIVE_LOG_DIR ]
then
	mkdir -p $HIVE_LOG_DIR
fi
#检查进程是否运行正常,参数 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 &"
    [ -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)
    kill $metapid
    server2pid=$(check_process HiveServer2 10000)
    kill $server2pid
}

case $1 in
    "start")
    hive_start
    ;;
    "stop")
    hive_stop
    ;;
    "status")
    check_process Hivemetastore 9083 >/dev/null && echo "metastore 服务运行 正常" || echo "metastore 服务运行异常"
    check_process HiveServer2 10000 >/dev/null && echo "HiveServer2 服务运 行正常" || echo "HiveServer2 服务运行异常"
    ;;

    "1")
    hive_start
    ;;
    "0")
    hive_stop
    ;;
    *){
        echo "非法参数!"
    };;
esac
Kafka集群 [启动/停止] 脚本kf.sh
#!/bin/bash
case $1 in
	"start"){
		all $KAFKA_HOME/bin/kafka-server-start.sh -daemon $KAFKA_HOME/config/server.properties
	};;
	"stop"){
		all $KAFKA_HOME/bin/kafka-server-stop.sh
	};;
esac
Hbase集群 [启动/停止] 脚本hbase.sh
#!/bin/bash
case $1 in
	"start"){
		all start-hbase.sh
	};;
	"stop"){
		all stop-hbase.sh
	};;
esac
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/753121.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号