linux中ClusterShell怎么用

56次阅读
没有评论

共计 5477 个字符,预计需要花费 14 分钟才能阅读完成。

这篇文章给大家分享的是有关 linux 中 ClusterShell 怎么用的内容。丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,一起跟随丸趣 TV 小编过来看看吧。

ClusterShell

ClusterShell 是一个事件驱动的开源 Python 库,旨在在服务器场或大型 Linux 集群上并行运行本地或远程命令。(clush 即 ClusterShell)。

它将处理在 HPC 集群上遇到的常见问题,例如在节点组上操作,使用优化过的执行算法运行分布式命令,以及收集结果和合并相同的输出,或检索返回代码。

ClusterShell 可以利用已安装在系统上的现有远程 shell 设施,如 SSH。

ClusterShell 的主要目标是通过为开发人员提供轻量级、但可扩展的 Python API 来改进高性能集群的管理。它还提供了 clush、clubak 和 cluset/nodeset 等方便的命令行工具,可以让传统的 shell 脚本利用这个库的一些功能。

ClusterShell 是用 Python 编写的,它需要 Python(v2.6+ 或 v3.4+)才能在你的系统上运行。

如何在 Linux 上安装 ClusterShell?

ClusterShell 包在大多数发行版的官方包管理器中都可用。因此,使用发行版包管理器工具进行安装。

对于 Fedora 系统,使用 DNF 命令来安装 clustershell。

$ sudo dnf install clustershell

如果系统默认是 Python 2,这会安装 Python 2 模块和工具,可以运行以下命令安装 Python 3 开发包。

$ sudo dnf install python3-clustershell

在执行 clustershell 安装之前,请确保你已在系统上启用 EPEL 存储库。

对于 RHEL/CentOS 系统,使用 YUM 命令 来安装 clustershell。

$ sudo yum install clustershell

如果系统默认是 Python 2,这会安装 Python 2 模块和工具,可以运行以下命令安装 Python 3 开发包。

$ sudo yum install python34-clustershell

对于 openSUSE Leap 系统,使用 Zypper 命令 来安装 clustershell。

$ sudo zypper install clustershell

如果系统默认是 Python 2,这会安装 Python 2 模块和工具,可以运行以下命令安装 Python 3 开发包。

$ sudo zypper install python3-clustershell

对于 Debian/Ubuntu 系统,使用 APT-GET 命令 或 APT 命令 来安装 clustershell。

$ sudo apt install clustershell

如何在 Linux 使用 PIP 安装 ClusterShell?

可以使用 PIP 安装 ClusterShell,因为它是用 Python 编写的。

在执行 clustershell 安装之前,请确保你已在系统上启用了 Python 和 PIP。

$ sudo pip install ClusterShell

如何在 Linux 上使用 ClusterShell?

与其他实用程序(如 pssh 和 dsh)相比,它是直接了当的优秀工具。它有很多选项可以在远程并行执行。

在开始使用 clustershell 之前,请确保你已启用系统上的无密码登录。

以下配置文件定义了系统范围的默认值。你不需要修改这里的任何东西。

$ cat /etc/clustershell/clush.conf

如果你想要创建一个服务器组,那也可以。默认情况下有一些示例,请根据你的要求执行相同操作。

$ cat /etc/clustershell/groups.d/local.cfg

只需按以下列格式运行 clustershell 命令即可从给定节点获取信息:

$ clush -w 192.168.1.4,192.168.1.9 cat /proc/version192.168.1.9: Linux version 4.15.0-45-generic ([email protected]) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019192.168.1.4: Linux version 3.10.0-957.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Thu Nov 8 23:39:32 UTC 2018

选项:

-w: 你要运行该命令的节点。

你可以使用正则表达式而不是使用完整主机名和 IP:

$ clush -w 192.168.1.[4,9] uname -r192.168.1.9: 4.15.0-45-generic192.168.1.4: 3.10.0-957.el7.x86_64

或者,如果服务器位于同一 IP 系列中,则可以使用以下格式:

$ clush -w 192.168.1.[4-9] date192.168.1.6: Mon Mar 4 21:08:29 IST 2019192.168.1.7: Mon Mar 4 21:08:29 IST 2019192.168.1.8: Mon Mar 4 21:08:29 IST 2019192.168.1.5: Mon Mar 4 09:16:30 CST 2019192.168.1.9: Mon Mar 4 21:08:29 IST 2019192.168.1.4: Mon Mar 4 09:16:30 CST 2019

clustershell 允许我们以批处理模式运行命令。使用以下格式来实现此目的:

$ clush -w 192.168.1.4,192.168.1.9 -bEnter  quit  to leave this interactive modeWorking with nodes: 192.168.1.[4,9]clush  hostnamectl---------------192.168.1.4--------------- Static hostname: CentOS7.2daygeek.com Icon name: computer-vm Chassis: vm Machine ID: 002f47b82af248f5be1d67b67e03514c Boot ID: f9b37a073c534dec8b236885e754cb56 Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-957.el7.x86_64 Architecture: x86-64---------------192.168.1.9--------------- Static hostname: Ubuntu18 Icon name: computer-vm Chassis: vm Machine ID: 27f6c2febda84dc881f28fd145077187 Boot ID: f176f2eb45524d4f906d12e2b5716649 Virtualization: oracle Operating System: Ubuntu 18.04.2 LTS Kernel: Linux 4.15.0-45-generic Architecture: x86-64clush  free -m---------------192.168.1.4--------------- total used free shared buff/cache availableMem: 1838 641 217 19 978 969Swap: 2047 0 2047---------------192.168.1.9--------------- total used free shared buff/cache availableMem: 1993 352 1067 1 573 1473Swap: 1425 0 1425clush  w---------------192.168.1.4--------------- 09:21:14 up 3:21, 3 users, load average: 0.00, 0.01, 0.05USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATdaygeek :0 :0 06:02 ?xdm? 1:28 0.30s /usr/libexec/gnome-session-binary --session gnome-classicdaygeek pts/0 :0 06:03 3:17m 0.06s 0.06s bashdaygeek pts/1 192.168.1.6 06:03 52:26 0.10s 0.10s -bash---------------192.168.1.9--------------- 21:13:12 up 3:12, 1 user, load average: 0.08, 0.03, 0.00USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATdaygeek pts/0 192.168.1.6 20:42 29:41 0.05s 0.05s -bashclush  quit

如果要在一组节点上运行该命令,请使用以下格式:

$ clush -w @dev uptimeor$ clush -g dev uptimeor$ clush --group=dev uptime 192.168.1.9: 21:10:10 up 3:09, 1 user, load average: 0.09, 0.03, 0.01192.168.1.4: 09:18:12 up 3:18, 3 users, load average: 0.01, 0.02, 0.05

如果要在多个节点组上运行该命令,请使用以下格式:

$ clush -w @dev,@uat uptimeor$ clush -g dev,uat uptimeor$ clush --group=dev,uat uptime 192.168.1.7: 07:57:19 up 59 min, 1 user, load average: 0.08, 0.03, 0.00192.168.1.9: 20:27:20 up 1:00, 1 user, load average: 0.00, 0.00, 0.00192.168.1.5: 08:57:21 up 59 min, 1 user, load average: 0.00, 0.01, 0.05

clustershell 允许我们将文件复制到远程计算机。将本地文件或目录复制到同一个远程节点:

$ clush -w 192.168.1.[4,9] --copy /home/daygeek/passwd-up.sh

我们可以通过运行以下命令来验证它:

$ clush -w 192.168.1.[4,9] ls -lh /home/daygeek/passwd-up.sh192.168.1.4: -rwxr-xr-x. 1 daygeek daygeek 159 Mar 4 09:00 /home/daygeek/passwd-up.sh192.168.1.9: -rwxr-xr-x 1 daygeek daygeek 159 Mar 4 20:52 /home/daygeek/passwd-up.sh

将本地文件或目录复制到不同位置的远程节点:

$ clush -g uat --copy /home/daygeek/passwd-up.sh --dest /tmp

我们可以通过运行以下命令来验证它:

$ clush --group=uat ls -lh /tmp/passwd-up.sh192.168.1.7: -rwxr-xr-x. 1 daygeek daygeek 159 Mar 6 07:44 /tmp/passwd-up.sh

将文件或目录从远程节点复制到本地系统:

$ clush -w 192.168.1.7 --rcopy /home/daygeek/Documents/magi.txt --dest /tmp

我们可以通过运行以下命令来验证它:

$ ls -lh /tmp/magi.txt.192.168.1.7-rw-r--r-- 1 daygeek daygeek 35 Mar 6 20:24 /tmp/magi.txt.192.168.1.7

感谢各位的阅读!关于“linux 中 ClusterShell 怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-25发表,共计5477字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)