前提做免密
yum安装epel-release后,在yum安装pssh
[root@centos7 ~]# cat /root/iplist
root@172.16.134.128
root@172.16.134.129
root@172.16.134.130
#-h读取主机列表 -i输出信息
[root@centos7 ~]# pssh -h /root/iplist -i 'cat /etc/hosts'
[1] 16:10:57 [SUCCESS] root@172.16.134.128
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.134.128 centos7
172.16.134.129 centos7-mini01
172.16.134.130 centos7-mini02
[2] 16:10:57 [SUCCESS] root@172.16.134.129
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[3] 16:10:57 [SUCCESS] root@172.16.134.130
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
#单引和双引都可以
[root@centos7 ~]# pssh -H "root@172.16.134.128 root@172.16.134.129" -i "cat /etc/hosts"
[1] 16:24:19 [SUCCESS] root@172.16.134.128
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.134.128 centos7
172.16.134.129 centos7-mini01
172.16.134.130 centos7-mini02
[2] 16:24:19 [SUCCESS] root@172.16.134.129
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
#如果没有做免密,可以手动输入,但还是麻烦,一般不用
[root@centos7 ~]# pssh -h /root/iplist -A -i 'ls -l'
Warning: do not enter your password if anyone else has superuser
privileges or access to your account.
Password:
[1] 16:15:48 [SUCCESS] root@172.16.134.128
总用量 12
-rw-------. 1 root root 1659 4月 8 16:53 anaconda-ks.cfg
-rw-r--r--. 1 root root 1707 4月 8 17:04 initial-setup-ks.cfg
-rw-r--r--. 1 root root 60 4月 14 16:04 iplist
drwxr-xr-x. 2 root root 6 4月 8 17:05 公共
drwxr-xr-x. 2 root root 6 4月 8 17:05 模板
drwxr-xr-x. 2 root root 6 4月 8 17:05 视频
drwxr-xr-x. 2 root root 6 4月 8 17:05 图片
drwxr-xr-x. 2 root root 6 4月 8 17:05 文档
drwxr-xr-x. 2 root root 6 4月 8 17:05 下载
drwxr-xr-x. 2 root root 6 4月 8 17:05 音乐
drwxr-xr-x. 2 root root 6 4月 8 17:05 桌面