前提:集群中机器都配了互信
1、多机拷贝文件到目标机器(其中hadoop01~20为目标机器hostname或ip)
使用示例: sh sshc.sh /etc/profile 将/etc/profile拷贝所有机器
sshc.sh脚本
# !/bin/bash scp -r "$1" hadoop01:"$1" scp -r "$1" hadoop02:"$1" scp -r "$1" hadoop03:"$1" scp -r "$1" hadoop04:"$1" scp -r "$1" hadoop05:"$1" scp -r "$1" hadoop06:"$1" scp -r "$1" hadoop07:"$1" scp -r "$1" hadoop08:"$1" scp -r "$1" hadoop09:"$1" scp -r "$1" hadoop10:"$1" scp -r "$1" hadoop11:"$1" scp -r "$1" hadoop12:"$1" scp -r "$1" hadoop13:"$1" scp -r "$1" hadoop14:"$1" scp -r "$1" hadoop15:"$1" scp -r "$1" hadoop16:"$1" scp -r "$1" hadoop17:"$1" scp -r "$1" hadoop18:"$1" scp -r "$1" hadoop19:"$1" scp -r "$1" hadoop20:"$1"
2、ssht.sh 多机同时执行命令(其中hadoop01~20为目标机器hostname或ip)
使用示例: sh ssht.sh 'date' 打印出所有机器的当前时间
# !/bin/bash ssh -t hadoop01:"$1" ssh -t hadoop02:"$1" ssh -t hadoop03:"$1" ssh -t hadoop04:"$1" ssh -t hadoop05:"$1" ssh -t hadoop06:"$1" ssh -t hadoop07:"$1" ssh -t hadoop08:"$1" ssh -t hadoop09:"$1" ssh -t hadoop10:"$1" ssh -t hadoop11:"$1" ssh -t hadoop12:"$1" ssh -t hadoop13:"$1" ssh -t hadoop14:"$1" ssh -t hadoop15:"$1" ssh -t hadoop16:"$1" ssh -t hadoop17:"$1" ssh -t hadoop18:"$1" ssh -t hadoop19:"$1" ssh -t hadoop20:"$1"