ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

pssh批量管理服务器

2022-08-11 20:02:57  阅读:150  来源: 互联网

标签:pssh 批量 -- host hosts 服务器 txt irb2


pssh批量管理服务器

目录

pssh是一个python编写可以在多台服务器上执行命令的工具,同时支持拷贝文件,是同类工具中很出色的,类似pdsh。

安装

  • 编译安装
1 2 3 4 wget http://parallel-ssh.googlecode.com/files/pssh-2.3.1.tar.gz tar zxvf pssh-2.3.1.tar.gz cd pssh-2.3.1/ python setup.py install
  • yum安装
1 2 yum -y install epel-release yum -y install pssh
  • cygwin下安装
1 2 3 apt-cyg install python-setuptools easy_install pip pip install pssh

使用pssh

简要范例

  • pssh 在多个主机上并行地运行命令。
    • pssh -h hosts.txt -l irb2 -o /tmp/foo uptime
  • pscp 传输文件到多个主机,类似scp。
    • pscp -h hosts.txt -l irb2 foo.txt /home/irb2/foo.txt
  • pslurp 从多个主机拷贝到本地。
    • Example: pslurp -h hosts.txt -L /tmp/outdir -l irb2 /home/irb2/foo.txt foo.txt
  • pnuke 在多个主机并行地杀进程。
    • pnuke -h hosts.txt -l irb2 java
  • prsync 使用rsync协议从本地同步到远程主机。
    • prsync -r -h hosts.txt -l irb2 foo /home/irb2/foo
  • 避免ssh检查host keys:
    1 2 3 pssh -i -H host1 -H host2 \ -x "-O StrictHostKeyChecking=no -O UserKnownHostsFile=/dev/null -O GlobalKnownHostsFile=/dev/null" \ echo hi
    • 也可以加到.ssh/config
      1 2 3 4 5 cat >>~/.ssh/config <<EOF StrictHostKeyChecking=no UserKnownHostsFile=/dev/null GlobalKnownHostsFile=/dev/null EOF
  • host文件格式
    1 2 3 4 5 # 可以有空行,#开头的是注释行 # 每行一个主机,格式: [user@]host[:port] 192.168.1.4 root@192.168.1.5 root@192.168.1.7:2203

pssh --help

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 Usage: pssh [OPTIONS] command [...]   Options:   --version             show programs version number and exit   --help                show this help message and exit   -h HOST_FILE, --hosts=HOST_FILE                         hosts file (each line "[user@]host[:port]")                         #如果指定了多个host文件(多次使用-h选择),pssh将它们连接在一起使用;                         #如果同一主机出现多次,pssh将会多次连接。   -H HOST_STRING, --host=HOST_STRING                         additional host entries ("[user@]host[:port]")   -l USER, --user=USER  username (OPTIONAL)   -p PAR, --par=PAR     max number of parallel threads (OPTIONAL)   -o OUTDIR, --outdir=OUTDIR                         output directory for stdout files (OPTIONAL)   -e ERRDIR, --errdir=ERRDIR                         output directory for stderr files (OPTIONAL)   -t TIMEOUT, --timeout=TIMEOUT                         timeout (secs) (0 = no timeout) per host (OPTIONAL)   -O OPTION, --option=OPTION                         SSH option (OPTIONAL)   -v, --verbose         turn on warning and diagnostic messages (OPTIONAL)   -A, --askpass         Ask for a password (OPTIONAL)   -x ARGS, --extra-args=ARGS                         Extra command-line arguments, with processing for                         spaces, quotes, and backslashes   -X ARG, --extra-arg=ARG                         Extra command-line argument   -i, --inline          inline aggregated output and error for each server   --inline-stdout       inline standard output for each server   -I, --send-input      read from standard input and send as input to ssh   -P, --print           print output as we get it   Example: pssh -h hosts.txt -l irb2 -o /tmp/foo uptime

标签:pssh,批量,--,host,hosts,服务器,txt,irb2
来源: https://www.cnblogs.com/zafu/p/16577653.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有