1、下载pssh
下载地址
http://code.google.com/p/parallel-ssh/downloads/list
2、安装
wget http://parallel-ssh.googlecode.com/files/pssh-2.2.2.tar.gz tar -xzvf pssh-2.2.2.tar.gz cd pssh-2.2.2 python ./setup.py install
安装完之后会产生下面这几个命令
changing mode of /usr/bin/pnuke to 755 并行地在多个远程主机上杀死进程。
changing mode of /usr/bin/pssh to 755 在多个主机上并行地运行命令。
changing mode of /usr/bin/pscp to 755 把文件并行地复制到多个主机上。
changing mode of /usr/bin/pslurp to 755 把文件并行地从多个远程主机复制到中心主机上。
changing mode of /usr/bin/prsync to 755 通过 rsync
协议把文件高效地并行复制到多个主机上。
changing mode of /usr/bin/pssh-askpass to 755
3、编辑主机文件
[root@tyServer shell]# cat service.txt 172.16.1.11 172.16.1.12 172.16.1.13 192.168.3.4 172.16.254.1
4、执行命令 -i 选项必须加上,要不然会报错的
如果远程命令在 60 秒内没有完成,连接会终止。如果命令需要更多处理时间,可以使用 -t 设置更长的到期时间。
[root@tyServer shell]# pssh -h ./service.txt -i uptime [1] 15:30:58 [SUCCESS] 172.16.1.11 15:29:35 up 5 days, 1:16, 0 users, load average: 0.03, 0.01, 0.00 [2] 15:30:58 [SUCCESS] 172.16.1.13 15:29:35 up 5 days, 1:16, 0 users, load average: 0.00, 0.00, 0.00 [3] 15:30:58 [SUCCESS] 172.16.254.1 15:29:35 up 4 days, 23:56, 0 users, load average: 0.00, 0.00, 0.00 [4] 15:30:58 [SUCCESS] 192.168.3.4 15:29:35 up 5 days, 1:04, 0 users, load average: 0.00, 0.00, 0.00 [5] 15:30:58 [SUCCESS] 172.16.1.12 15:29:35 up 21:14, 1 user, load average: 0.15, 0.08, 0.02
5、如果遇到执行的命令中有双引号,那就用单引号将命令引起来,要不然会报错
[root@tyServer shell]# pssh -h ./service.txt -i 'date +"%Y %m %d"' [1] 15:30:37 [SUCCESS] 172.16.1.11 2013 06 25 [2] 15:30:37 [SUCCESS] 172.16.254.1 2013 06 25 [3] 15:30:37 [SUCCESS] 172.16.1.13 2013 06 25 [4] 15:30:37 [SUCCESS] 192.168.3.4 2013 06 25 [5] 15:30:37 [SUCCESS] 172.16.1.12 2013 06 25
6、pscp的使用
[root@tyServer shell]# pscp -h service.txt /etc/hosts /etc/hosts [1] 15:36:02 [SUCCESS] 172.16.1.12 [2] 15:36:02 [SUCCESS] 172.16.254.1 [3] 15:36:02 [SUCCESS] 192.168.3.4 [4] 15:36:02 [SUCCESS] 172.16.1.11 [5] 15:36:02 [SUCCESS] 172.16.1.13
第一个/etc/hosts是本地文件,第二个/etc/hosts是目标文件
7、复制172.16.1.12主机上的/etc/hosts文件到/tmp目录下,并指定文件名为hosts。
这里root@172.16.1.12,主机必须使用IP地址。
[root@tyServer tmp]# pslurp -H "root@172.16.1.12" -L /tmp /etc/hosts hosts [1] 15:43:45 [SUCCESS] root@172.16.1.12 [root@tyServer tmp]# cat 172.16.1.12/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 172.16.1.11 vs1 172.16.1.12 vs2 172.16.1.13 vs3 192.168.3.4 mail 172.16.254.1 snap1