dropdown menu

DSH (Distributed Shell):

DSH is a tool for running commands on a list of AIX servers parallel (no long running for cycle is needed to go through on a list of servers, but the command will be executed instantly on all servers). DSH is installed by default in AIX and it can be configured to use rsh or ssh. (By default the maximum number of concurrently run execution is 64. This can be controlled by -f flag. If it is set to 1, that is similar to serial execution.)

# lslpp -L csm.dsh
Fileset                      Level  State  Type  Description (Uninstaller)
csm.dsh              C     F    Cluster Systems Management Dsh

# ls -l /usr/bin/dsh
lrwxrwxrwx    1 bin      bin              16 Jul 22 2009  /usr/bin/dsh -> /opt/csm/bin/dsh

Commands which available with this fileset: dsh, dcp, dping, dshbak

dsh: remote command execution (as ssh)
dcp: remote copy (as scp)
dping: ping utility (list of servers can be pinged at the same time)
dshbak: it formats the output (for better verview)

(SSH key should be distributed, so no password will be asked during the dsh session.)


DSH config:

dsh needs to know what to use for remote session (ssh or rsh) and it needs a node list file as well.

To configure them these variables are needed:
(these can be put in .kshrc file, so not needed to configure each time)

export DSH_NODE_LIST=/bb/AIX_list                    <--file contains the list of servers

export DCP_NODE_RCP=/usr/bin/scp                     <--which command to use for remote copy
export DCP_NODE_OPTS="-oStrictHostKeyChecking=no -q"   <--which flags to add for remote copy command (-q will suppress banner)

export DSH_NODE_RSH=/usr/bin/ssh                     <--which command to use for remote command execution
export DSH_NODE_OPTS="-oStrictHostKeyChecking=no -q"   <--which flags to add for remote command execution (-q will suppress banner)

export DSH_LOG=/bb/dsh.log                          <--where to log (only if needed)


Sample output: Finding which LPAR is holding the optical drive:

# dsh lsdev -Cc cdrom|dshbak
HOST: aix1
cd0 Available Virtual SCSI Optical Served by VIO Server

HOST: aix2
cd0 Defined  Virtual SCSI Optical Served by VIO Server

HOST: aix3
cd0 Defined  Virtual SCSI Optical Served by VIO Server

Something like this can be put in .kshrc as well, so switching between server lists is easier:
alias dsh_test='export DSH_NODE_LIST=/bb/dsh_test'
alias dsh_dev='export DSH_NODE_LIST=/bb/dsh_dev'
alias dsh_prod='export DSH_NODE_LIST=/bb/dsh_prod'


dsh -q displays the values of the dsh variables (DSH_NODE_LIST, DCP_NODE_RCP...)
dsh <command> runs comamnd on each server in DSH_NODE_LIST
dsh <command> | dshbak      same as above, just formats output to separate each host
dsh -w aix1,aix2 <command> execute command on the given servers (dsh -w aix1,aix2 "oslevel -s")
dsh -e <script>            to run the given script on each server
                         (for me it was faster to dcp and after run the script with dsh on the remote server)

dcp <file> <location>       copies a file to the given location (without location home dir will be used)

dping -n aix1, aix2 do a ping on the listed servers
dping -f <filename> do a ping for all servers given in the file (-f)




PSSH (Parallel SSH)

Parallel SSH utility is similar to DSH, the commands can be run on several hosts at the same time.

Installation package (rpm) can be found on perzl.org, but it has a dependency: python
(If there are some problems during install, you can try manually copy the parallel SSH binaries to any location from which you want to run them)

To run pssh a hosts file is needed, which contains the list of hosts where commands will be executed.

# pssh -h <hostlist> -i <command>
     -h   hosts file, it can conatin port or user as well (each line "[user@]host[:port]")
     -i   displays output on screen (inline on screen)
     -l   username (OPTIONAL)
     -p   max number of parallel threads (OPTIONAL)
     -o   outdir  output directory for stdout files (OPTIONAL)
     -t   timeout timeout in seconds to do ssh to a host (OPTIONAL)
     -v   verbose turn on warning and diagnostic messages (OPTIONAL)
     -O   options SSH options (OPTIONAL)

pssh -i -h hosts.txt echo "hello, world" print "hello, world" from each host specified in the file hosts.txt:
pssh -i -h hosts.txt -l root "oslevel -s" run a command as root
pssh -i -h hosts.txt -t 0 sleep 10000 run a command without timing out (or if you want timeout change the value of -t)
pssh -i -h hosts.txt -p 100 "uptime" if hosts.txt has 100 server, parallelism can be set to 100 to ensure concurrent run
pssh -i -h hosts.txt -x "-O StrictHostKeyChecking=no -O UserKnownHostsFile=/dev/null" echo hi     run pssh to use ssh options
pssh -i -h hosts.txt -I < script.sh run a script on each server (-I tells read commands from standard input)
                                         ("< script.sh" feeds this script, without copying it to each server)



It can copy files to multiple hosts (similar to dscp)

pscp -h <hostlist> <file> <location>
     -h   hosts file (each line "[user@]host[:port]")
     -r   ecusively copy directories (OPTIONAL)
     -l   username (OPTIONAL)
     -p   max number of parallel threads (OPTIONAL)
     -t   imeout   timeout in seconds to do scp to a host (OPTIONAL)
     -O   options   SSH options (OPTIONAL)

pscp -h hosts.txt script.sh /tmp/script.sh copy script.sh to /tmp on each server listed in hosts.txt

No comments:

Post a Comment