1.安装软件 sshpass,官网为http://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gz/download,只需选择集群中的一台节点安装就好,后面的工作主要在这台节点上完成
2.下面是我配置集群用户和无密码ssh登陆的一个实例脚本,脚本中配置的是节点gd111-gd118,gd121-gd128,gd131-gd138,gd141-gd148,该脚本就是在安装有sshpass的机子上运行的,脚本给出了思想,其他细节内容请自行稍作更改:
#-----------create a new user which username is 'zhangliuhang' and password is '111111'----------- #cmd='useradd zhangliuhang;echo '111111' | passwd zhangliuhang --stdin'
#for ((i=1;i<=4;i++)) do # for ((j=1;j<=8;j++)) do # sshpass -p 111111 ssh root@gd1$i$j $cmd # echo gd1$i$j # done #done
#-------generate the public and private ssh key------------------------------------------------ #cmd='ssh-keygen -q -N "" -t rsa -f /home/zhangliuhang/.ssh/id_rsa'
#for ((i=1;i<=4;i++)) do # for ((j=1;j<=8;j++)) do # sshpass -p 111111 ssh zhangliuhang@gd1$i$j $cmd # echo gd1$i$j # done #done
#--------copy all cluster nodes' public ssh key to one node,here i choose gd111------------------- #cmd='cat /home/zhangliuhang/.ssh/id_rsa.pub'
#for ((i=1;i<=4;i++)) do # for ((j=1;j<=8;j++)) do # sshpass -p 111111 ssh zhangliuhang@gd1$i$j $cmd>>/home/zhangliuhang/.ssh/authorized_keys # echo gd1$i$j # done #done
#---------copy the authorized_keys to all nodes--------------------------------------------------------------------------------- #for ((i=1;i<=4;i++)) do # for ((j=1;j<=8;j++)) do # sshpass -p 111111 scp /home/zhangliuhang/.ssh/authorized_keys zhangliuhang@gd1$i$j:/home/zhangliuhang/.ssh # echo gd1$i$j # done #done
剩下的脚本应该在zhangliuhang用户下进行
#---------test as user zhangliuhang not root------------------------------------------------- #for ((i=1;i<=4;i++)) do # for ((j=1;j<=8;j++)) do # ssh gd1$i$j hostname # echo gd1$i$j # done #done
#---------copy the known_hosts to all nodes as user zhangliuhang----------------------------------------------- #for ((i=1;i<=4;i++)) do # for ((j=1;j<=8;j++)) do # scp /home/zhangliuhang/.ssh/known_hosts zhangliuhang@gd1$i$j:/home/zhangliuhang/.ssh # echo gd1$i$j # done #done