1. 程式人生 > >自動化運維工具-pdsh工具安裝配置及簡單使用講解

自動化運維工具-pdsh工具安裝配置及簡單使用講解

stat 運維 條件 ati etc amp gen nodes ogl

1、先決條件:
安裝pssh工具的主機針對遠程主機需要配置免秘鑰認證:
ssh-keygen -t rsa
ssh-copy-id [remotehost]

2、下載pssh工具安裝介質:
https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/pdsh/pdsh-2.29.tar.bz2

3、安裝pdsh:
tar -jxvf pdsh-2.29.tar.bz2
cd pdsh-2.29
./configure --with-ssh --with-rsh --with-mrsh --with-mqshell \
--with-dshgroups --with-machines=/etc/pdsh/machines

make && make install

安裝成功後OS會多出pdsh和pdcp兩個命令:

3、pdsh工具使用詳解:

查看幫助:
pdsh --help
pdsh: invalid option -- ‘-‘
Usage: pdsh [-options] command ...
-S return largest of remote command return values
-h output usage menu and quit
-V output version information and quit
-q list the option settings and quit
-b disable ^C status feature (batch mode)
-d enable extra debug information from ^C status
-l user execute remote commands as user
-t seconds set connect timeout (default is 10 sec)
-u seconds set command timeout (no default)
-f n use fanout of n nodes
-w host,host,... set target node list on command line
-x host,host,... set node exclusion list on command line
-R name set rcmd module to name
-M name,... select one or more misc modules to initialize first
-N disable hostname: labels on output lines
-L list info on all loaded modules and exit
-g groupname target hosts in dsh group "groupname"
-X groupname exclude hosts in dsh group "groupname"
-a target all nodes
available rcmd modules: ssh,rsh,exec (default: rsh)

1)pdsh使用案例:

pdsh -w ssh:192.168.0.18[1-4] "uname -n"
pdsh -w ssh:192.168.0.18[1-4] -x db01 "uptime"
pdsh -w ssh:192.168.0.18[1-4],/[234]$/ "uptime"

$ cat /etc/pdsh/machines
db01
db02
db03
db04
$ pdsh -R ssh -a "uptime"

cat /etc/dsh/group/bdgroup
db01
db02
db03
db04
pdsh -R ssh -g bdgroup "uptime"

pdsh -R ssh -a -X bdgroup uptime

pdsh -R ssh -a "sudo touch /mnt/aaa"

pdsh交互式命令窗口:
$ pdsh -R ssh -w db02
pdsh> ls -l
db02: total 139040
db02: drwxr-xr-x 8 hadoop hadoop 233 Jul 26 2014 jdk1.7.0_67
db02: -rwxrwxr-x 1 hadoop hadoop 142376665 Oct 2 07:51 jdk-7u67-linux-x64.tar.gz
pdsh> pwd
db02: /home/hadoop
pdsh> rm -rf jdk1.7.0_67
pdsh> ls -l
db02: total 139040
db02: -rwxrwxr-x 1 hadoop hadoop 142376665 Oct 2 07:51 jdk-7u67-linux-x64.tar.gz
pdsh> sudo tar -zxf jdk-7u67-linux-x64.tar.gz -C /mnt/
pdsh> ls -l /mnt
db02: total 9424
db02: drwxr-xr-x 8 10 143 233 Jul 26 2014 jdk1.7.0_67
pdsh> quit

2)pdcp使用案例:

使用pdcp命令要求本地主機和遠程主機必須安裝pdsh工具,這也是唯一一點麻煩的地方。

pdcp -R ssh -w db02 /mnt/pssh-2.3.1.tar.gz /home/hadoop/

自動化運維工具-pdsh工具安裝配置及簡單使用講解