• pdsh是一个多线程远程shell客户机,它在多个远程主机并行执行命令
  • pdsh可以使用几种不同的远程shell服务,包括标准的 rshKerberos IVssh
  • 在使用pdsh之前,必须保证本地主机和要管理远程主机之间的单向信任
  • pdsh还附带了pdcp命令,该命令可以将本地文件批量复制到远程的多台主机上,这在大规模的文件分发环境下非常有用
  • github:https://github.com/grondo/pdsh

安装

  • CentOS系列可以使用yum安装,pdsh需要epel
Linux:~ # wget https://github.com/grondo/pdsh/archive/pdsh-2.31.tar.gz
Linux:~ # tar xf pdsh-2.31.tar.gz -C /usr/local/src/
Linux:~ # cd /usr/local/src/pdsh-pdsh-2.31/
Linux:/usr/local/src/pdsh-pdsh-2.31 # ./configure \
--prefix=/usr/local/pdsh \
--with-ssh \
--with-machines=/usr/local/pdsh/machines \
--with-dshgroups=/usr/local/pdsh/group \
--with-rcmd-rank-list=ssh \
--with-exec && \
make && \
make install
  • --with-ssh ssh模块(支持ssh)
  • --with-rcmd-rank-list=ssh 指定默认模式为ssh
  • --with-dshgroups= 指定默认主机组路径
  • --with-machines= 指定默认主机列表
    • 在该文件中写入主机地址(或主机名,需要在hosts中写好主机解析),每行一个
    • 存在machines文件,使用pdsh执行时若不指定主机,则默认对machines文件中所有主机执行该命令
  • --with-exec exec模块
  • 其他模块参数可以在pdsh-pdsh-2.31目录下使用 ./configure --help 命令查看
Linux:~ # ll /usr/local/pdsh/bin/
total 516
-rwxr-xr-x 1 root root 8638 Jan 29 22:15 dshbak
-rwxr-xr-x 1 root root 171664 Jan 29 22:15 pdcp
-rwxr-xr-x 1 root root 171664 Jan 29 22:15 pdsh
-rwxr-xr-x 1 root root 171664 Jan 29 22:15 rpdcp
Linux:~ # echo 'export PATH=/usr/local/pdsh/bin:$PATH' >> /etc/profile
Linux:~ # source /etc/profile
"将pdsh的所有命令追加到环境变量中"
Linux:~ # pdsh -V
pdsh-2.31
rcmd modules: ssh,rsh,exec (default: ssh)
misc modules: machines,dshgroup

使用

  • 语法:pdsh <参数> <需要并行执行的命令>

    • 如果只输入前面两部分,回车后可进入pdsh交互式命令行(若是编译安装需要启用--with-readline),再输入并行执行的命令部分
  • 常用参数:
    • -w 指定主机 -x 排除指定的主机

      • 目标主机可以使用Ip地址或主机名(确保该主机名已经在/etc/hosts中存在解析)
      • 多个主机之间可以使用逗号分隔,可重复使用该参数指定多个主机;可以使用简单的正则
    • -g 指定主机组 -G 排除指定主机组
    • -l 目标主机的用户名
      • 如果不指定用户名,默认以当前用户名作为在目标主机上执行命令的用户名
    • -N 用来关闭目标主机所返回值前的主机名显示

示例

-w 指定主机

Linux:~ # pdsh -w ssh:192.168.72.12,192.168.72.13,192.168.72.14 date
192.168.72.12: Sun Jan 31 12:35:36 CST 2021
192.168.72.14: Sun Jan 31 12:35:36 CST 2021
192.168.72.13: Sun Jan 31 12:35:36 CST 2021
"pdsh -w ssh:192.168.72.[12-14] date 也可以"

-l 指定用户

Linux:~ # pdsh -w ssh:192.168.72.[12-14] -l linux date
192.168.72.12: Sun Jan 31 12:36:32 CST 2021
192.168.72.13: Sun Jan 31 12:36:32 CST 2021
192.168.72.14: Sun Jan 31 12:36:32 CST 2021

-g指定用户组

Linux:~ # mkdir /usr/local/pdsh/group
Linux:~ # cat > /usr/local/pdsh/group/test1 <<EOF
192.168.72.12
192.168.72.13
192.168.72.14
EOF
Linux:~ # pdsh -g test1 'uname -r'
192.168.72.12: 4.4.73-5-default
192.168.72.14: 4.4.73-5-default
192.168.72.13: 4.4.73-5-default

主机列表

Linux:~ # cat > /usr/local/pdsh/machines <<EOF
192.168.72.12
192.168.72.13
192.168.72.14
EOF
Linux:~ # pdsh -a uptime
192.168.72.12: 12:37pm up 0:08, 2 users, load average: 0.08, 0.13, 0.09
192.168.72.13: 12:37pm up 0:07, 1 user, load average: 0.12, 0.05, 0.01
192.168.72.14: 12:37pm up 0:07, 1 user, load average: 0.00, 0.01, 0.00

交互式界面

"有exec模块即可,或者readline模块"
Linux:~ # pdsh -a
pdsh> date
192.168.72.14: Sun Jan 31 12:38:05 CST 2021
192.168.72.13: Sun Jan 31 12:38:05 CST 2021
192.168.72.12: Sun Jan 31 12:38:05 CST 2021
pdsh> whoami
192.168.72.12: root
192.168.72.14: root
192.168.72.13: root
pdsh> exit "退出交互式界面"

Linux海王 之 pdsh (并行管理工具)的更多相关文章

  1. ​Linux环境下搭建禅道管理工具-包含软件资源

    ​Linux环境下搭建禅道管理工具 1:百度云盘下载: 禅道--链接: https://pan.baidu.com/s/1Stu7nOZVIPO5TnpJWjWtiQ 提取码:dnik CentOs操 ...

  2. 并行管理工具——pdsh

    1. pdsh安装2. pdsh常规使用2.1 pdsh2.2 pdcp 并行管理的方式有很多种: 命令行 一般是for循环 脚本 一般是expect+ssh等自编辑脚本 工具 pssh,pdsh,m ...

  3. Linux下取代top的进程管理工具 htop

    一.htop 简介 This is htop, an interactive process viewer for Linux. It is a text-mode application (for ...

  4. linux(centos)下安装supervisor进程管理工具

    在接触supervisor进程管理工具之前,使用springboot打包部署到linux服务器的流程是这样子的,如下图所示: 上图展示的就是最一般的流程,如果项目是小项目或者demo可以这样子去部署, ...

  5. Linux服务器中安装python包管理工具pip

    pip是python的包管理工具,python的强大之处除了在于语法的简练,还有就是对众多的库支持了. 1.下载pip包管理工具 链接地址:https://pypi.python.org/pypi/p ...

  6. 搭建KVM环境——07 带GUI的Linux上安装KVM图形界面管理工具

    清空yum源缓存,并查看yun源 [root@CentOS2 ~]# yum clean all Loaded plugins: fastestmirror, langpacks Cleaning r ...

  7. Linux下KVM的图形界面管理工具(virt-manager)(桌面版)

    背景: virt-manager是用于管理KVM虚拟环境的主要工具,virt-manager默认设置下需要使用root用户才能够使用该工具.当你想在KVM hypervisor服务器上托管虚拟机,由最 ...

  8. linux CentOS6.5 安装SVN & 可视化管理工具iF.SVNAdmin

    转:http://tanghenxin.lofter.com/post/1cc667b3_5ac50dc 实际系统环境: CentOS 6.5 x64 一.安装Apache 通常系统都已经装好了,但我 ...

  9. Linux下KVM的图形界面管理工具(WebVirtMgr)(Web版)

    WebVirtMgr面板 截图 介绍 WebVirtMgr是一个基于libvirt的Web界面,用于管理虚拟机.它允许您创建和配置新域,并调整域的资源分配.VNC查看器为来宾域提供完整的图形控制台.K ...

随机推荐

  1. 新增访客数量MR统计之NewInstallUserMapper相关准备

    关注公众号:分享电脑学习回复"百度云盘" 可以免费获取所有学习文档的代码(不定期更新)云盘目录说明:tools目录是安装包res 目录是每一个课件对应的代码和资源等doc 目录是一 ...

  2. Centos6.9虚拟机环境搭建

    原文链接:https://www.toutiao.com/i6481534700216123918/ 一.准备工具 VMware Workstation CentOS-6.9-x86_64-minim ...

  3. less 循环模拟sass的for循环效果

    // 输入框部分宽度 从10px到600px 相隔10像素 .generate-widths(600); .generate-widths(@n, @i: 10) when (@i =< @n) ...

  4. 【涨姿势】原来golang的case <-time.After(xxx)还有这样的坑

    偶然看到这样一篇文章:<使用 pprof 排查 Golang 内存泄露>https://www.toutiao.com/i6881796351139676680/ 最后一段让我很疑惑: 修 ...

  5. manjaro20安装TIM

    安装 yaourt -S deepin-wine-tim 失败 yaourt -S deepin.qq.office 成功,但是tim版本没有待办,版本比较旧. 配置分辨率 https://blog. ...

  6. 深入理解http1.x、http 2和https

    转自 https://segmentfault.com/a/1190000015316332 一.HTTP/1.x Http1.x 缺陷:线程阻塞,在同一时间,同一域名的请求有一定数量限制,超过限制数 ...

  7. 不难懂——th: 的常用标签

    关键字>       功能介绍    >      案例 th:id 替换id <input th:id="'xxx' + ${collect.id}"/> ...

  8. Kubernetes集群PV和PVC详解

    Kubernetes集群高级存储资源PV及PVC 文章目录 Kubernetes集群高级存储资源PV及PVC 1.高级存储PV和PVC概念部分 2.PV和PVC资源的生命周期 3.PV资源介绍与案例配 ...

  9. http中的8种请求介绍

    HTTP协议的8种请求类型介绍 HTTP协议中共定义了八种方法或者叫"动作"来表明对Request-URI指定的资源的不同操作方式,具体介绍如下: OPTIONS:返回服务器针对特 ...

  10. Git常用命令(超实用)

    Git常用命令 一.Git常用命令 1.1 创建SSH Key 1.2 仓库 1.3 增加/删除文件 1.4 代码提交 1.5 分支 1.6 标签 1.7 查看信息 1.8 远程同步 1.9 撤销 1 ...