通過pssh同時管理多臺服務器,批量管理服務器

運維人員往往會頭疼,要在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.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






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章