首页 > 编程知识 正文

linux中ps命令,linux的ps命令用法

时间:2023-05-03 21:38:14 阅读:231317 作者:226

linux pssh

I'm sure you've heard that all the cool kids are playing with orchestration automation these days. But do you know why? Well first, the resources consumed by modern microservices workloads are becoming much more complex and deploy to far more instances than ever before. And second, more and more of those resources are virtual rather than physical - so many of them will only exist for minutes or even seconds.

我敢肯定,您已经听说过这些天所有很棒的孩子都在使用编排自动化。 但是你知道为什么吗? 首先,现代微服务工作负载消耗的资源变得越来越复杂,并且部署到比以前更多的实例上。 其次,越来越多的资源是虚拟的,而不是物理的-因此,它们中的许多资源将只存在几分钟甚至几秒钟。

All of which means that even if you wanted to go around logging into each of your many servers, it just wouldn't make sense. In most cases in fact, it wouldn't even be possible. Instead, you're going to be running a lot of clever scripts. And the tools you use to run those kinds of scripts are generally called orchestrators.

所有这些都意味着,即使您想遍历登录到许多服务器中的每台服务器,也没有任何意义。 实际上,在大多数情况下,这甚至是不可能的。 相反,您将运行许多巧妙的脚本。 用于运行这类脚本的工具通常称为协调器。

I'm sure you've encountered at least one or two members of the orchestration club. Besides Ansible, there's Terraform, Chef, Puppet and others. But there are also lower-level tools that work as add-ons to core Linux tools like SSH. Although, seeing how it'll run natively on Windows and, of course, macOS, I'm not sure it's quite correct to call SSH a "Linux" tool any more.

我确定您至少遇到了编排俱乐部的一两个成员。 除了Ansible,还有Terraform,Chef,Puppet等。 但是,还有一些低级工具可以作为SSH等核心Linux工具的附件。 尽管看到它如何在Windows以及macOS上本机运行,但我不确定再将SSH称为“ Linux”工具是否是正确的。

One of those SSH add-ons is a tool set called pssh - which stands for Parallel SSH. That's what we're going to be learning about in this article - which is excerpted from my new Pluralsight course, Linux System Optimization.

这些SSH附加组件之一是一个名为pssh的工具集-代表并行SSH。 这就是我们将在本文中学习的内容-摘录自我的新Pluralsight课程Linux System Optimization 。

For now, though, I'm going to tell you a bit about the lab I'm using so that you can more easily reproduce it and follow along at home. I've got three Ubuntu LXD containers running. The base for all of our operations will be the one with an IP address of 10.0.3.140, while the two host nodes we'll be remotely provisioning will use 10.0.3.93 and 10.0.3.43.

不过,现在,我将向您介绍我正在使用的实验室,以便您可以更轻松地复制它并在家中继续学习。 我有三个正在运行的Ubuntu LXD容器 。 我们所有操作的基础都是IP地址为10.0.3.140的操作,而我们将要进行远程配置的两个主机节点将使用10.0.3.93和10.0.3.43。

Everything we'll do assumes that we've got passwordless SSH access from my base container to each of the two nodes. If you're not sure how to do that, you can view the SSH module of my Protocol Deep Dive: SSH and Telnet course on Pluralsight. If you're in a hurry, this Red Hat tutorial will get you to the same place.

我们将做的所有事情都假设我们已经从我的基本容器到两个节点的每一个都进行了无密码的SSH访问。 如果不确定如何执行此操作,可以在Pluralsight上查看“ 协议深度学习:SSH和Telnet”课程的SSH模块。 如果您很着急, 此Red Hat教程将使您到达同一个地方。

Installing pssh on Ubuntu is simple and quick: sudo apt install pssh. It doesn't get any harder on CentOS.

在Ubuntu上安装pssh非常简单快捷: sudo apt install pssh 。 在CentOS上,它一点也不难。

I created a simple host inventory file called sshhosts.txt that contains nothing more than the IP addresses of my two nodes:

我创建了一个简单的主机清单文件,名为sshhosts.txt,其中仅包含我两个节点的IP地址:

$ less sshhosts.txt10.0.3.9310.0.3.43

Now I'm going to run the pssh parallel-ssh command to execute a single command on my hosts.

现在,我将运行pssh parallel-ssh命令以在主机上执行单个命令。

$ parallel-ssh -i -h sshhosts.txt df -ht ext4

-i tells the program to run as interactive - otherwise we wouldn't be shown any command output. -h points to the hosts file that I called sshhosts.txt. And the command itself will be the old Unix utility df. That'll return a list of drives attached to the system along with their mount points and usage information. The -h here will display disk space in human readable units and the t will restrict access to only drives formatted as ext4.

-i告诉程序以交互方式运行-否则我们将不会看到任何命令输出。 -h指向我称为sshhosts.txt的主机文件。 该命令本身将是旧的Unix实用程序df。 这将返回连接到系统的驱动器列表以及它们的安装点和使用信息。 这里的-h将以人类可读的单位显示磁盘空间,而t将限制对格式为ext4的驱动器的访问。

Why do I care about that ext4 business? Because Ubuntu uses the snap package manager and each snap creates its own virtual device. So what? Well, I don't want to have to comb through a dozen or so virtual devices reporting 0 free space just to get to the real drives reporting actual usage.

为什么我要关心ext4业务? 因为Ubuntu使用快照程序包管理器,并且每个快照都创建了自己的虚拟设备。 所以呢? 好吧,我不想遍历十几个报告0个可用空间的虚拟设备,而只是为了获得报告实际使用情况的真实驱动器。

$ parallel-ssh -i -h sshhosts.txt df -ht ext4[1] 22:02:00 [SUCCESS] 10.0.3.43Filesystem Size Used Avail Use% Mounted on/dev/sda2 457G 131G 304G 30% /[2] 22:02:00 [SUCCESS] 10.0.3.93Filesystem Size Used Avail Use% Mounted on/dev/sda2 457G 131G 304G 30% /

And there you go! Full disk space information about both of my nodes. I'm sure you noticed that the information is identical. That's because these are both containers running on my workstation, so as far as they know, they both have full access to my own drive.

然后你去了! 有关两个节点的完整磁盘空间信息。 我确定您注意到这些信息是相同的。 这是因为这两个都是在我的工作站上运行的容器,据他们所知,它们都可以完全访问我自己的驱动器。

For my next trick, I'll collect the /etc/group files from each of my nodes. This is the kind of operation that could be useful to quickly monitor the security status of your nodes. You could add a script that parses the incoming data and alerts you if there are any anomalies.

对于下一个技巧,我将从每个节点中收集/ etc / group文件。 这种操作对于快速监视节点的安全状态很有用。 您可以添加一个脚本,该脚本分析传入的数据并在出现任何异常时提醒您。

Before I begin, I'll create a directory locally called host-files. Then I'll use the parallel-slurp command - whose name wonderfully describes its function. Again, -h points to the hosts file. The -L sets the host-files directory as the target location for writing the data we're going to generate, /etc/group is the remote file we want to slurp up, and group is the name we'd like to assign the data locally.

在开始之前,我将在本地创建一个目录,称为主机文件。 然后,我将使用parallel-slurp命令-其名称很好地描述了其功能。 同样,-h指向主机文件。 -L将host-files目录设置为写入将要生成的数据的目标位置, /etc/group是我们要吸收的远程文件,而group是我们想要分配的名称。本地数据。

mkdir host-filesparallel-slurp -h sshhosts.txt -L host-files/ /etc/group group

When it's done, your host-files directory will contain sub-directories named after the IP address of each of your nodes. As you can see, there's a file called "group" that contains the /etc/group data from each node.

完成后,您的host-files目录将包含以每个节点的IP地址命名的子目录。 如您所见,有一个名为“ group”的文件,其中包含每个节点的/ etc / group数据。

$ tree host-files/host-files/├── 10.0.3.43│   └── group└── 10.0.3.93 └── group

Does pssh come with any other treats? Yup. And running apropos gives you the whole list.

pssh是否附带其他任何功能? 对。 运行apropos会给您整个列表。

$ apropos parallelparallel-nuke (1) - parallel process kill programparallel-rsync (1) - parallel process kill programparallel-scp (1) - parallel process kill programparallel-slurp (1) - parallel process kill programparallel-ssh (1) - parallel ssh program

This article is based on content in my Pluralsight course, "Linux System Optimization." There's much more administration goodness in the form of books, courses, and articles available at bootstrap-it.com.

本文基于我的Pluralsight课程“ Linux System Optimization”中的内容。 bootstrap-it.com上提供了书籍,课程和文章形式的管理优势。

翻译自: https://www.freecodecamp.org/news/running-commands-linux-hosts-using-pssh/

linux pssh

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。