原文地址:

http://hi.baidu.com/chenshake/item/40a9b591343ef31e924f41c9


当你需要在10台服务器干同样的工作,你肯定就会有这个想法。

今天学习半天,觉得使用pssh来管理多台服务器。不过目前就只能在linux下用,好像没有windows的工具

用途

pssh 在多个主机上并行地运行命令。
pscp 把文件并行地复制到多个主机上。
prsync 通过 rsync 协议把文件高效地并行复制到多个主机上。
pslurp 把文件并行地从多个远程主机复制到中心主机上。
pnuke 并行地在多个远程主机上杀死进程。

1:安装

wget http://parallel-ssh.googlecode.com/files/pssh-2.2.2.tar.gz
tar zxvf pssh-2.2.2.tar.gz
cd pssh-2.2.2
python setup.py install



2.配置密钥,免密码访问管理机器

在使用之前需要配置密钥访问,如下:

#ssh-keygen #一直回车
#复制公钥到远端服务器
#ssh-copy-id -i .ssh/id_rsa.pub root@192.168.16.X

ps.如果端口不是默认22 ,需要使用:ssh-copy-id -i .ssh/id_rsa.pub  ”-p 4567 yin@192.168.16.X”


3:运行第一条命令,查看启动时间

]# pssh -h servers.txt -l root -P uptime
173.16.0.102:  13:14:57 up 1 day,  2:00,  1 user,  load average: 0.00, 0.00, 0.00
173.16.0.100:  13:23:34 up 21:40,  1 user,  load average: 0.00, 0.00, 0.00
[1] 13:13:52 [SUCCESS] 173.16.0.102
[2] 13:13:52 [SUCCESS] 173.16.0.100

4:删除文件

我需要删除以前yum.repo 文件

pssh -h servers.txt  -P "rm -r /etc/yum.repos.d/*.repo"

5:传输单个文件

pscp -h servers.txt /etc/yum.repos.d/ftp.repo /etc/yum.repos.d/
6:运行yum update

]# pssh -h servers.txt -l root -P "yum update"

173.16.0.100: Loaded plugins: fastestmirror
173.16.0.102: Loaded plugins: fastestmirror
173.16.0.100: Loading mirror speeds from cached hostfile
173.16.0.102: Loading mirror speeds from cached hostfile
173.16.0.100: Setting up Update Process
173.16.0.102: Setting up Update Process
173.16.0.100: No Packages marked for Update
173.16.0.102: No Packages marked for Update
[1] 13:38:13 [SUCCESS] 173.16.0.100
[2] 13:38:13 [SUCCESS] 173.16.0.102

7:让机器加载Ext4

]# pssh -h servers.txt -l root -P "modprobe ext4"
[1] 13:49:42 [SUCCESS] 173.16.0.100
[2] 13:49:42 [SUCCESS] 173.16.0.102

8:安装e4fsprogs, 支持ext4分区
[root@gluster02b ~]# pssh -h servers.txt -l root -P "yum -y install e4fsprogs"
173.16.0.102: Loaded plugins: fastestmirror
173.16.0.100: Loaded plugins: fastestmirror
173.16.0.100: Complete!
[1] 13:53:11 [SUCCESS] 173.16.0.100
173.16.0.102:

Installed:
 e4fsprogs.x86_64 0:1.41.12-2.el5

173.16.0.102: Complete!
[2] 13:53:11 [SUCCESS] 173.16.0.102

9:创建一个目录

# pssh -h servers.txt -l root -P "mkdir /data01"
[1] 09:53:27 [SUCCESS] 173.16.0.100
[2] 09:53:27 [SUCCESS] 173.16.0.102
# pscp -h servers.txt /etc/fstab /etc/
[1] 09:53:51 [SUCCESS] 173.16.0.102
[2] 09:53:51 [SUCCESS] 173.16.0.100


10:复制文件夹到远程

# pscp -h servers.txt -r /root/tools/ /root/
[1] 10:23:27 [SUCCESS] 173.16.0.100
[2] 10:23:28 [SUCCESS] 173.16.0.102


11:关闭Selinux

# pssh -h servers.txt -l root -P "sed -i '/SELINUX=enforcing/s/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux"
[1] 11:47:15 [SUCCESS] 173.16.0.100
[2] 11:47:15 [SUCCESS] 173.16.0.102


# pssh -h servers.txt -l root -P init 6
[1] 11:47:28 [SUCCESS] 173.16.0.102
[2] 11:47:28 [SUCCESS] 173.16.0.100
# pssh -h servers.txt -l root -P sestatus
[1] 11:49:37 [FAILURE] 173.16.0.100 Exited with error code 255
[2] 11:49:37 [FAILURE] 173.16.0.102 Exited with error code 255


# pssh -h servers.txt -l root -P sestatus
173.16.0.100: SELinux status:                 disabled
[1] 11:52:32 [SUCCESS] 173.16.0.100
173.16.0.102: SELinux status:                 disabled
[2] 11:52:32 [SUCCESS] 173.16.0.102


http://sheriy.com/?p=748

http://www.theether.org/pssh/docs/0.2.3/pssh-HOWTO.html