# 节点分发脚本,将某一台节点上的数据,分发到集群中每一个节点中的同样的路径
- # 节点分发脚本,将某一台节点上的数据,分发到集群中每一个节点中的同样的路径
- #!/bin/bash
- # 1 get the number of input parameters, if there i no parameter, quit directly
-
- pcount=$#
- if((pcount==0)); then
- echo no args;
- exit;
- fi
-
- # 2 get the file name
-
- p1=$1
- fname=`basename $p1`
- echo fname=$fname
-
- # 3 get the upper directory to the absolute path
-
- pdir=`cd -P $(dirname $p1); pwd`
- echo pdir=$pdir
-
- # 4 get the current user name
-
- user=`whoami`
-
- # 5 cycle
- for((host=1; host<4; host++)); do
- #echo $pdir/$fname $user@hadoop$host:$pdir
- echo ---------- spark$host -----------
- rsync -rvl $pdir/$fname $user@spark$host:$pdir
- done
脚本使用示例:/root/ync.sh /usr/local/users.txt
可能会报错:./ync.sh: line 29: rsync: command not found
报错解决:需要要集群中的每一台节点上都安装rsync,安装指令yum install rsync -y
# 节点调用脚本,即每个节点都执行同样的指令
- # 节点调用脚本,即每个节点都执行同样的指令
- #!/bin/bash
- pcount=$#
- if((pcount==0));then
- tput setaf 1
- tput bold
- echo no args;
- tput setaf 7
- exit;
- fi
-
- params=$@
-
- for ((host=1; host<=3; host++)); do
- tput setaf 2
- echo =========================== spark$host ====================
- tput setaf 7
- ssh spark$host $@
- # ssh -4 spark$host "source /etc/profile; $params"
- done
使用示例:/root/xcall.sh ls /usr/local/
以上就是两个超级实用的脚本工具,供大家参考!
文章最后,给大家推荐一些受欢迎的技术博客链接:
- Hadoop相关技术博客链接
- Spark 核心技术链接
- JAVA相关的深度技术博客链接
- 超全干货--Flink思维导图,花了3周左右编写、校对
- 深入JAVA 的JVM核心原理解决线上各种故障【附案例】
- 请谈谈你对volatile的理解?--最近小李子与面试官的一场“硬核较量”
- 聊聊RPC通信,经常被问到的一道面试题。源码+笔记,包懂
欢迎扫描下方的二维码或 搜索 公众号“10点进修”,我们会有更多、且及时的资料推送给您,欢迎多多交流!
评论记录:
回复评论: