pssh(附批量部署openssh 公钥)

第一 批量部署openssh 公钥, 为什么把这个写在前面呢 ,因为一批虚拟机过来 当然是先配置 pub key的啦 一台台来多麻烦,所以这个是为了后面而准备的
#!/bin/bash
cd /root
cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
for i in `cat ip`
do
ip=$(echo "$i"|cut -f1 -d":")
password=$(echo "$i"|cut -f2 -d":")
expect -c "
spawn scp /root/.ssh/authorized_keys /root/rem [email protected]$ip:/tmp/
expect {
"*yes/no*" {send "yesr"; exp_continue}
"*password*" {send "$passwordr"; exp_continue}
"*Password*" {send "$passwordr";}
}
"
expect -c "
spawn ssh [email protected]${ip} /tmp/rem
expect {
"*yes/no*" {send "yesr"; exp_continue}
"*password*" {send "$passwordr"; exp_continue}
"*Password*" {send "$passwordr";}
}
"
done

[[email protected] ~]# cat rem
#!/bin/bash
if [ ! -d /root/.ssh ];then
mkdir /root/.ssh
fi
cp /tmp/authorized_keys /root/.ssh/

[[email protected] ~]# cat ip
192.168.23.41:2240
192.168.23.50:2240
SSH=”/usr/local/bin/ssh -p 22 -o StrictHostKeyChecking=no”
${SSH} [email protected]${ip} “sh /tmp/rem”
${SSH} [email protected]${GAME_SERVER_IP_2} “nohup sh -x ${TMP_DIR}/exp
.sh > /data/db0620.log 2>&1 &”
第二 pssh
#这个也可安装一下的
wget http://peak.telecommunity.com/dist/ez_setup.py
python ez_setup.py

https://parallel-ssh.googlecode.com/files/pssh-2.3.1.tar.gz
#新版本下载不了,先用这个吧
wget --no-check-certificate https://parallel-ssh.googlecode.com/files/pssh-2.2.2.tar.gz
tar xvf pssh-2.2.2.tar.gz
cd pssh-2.2.2
python setup.py install

其实包含了5个工具 pssh,pscp,prsync,pnuke,pslurp
下面就一个个来讲解一下下
1. pssh
pssh常用参数 man 可见
[-l user]
[-h hosts_file]
用法举例
pssh -h iplist -l root hostname
[1] 16:37:48 [SUCCESS] 192.168.23.41
[2] 16:37:48 [SUCCESS] 192.168.23.50
2. pscp
pscp -h iplist -l root pssh-2.2.2.tar.gz /tmp/
3. prsync ##注意 远程的目录最好是存在的
prsync -r -h iplist -l root pssh-2.2.2 /tmp/
4. pslurp
pslurp 正好和上面的 pscp prsync 相反 ,在中心服拿回 log 还是很不错的呢
把文件或者目录并行地从多个远程主机复制到中心主机
它从每台远程计算机收集指定的文件,但是并不覆盖文件的本地版本。pslurp 为每台远程计算机创建一个子目录并把指定的文件复制到此位置
1)#标示将目标服务器的 /tmp/test文件复制到本地的 /root/dir 目录下 ,并改名为 testdown
pslurp -r -h ../iplist -L /root/dir/ -l root /tmp/test testdown
[1] 17:07:54 [SUCCESS] 192.168.23.41
[2] 17:07:54 [SUCCESS] 192.168.23.50
[[email protected] tmp]# ls /root/dir/
192.168.23.41 192.168.23.50
2)
#把远程的 /tmp/test 拷贝到本地的 /root目录下,不过有时不成功呢,不会create dir
pslurp -r -h iplist /tmp/test /root
5. pnuke 并行在远程主机杀进程:
[[email protected] ~]# pnuke -h iplist --user=root crond
[1] 17:14:17 [SUCCESS] 192.168.23.41
[2] 17:14:18 [SUCCESS] 192.168.23.50
参考
http://www.dongwm.com/archives/%E4%BD%BF%E7%94%A8pssh%E8%BF%9B%E8%A1%8C%E5%B9%B6%E8%A1%8C%E6%89%B9%E9%87%8F%E6%93%8D%E4%BD%9C/
http://research.blog.51cto.com/2258479/922317
http://blog.csdn.net/jiedushi/article/details/7161439
ubuntu下PSSH的使用
http://hi.baidu.com/gaolongquan/item/c5267981a070035e26ebd9bc