pssh有2種模式,一種是服務端與客戶端之間基於證書,另外一種是不需要證書的,那麼就需要root的密碼
#wget http://peak.telecommunity.com/dist/ez_setup.py
python ez_setup.py
#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
機器之間建立證書連接
A B C 三臺機器
對A和B之間做證書連接,然後對A和C之間建立證書連接就行了。
ssh-keygen -t rsa
然後把/root/.ssh下的id_rsa.pub拷貝到目標機器/root/.ssh/下,並衝命令爲authorized_keys
B機器也一樣
然後再A上,新建一個txt文本文件,裏面存放客戶端機器ip
pssh -h 1.txt mkdir /home/ss
[1] 15:37:04 [SUCCESS] 192.168.1.9
[2] 15:37:04 [SUCCESS] 192.168.1.43
如果ssh端口非22的話,則需要在1.txt中寫上去
[email protected]:9922
[email protected]:9922
--root用戶可以證書登陸到目標機器
pscp 把文件並行地複製到多個主機上 注意 是從服務器端給客戶端傳送文件:
[root@server pssh-2.2.2]# pscp -h test.txt /etc/sysconfig/network /tmp/network //標示將本地的/etc/sysconfig
prsync 使用rsync協議從本地計算機同步到遠程主機
[root@server ~]# pssh -h test.txt -P mkdir /tmp/etc
[root@server ~]# prsync -h test.txt -l dongwm -a -r /etc/sysconfig /tmp/etc //標示將本地的/etc/sysconfig目錄遞
pnuke 並行在遠程主機殺進程:
[root@server ~]# pnuke -h test.txt syslog //殺死目標服務器的syslog進程,只要ps進程中出現相關詞語 都能殺死
[1] 15:05:14 [SUCCESS] 192.168.9.102 9922
[2] 15:05:14 [SUCCESS] 192.168.9.104 9922
【測試】
pssh -h 1.txt "echo '192.168.1.1 www.inbank.cn' >> /etc/hosts"
然後跑到客戶端下去查看
pssh -h 1.txt "sed -i 's/1/zzz/g' /home/1.txt“
也可以直接用正則
pssh -h 1.txt yum -y install subversion
多個linux命令
./pssh -h 1.txt "echo '11' >>/etc/hosts && mkdir /home/test"
####另:python 2.7安裝
tar -zxvf Python-2.7.3.tgz
cd Python-2.7.3
./configure
make;make install
cd /usr/bin
mv python python.bak
ln -s /usr/local/bin/python python
#####如果覺的證書麻煩,可以試試以下方法#######
普通的pssh需要使用私鑰驗證,但是大多數情況下我們並不想將某一臺機器的私鑰推送至所有機器。
1. wget https://github.com/knktc/insecure_pssh/archive/master.zip
或者IE打開https://github.com/knktc/insecure_pssh 然後點擊zip即可下載
2. 將master(insecure_pssh-master.zip) 拷貝至/usr/local
3. unzip master
4. cd insecure_pssh-master
5. 賦予其執行權限:
chmod +x pscp pslurp pssh
6. 直接使用即可,無需安裝了。
新增用戶,並初始化密碼
[root@cobbler66666 pssh]# ./pssh -h hosts.txt -P "echo '123456'|passwd --stdin aa"
192.168.1.133: Changing password for user aa.
passwd: all authentication tokens updated successfully.
[1] 17:14:35 [SUCCESS] [email protected]
192.168.1.244: Changing password for user aa.
passwd: all authentication tokens updated successfully.
[2] 17:14:35 [SUCCESS] [email protected]
查看每個客戶端的具體詳情,例如,查看apache服務的狀態
[root@cobbler66666 pssh]# ./pssh -h hosts.txt -P "/etc/init.d/httpd stop"
192.168.1.133: Stopping httpd: [FAILED]
192.168.1.133:
[1] 17:03:57 [SUCCESS] [email protected]
192.168.1.244: Stopping httpd:
192.168.1.244: [
192.168.1.244: FAILED
192.168.1.244: ]
192.168.1.244:
[2] 17:03:57 [SUCCESS] [email protected]
## pslurp用法-把文件或者目錄並行地從多個遠程主機複製到中心主機上
它從每臺遠程計算機收集指定的文件,但是並不覆蓋文件的本地版本。pslurp 爲每臺遠程計算機創建一個子目錄並把指定的文件複製到此位置
./pslurp -r -h hosts.txt -L /home/dest /test inbank
-r:表示遞歸子目錄
-L:創建子目錄的位置
/home/dest是服務器的目錄
/test是客戶端的目錄
inbank是/home/dest下的子目錄
[root@cobbler66666 home]# tree dest/
dest/
├── 192.168.1.133
│ └── inbank
│ └── 133
└── 192.168.1.244
└── inbank
└── 244
4 directories, 2 files