使用pssh批量管理服务器
来源:互联网 发布:莱州网络销售招聘 编辑:程序博客网 时间:2024/05/01 22:50
pssh是一个可以在多台服务器上执行命令的工具,同时支持拷贝文件,是同类工具中很出色的。使用是必须在各个服务器上配置好密钥认证访问。
在系统centos 5.6 64位 和 red hat enterprise linux 6.1 64位中测试通过
1 安装pssh
在http://www.theether.org/pssh/ 或者http://code.google.com/p/parallel-ssh/下载pssh最新版本
# wget http://www.theether.org/pssh/pssh-1.4.3.tar.gz
# tar zxvf pssh-1.4.3.tar.gz
# cd pssh-1.4.3
# wget 'http://peak.telecommunity.com/dist/ez_setup.py'
# python ez_setup.py
# python setup.py install
2 pssh使用
- Usage: pssh [OPTIONS] -h hosts.txt prog [arg0] ..
- -h --hosts hosts file (each line "host[:port] [user]")
- -l --user username (OPTIONAL)
- -p --par max number of parallel threads (OPTIONAL)
- -o --outdir output directory for stdout files (OPTIONAL)
- -e --errdir output directory for stderr files (OPTIONAL)
- -t --timeout timeout (secs) (-1 = no timeout) per host (OPTIONAL)
- -O --options SSH options (OPTIONAL)
- -v --verbose turn on warning and diagnostic messages (OPTIONAL)
- -P --print print output as we get it (OPTIONAL)
- -i --inline inline aggregated output for each server (OPTIONAL)
- Example: pssh -h nodes.txt -l irb2 -o /tmp/foo uptime
创建管理服务器列表文件
vi server1.txt
192.168.1.11
192.168.1.12
192.168.1.13
192.168.1.14
在各个主机执行命令hostname
# pssh -h server1.txt -l root -P hostname
在各个主机传送文件
pscp -h server1.txt -l root test.txt /tmp/test.txt
prsync -r -h server1.txt -l root foo /home/irb2/foo
把文件或者目录并行地从多个远程主机复制到中心主机它从每台远程计算机收集指定的文件,但是并不覆盖文件的本地版本。pslurp 为每台远程计算机创建一个子目录并把指定的文件复制到此位置
# pslurp -r -h /home/server1.txt /home/test.txt /home
/home/server1.txt 为远程文件 /home为本地目录,也可以为拷贝到本地后的文件名
# pslurp -r -h /home/server1.txt -L /srv/test/ /srv llll
其中 -r表示递归子目录,-L 选项指定创建子目录的位置,/srv为远程目录,lll为拷贝到本地后的目录名
pnuke用法-并行地在多个远程主机上杀死进程
pnuke 相当于运行 ssh host killall。pnuke 的参数是一个模式。在远程计算机上运行的名称符合这个模式的所有进程都被杀死。可以用此命令方便地在一组服务器上停止同一守护进程。
# pnuke -h /home/server.txt --user=root cron
命令的结果则是在server.txt文件中指定的主机上执行killall cron命令 其中cron为匹配到cron的进程, 只要ps进程中出现相关词语 都能杀死
1 安装:
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
pssh工具包主要有5个程序:
1 pssh 多主机并行运行命令
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.104 9922
[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 选项
注意 是从服务器端给客户端传送文件:
[root@server ~]# prsync -h test.txt -l dongwm -a -r /etc/sysconfig /tmp/etc //标示将本地的/etc/sysconfig目录递归同步到目标服务器的 /tmp/etc目录下,并保持原来的时间戳,使用用户 dongwm
[1] 14:53:54 [SUCCESS] 192.168.9.102 9922
[2] 14:53:54 [SUCCESS] 192.168.9.104 9922
[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] 15:05:14 [SUCCESS] 192.168.9.102 9922
[2] 15:05:14 [SUCCESS] 192.168.9.104 9922
- 使用pssh批量管理服务器
- 使用pssh批量管理服务器
- pssh 服务器批量管理
- Linux集群管理工具pssh批量管理服务器
- Linux集群管理工具PSSH批量管理服务器
- 使用PSSH批量SSH操作Linux服务器
- 使用PSSH批量SSH操作Linux服务器
- 使用PSSH批量操作Linux服务器
- 服务器批量执行工具 PSSH
- 使用pssh进行并行批量操作
- 使用pssh进行并行批量操作
- 使用pssh进行并行批量操作
- 使用pssh进行并行批量操作
- 通过pssh同时管理多台服务器
- linux批量管理推送工具mussh和pssh介绍
- SVN化的WEB目录更新方案以及管理服务器群的PSSH并行工具的使用
- 灵活使用ssh、dsh和pssh高效管理大量计算机
- pssh进行并行批量操作
- 冒泡法排序
- 【UML 建模】在线UML建模工具 ProcessOn 使用详解
- 深度优先搜索
- OC学习笔记八 Block
- 2013-12-阿里技术沙龙:双十一背后的那些事
- 使用pssh批量管理服务器
- return finally
- GYM 100285 B. The battle near the swamp(水~)
- java基础_多线程
- PCIE的mmio内存映射访问机制
- Code Forces 476C Dreamoon and Sums
- 《JAVA设计模式》之适配器模式
- 简单的一些字符串实现函数
- HDU 5335 Walk Out (BFS后贪心)