運維人員往往會頭疼,要在10多台伺服器上去執行同樣的操作。
在linux下有一款這樣的工具(pssh),解決了這個問題。
這款工具的幾個主要功能:
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 [email protected]
ps.如果端口不是預設22 ,需要使用:ssh-copy-id -i .ssh/id_rsa.pub ”-p 4567 [email protected]”
編輯 伺服器清單檔案 servers.txt
# vim /home/server.txt
[email protected]:22031
hosts file (each line "[user@]host[:port]")
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.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
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