此模板可以用于类似的多个集群节点一键配置
#!/bin/bash
# jdk.sh
set -e
WORKDIR=`cd $(dirname $0);pwd`
USER=root
HOSTS=(
hadoop02
hadoop03
hadoop04
)
for host in ${HOSTS[*]}
do
echo "=========== start host: "$host " ===========";
scp $WORKDIR/jdk1.8.tar.gz $USER@$host:$WORKDIR;
ssh -p 22 $host <<EOF
cd ${WORKDIR}
tar -zxvf jdk1.8.tar.gz
echo 'export JAVA_HOME=/data/jdk1.8.0_271' >> /etc/bashrc
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/bashrc
source /etc/bashrc
EOF
done