自动化运维工具-pdsh工具安装配置及简单使用讲解
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/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了