使用pssh进行并行批量操作
来源:互联网 发布:最强淘宝系统txt免费 编辑:程序博客网 时间:2024/05/16 07:26
假如同时给上千台服务器执行一个命令,拷贝一个文件,杀一个进程等,有什么简化运维管理的工具呢?在小型使用中我都是使用for循环,数量巨大,一方面不确定操作是否成功,一方面for循环语句性能不好估计且是不是同步并行执行.,这类工具比如pdsh,mussh,cssh,dsh等还有这里提到的pssh:
1 安装:
1 安装:
#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
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
2 pssh使用 (假设ssh已做好SSH信任,ssh信任请参看:关于ssh命令研究以及SSH信任详解)
pssh工具包主要有5个程序:
1 pssh 多主机并行运行命令
pssh工具包主要有5个程序:
1 pssh 多主机并行运行命令
[root@server pssh-2.2.2]# pssh -P -h test.txt uptime
192.168.9.102: 14:04:58 up 26 days, 17:05, 0 users, load average: 0.07, 0.02, 0.00
192.168.9.102: [1] 14:04:58[SUCCESS] 192.168.9.102 9922
192.168.8.171: 14:04:59 up 35 days, 2:01, 6 users, load average: 0.00, 0.00, 0.00
192.168.8.171: [2] 14:04:59[SUCCESS] 192.168.8.171 22
192.168.9.104: 14:04:59 up 7 days, 20:59, 0 users, load average: 0.10, 0.04, 0.01
192.168.9.104: [3]14:04:59 [SUCCESS] 192.168.9.1049922
[root@server pssh-2.2.2]# cat test.txt
192.168.9.102:9922
192.168.9.104:9922
192.168.8.171:22 //注意我的端口号不仅是默认的22
假如想将输出重定向到一个文件 加-o file 选项
192.168.9.102: 14:04:58 up 26 days, 17:05, 0 users, load average: 0.07, 0.02, 0.00
192.168.9.102: [1] 14:04:58[SUCCESS] 192.168.9.102 9922
192.168.8.171: 14:04:59 up 35 days, 2:01, 6 users, load average: 0.00, 0.00, 0.00
192.168.8.171: [2] 14:04:59[SUCCESS] 192.168.8.171 22
192.168.9.104: 14:04:59 up 7 days, 20:59, 0 users, load average: 0.10, 0.04, 0.01
192.168.9.104: [3]14:04:59 [SUCCESS] 192.168.9.1049922
[root@server pssh-2.2.2]# cat test.txt
192.168.9.102:9922
192.168.9.104:9922
192.168.8.171:22 //注意我的端口号不仅是默认的22
假如想将输出重定向到一个文件 加-o file 选项
2 pscp 把文件并行地复制到多个主机上
注意 是从服务器端给客户端传送文件:
注意 是从服务器端给客户端传送文件:
[root@server pssh-2.2.2]# pscp -h test.txt /etc/sysconfig/network /tmp/network //标示将本地的/etc/sysconfig/network传到目标服务器的/tmp/network
3 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目录递归同步到目标服务器的 /tmp/etc目录下,并保持原来的时间戳,使用用户 dongwm
[root@server ~]# prsync -h test.txt -l dongwm -a -r /etc/sysconfig /tmp/etc //标示将本地的/etc/sysconfig目录递归同步到目标服务器的 /tmp/etc目录下,并保持原来的时间戳,使用用户 dongwm
4 pslurp 将文件从远程主机复制到本地,和pscp方向相反:
[root@server ~]# pslurp -h test.txt -L /tmp/test -l root /tmp/network test //标示将目标服务器的/tmp/network文件复制到本地的/tmp/test目录下,并更名为test
[1]14:53:54[SUCCESS] 192.168.9.1029922
[2]14:53:54[SUCCESS] 192.168.9.1049922
[root@server ~]# ll /tmp/test/192.168.9.10
192.168.9.102/ 192.168.9.104/
[root@server ~]# ll /tmp/test/192.168.9.102/
总计 4.0K
-rw-r--r-- 1 root root 60 2011-04-22 14:53 test
[root@server ~]# ll /tmp/test/192.168.9.104/
总计 4.0K
-rw-r--r-- 1 root root 60 2011-04-22 14:53 test
[1]14:53:54[SUCCESS] 192.168.9.1029922
[2]14:53:54[SUCCESS] 192.168.9.1049922
[root@server ~]# ll /tmp/test/192.168.9.10
192.168.9.102/ 192.168.9.104/
[root@server ~]# ll /tmp/test/192.168.9.102/
总计 4.0K
-rw-r--r-- 1 root root 60 2011-04-22 14:53 test
[root@server ~]# ll /tmp/test/192.168.9.104/
总计 4.0K
-rw-r--r-- 1 root root 60 2011-04-22 14:53 test
5 pnuke 并行在远程主机杀进程:
[root@server ~]# pnuke -h test.txt syslog //杀死目标服务器的syslog进程,只要ps进程中出现相关词语 都能杀死[1]15:05:14 [SUCCESS] 192.168.9.1029922
[2]15:05:14 [SUCCESS] 192.168.9.1049922
http://www.dongwm.com/archives/%E4%BD%BF%E7%94%A8pssh%E8%BF%9B%E8%A1%8C%E5%B9%B6%E8%A1%8C%E6%89%B9%E9%87%8F%E6%93%8D%E4%BD%9C/
- 使用pssh进行并行批量操作
- 使用pssh进行并行批量操作
- 使用pssh进行并行批量操作
- 使用pssh进行并行批量操作
- pssh进行并行批量操作
- PSSH,PDSH,MUSSH并行批量操作
- 使用PSSH批量SSH操作Linux服务器
- 使用PSSH批量SSH操作Linux服务器
- 使用PSSH批量操作Linux服务器
- 使用pssh批量管理服务器
- 使用pssh批量管理服务器
- 通过shell脚本批量部署ssh私钥认证以及批量操作工具pssh的简单使用
- 使用JdbcTemplate进行批量操作
- 使用JdbcTemplate进行批量操作
- 并行脚本执行pssh
- pssh 服务器批量管理
- 服务器批量执行工具 PSSH
- Linux下批量管理工具pssh
- 【程序9】题目:要求输出国际象棋棋盘
- 密码-----ACM
- VS与Win7 共舞:用户界面特权隔离
- 让 Intellij IDEA 自动生成 serialVersionUID
- Visio画UML用例图
- 使用pssh进行并行批量操作
- c#中stringbuilder的使用
- 写在开始
- Chrome调试js出现Uncaught SyntaxError: Unexpected identifier
- 排序算法的c++模板实现
- Java乔晓松-jQuery中使用setInterval和setTimeout
- 【SCOI2010】【数论】【扩展欧几里徳】字符串
- Linux 压缩解压命令详解(tar、zip)
- project euler Problem 25