代码

#! /bin/bash

master=$MASTER
slaves=$SLAVES
arrs=(${slaves//,/ })

#config /etc/hadoop/conf/core-site.xml,yarn-site.xml
sed -i "/MASTER/s/MASTER/$master/g" /etc/hadoop/conf/core-site.xml
sed -i "/MASTER/s/MASTER/$master/g" /etc/hadoop/conf/yarn-site.xml

#config /etc/hadoop/conf/workers
#先清空然后写入
: > /etc/hadoop/conf/workers

for item in ${arrs[@]}
do
echo $item>> /etc/hadoop/conf/workers
done