Skip to content

pdsh 并行执行命令

pdsh全称是parallel distributed shell,可以并行执行对远程目标主机的操作。当需要在集群中批量对多个节点进行命令操作时可以使用该工具,SonmiHPC中已经预集成了该工具,因此可以直接进行使用。

下面以由3个节点组成的集群为例,进行说明。

[sonmi@sonmi ~]$ sonmictl node info 
+-------------+-----------------+-------------------+------+-----------------+----------+-------+
| NODENAME    | CPU ALLOC/TOTAL | MEMORY FREE/TOTAL | GRES | CPU TEMPERATURE | CPU LOAD | STATE |
+-------------+-----------------+-------------------+------+-----------------+----------+-------+
|    sonmi    |      0 / 8      |   4.1GB / 7.5GB   |  --  |  VM Not Support |   0.03   |  IDLE |
| compute-0-0 |      0 / 8      |   5.2GB / 7.5GB   |  --  |  VM Not Support |   0.00   |  IDLE |
| compute-0-1 |      0 / 8      |    6GB / 7.5GB    |  --  |  VM Not Support |   0.00   |  IDLE |
+-------------+-----------------+-------------------+------+-----------------+----------+-------+
[sonmi@sonmi ~]$ sonmictl node info 
+-------------+-----------------+-------------------+------+-----------------+----------+-------+
| NODENAME    | CPU ALLOC/TOTAL | MEMORY FREE/TOTAL | GRES | CPU TEMPERATURE | CPU LOAD | STATE |
+-------------+-----------------+-------------------+------+-----------------+----------+-------+
|    sonmi    |      0 / 8      |   4.1GB / 7.5GB   |  --  |  VM Not Support |   0.03   |  IDLE |
| compute-0-0 |      0 / 8      |   5.2GB / 7.5GB   |  --  |  VM Not Support |   0.00   |  IDLE |
| compute-0-1 |      0 / 8      |    6GB / 7.5GB    |  --  |  VM Not Support |   0.00   |  IDLE |
+-------------+-----------------+-------------------+------+-----------------+----------+-------+

使用示例

  1. 对所有节点执行hostname命令

-w: 参数指定要执行的节点,有多个节点可以用逗号进行拼接,也可以用[]指定连续的多个节点,如compute-0-[0-2,5-8]

shell
pdsh -w sonmi,compute-0-[0-1] hostname
pdsh -w sonmi,compute-0-[0-1] hostname

输出如下:

sonmi: sonmi.local
compute-0-0: compute-0-0
compute-0-1: compute-0-1
sonmi: sonmi.local
compute-0-0: compute-0-0
compute-0-1: compute-0-1

2.排除部分节点

-x 排除指定的节点

shell
pdsh -w compute-0-[0-8] -x compute-0-5 hostname
pdsh -w compute-0-[0-8] -x compute-0-5 hostname

本站内容未经授权禁止转载
联系邮箱: [email protected]