在rsh无密码互通已经配置好的情况下,
如果没有xCat等集群管理软件,想要执行多节点的管理命令,可以自己写一个脚本,如dsh,用来代替xCat的psh
编辑脚本dsh,放在/usr/bin目录下:
#!/bin/sh
if [ $# -eq 0 ]; then
echo "Usage: dsh " >&2
exit 1
fi
command=$@
clusterhosts=$(egrep -v '#' /etc/hosts.dsh)
for i in $clusterhosts
do
echo "----------------------------"
echo $i
/usr/bin/rsh $i $command
done
配合上述脚本,编辑 /etc/hosts.dsh如下,作为节点主机名列表:
hpz802
hpz803
此文件注释符#有效,不需要执行操作的行可用其注释掉。
类似地, 可以做一个dcp脚本,用于多节点远程拷贝rcp
#!/bin/sh
if [ $# -eq 0 ]; then
echo "Usage: dcp source target" >&2
echo "Usage: dcp source"
exit 1
fi
if [ $# -eq 1 ]; then
source=$1
target=$1
fi
if [ $# -eq 2 ]; then
source=$1
target=$2
fi
clusterhosts=$(egrep -v '#' /etc/hosts.dsh)
for i in $clusterhosts
do
echo "----------------------------"
echo "/usr/bin/rcp $source $i:$target"
/usr/bin/rcp $source $i:$target
done
类似地,可以写出ssh无密码互通情况下的脚本。