Pdsh: Difference between revisions

From Leo's Notes
This page was last edited on 23 March 2023, at 16:51.
Created page with "The pdsh command is a parallel version of the dsh (Distributed Shell). It is used to run commands on multiple remote hosts in parallel and supports a number of remote shell programs including SSH. == Cheat sheet == {| class="wikitable" !Action !Command |- |Run a command on all hosts |<code>pdsh -a uptime</code> |- |Run a command on a set of hosts by hostname Or by a specific gender (ie. attribute), see below. |<code>pdsh -w node[0-10] uptime</code><code>pdsh -w cpus=8 u..."
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:


== Cheat sheet ==
== Cheat sheet ==
Depending on your pdsh install, it may default to rsh rather than ssh. Pass in <code>-R ssh</code> to change the default module.
{| class="wikitable"
{| class="wikitable"
!Action
!Action
!Command
!Command
|-
|List all installed modules
|<code>pdsh -L</code>
|-
|Use a specific module. Eg. SSH
|<code>pdsh -R ssh -w node[0-10] uptime</code>
|-
|Connect to a certain nodes with a specific module
|<code>pdsh -w ssh:node[0-5],rsh:node[6-7] uptime</code>
|-
|-
|Run a command on all hosts
|Run a command on all hosts
|<code>pdsh -a uptime</code>
|<code>pdsh -a uptime</code>
|-
|Run a command on all hosts EXCEPT one
|<code>pdsh -a -x exclude-node uptime</code>
|-
|-
|Run a command on a set of hosts by hostname
|Run a command on a set of hosts by hostname
Line 16: Line 29:
|<code><nowiki>pdsh -a cat /etc/redhat-release | dshbak -c</nowiki></code>
|<code><nowiki>pdsh -a cat /etc/redhat-release | dshbak -c</nowiki></code>
|}
|}
== Installation ==
You can install pdsh from the epel repo.
{{Highlight
| code = # yum -y install epel-release
# yum -y install pdsh pdsh-rcmd-ssh
| lang = terminal
}}
Alternatively, install from source from the GitHub repo at: https://github.com/chaos/pdsh
=== Modules ===
Run <code>pdsh -L</code> to list all remote command modules available.
You can see the default module that will be used when running <code>pdsh --help</code>.
==== SSH remote module ====
For SSH support, you will need to install the <code>pdsh-rcmd-ssh</code> package. Additional SSH arguments can be passed by passing in the PDSH_SSH_ARGS_APPEND environment variable. Eg:
{{Highlight
| code = # PDSH_SSH_ARGS_APPEND=”-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=error” pdsh -a uptime
| lang = terminal
}}


== Configuration ==
== Configuration ==


=== Genders file ===
=== Genders file ===
The genders file can be used to give attributes to nodes in a cluster. It can be thought of as groups that can be used as a target when running pdsh commands.
The genders file can be used to give attributes to nodes in a cluster. It can be thought of as groups that can be used as a target when running pdsh commands. While the genders file isn't required, it's still a good idea to have set up because it allows the <code>-a</code> option to function properly.


The genders file is usually located at <code>/etc/genders</code>. Each line can contain one or more hosts and attributes are given as a comma delimited list. Here is an example genders file:
The genders file is usually located at <code>/etc/genders</code>. Each line can contain one or more hosts and attributes are given as a comma delimited list. Here is an example genders file:
Line 36: Line 70:
* Only cluster A nodes with <code>pdsh -w cluster-a</code>
* Only cluster A nodes with <code>pdsh -w cluster-a</code>
* Only nodes with 8 CPUs with <code>pdsh -w cpus=8</code>
* Only nodes with 8 CPUs with <code>pdsh -w cpus=8</code>
== See also ==
* Libgenders man page talks about using genders and target grouping - https://linux.die.net/man/3/libgenders

Latest revision as of 16:51, 23 March 2023

The pdsh command is a parallel version of the dsh (Distributed Shell). It is used to run commands on multiple remote hosts in parallel and supports a number of remote shell programs including SSH.

Cheat sheet

Depending on your pdsh install, it may default to rsh rather than ssh. Pass in -R ssh to change the default module.

Action Command
List all installed modules pdsh -L
Use a specific module. Eg. SSH pdsh -R ssh -w node[0-10] uptime
Connect to a certain nodes with a specific module pdsh -w ssh:node[0-5],rsh:node[6-7] uptime
Run a command on all hosts pdsh -a uptime
Run a command on all hosts EXCEPT one pdsh -a -x exclude-node uptime
Run a command on a set of hosts by hostname

Or by a specific gender (ie. attribute), see below.

pdsh -w node[0-10] uptimepdsh -w cpus=8 uptime
Collect the OS version on all hosts and group it pdsh -a cat /etc/redhat-release | dshbak -c

Installation

You can install pdsh from the epel repo.

# yum -y install epel-release
# yum -y install pdsh pdsh-rcmd-ssh

Alternatively, install from source from the GitHub repo at: https://github.com/chaos/pdsh

Modules

Run pdsh -L to list all remote command modules available.

You can see the default module that will be used when running pdsh --help.

SSH remote module

For SSH support, you will need to install the pdsh-rcmd-ssh package. Additional SSH arguments can be passed by passing in the PDSH_SSH_ARGS_APPEND environment variable. Eg:

# PDSH_SSH_ARGS_APPEND=”-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=error” pdsh -a uptime

Configuration

Genders file

The genders file can be used to give attributes to nodes in a cluster. It can be thought of as groups that can be used as a target when running pdsh commands. While the genders file isn't required, it's still a good idea to have set up because it allows the -a option to function properly.

The genders file is usually located at /etc/genders. Each line can contain one or more hosts and attributes are given as a comma delimited list. Here is an example genders file:

ca-controller management
ca-login cluster-a,login
ca[001-168] cluster-a,cpus=4
cb-login cluster-b,login
cb[091-320] cluster-b,cpus=8

Using this example, you can target:

  • Only the control node with pdsh -w management
  • Only cluster A nodes with pdsh -w cluster-a
  • Only nodes with 8 CPUs with pdsh -w cpus=8

See also