Saltstack 简明教程

SaltStack - Job Management

Salt 能够与大量的系统进行高速通信。此方法有助于 Salt 构筑一个功能强大的多任务处理系统。Salt 可以在多个系统上运行作业,因此 Salt 使用作业管理技术来管理所有系统上运行的每个作业。本章详细解释了作业管理。

Salt has the capability of high-speed communication with a large number of systems. This approach helps Salt to make a powerful multitasking system. Salt can run jobs on more than one systems, so Salt uses job management technique to manage each job running on all the systems. This chapter explains about job management in detail.

What is a Job ID?

Salt 具有缓存目录 ` cachedir `。在此内部,小 Minion 维护的目录称为 ` proc ` 目录。它位于以下目录 /var/cache/salt/proc 中。

Salt has cache directory, cachedir. Inside this, a directory that minions maintain is called as the proc directory. It is located in the following directory /var/cache/salt/proc.

proc 目录用于维护所有文件。当这些文件被执行时,它们会被分配一个唯一的作业 ID。此作业 ID 有助于识别小 Minion 上当前正在运行的作业,并允许查找作业。

The proc directory is used to maintain all the files. When these files are executed, they assign with a unique job ID. This job id helps to identify the current running jobs on the minion and allow the jobs to be looked up.

SALTUTIL Module

Salt 引入了一个称为 Saltutil 作业管理进程的新模块。该模块包含用于管理作业的不同函数。这些函数用于在 Minion 级别管理作业。对函数的简要描述如下所示:

Salt introduces a new module that is called as the Saltutil job management process. This module contains different functions to manage jobs. These functions are used to manage jobs at the minion level. The functions are described in brief as follows −

  1. running − Returns all the running jobs data that are found in the proc directory.

  2. find_job − Returns specific data about a certain job based on the job id.

  3. signal_job − Allows a given job id(jid) to be sent a signal.

  4. term_job − Sends a termination signal for the specified job.

  5. kill_job − Sends a kill signal for the specified job.

Jobs Runner

作业运行程序包含使查看数据更轻松、更简洁的函数。它有不同的函数。我们详细讨论其中每个函数。

The jobs runner contains functions to make viewing data easier and cleaner. It has different functions. Let us discuss each of these functions in detail.

ACTIVE Function

Active 函数用于识别哪些作业仍在运行,以及检查哪些系统已完成作业,以及哪些系统仍在等待。它使用以下命令执行:

The Active function is used to identify which jobs are still running and check what systems have completed a job and what systems are still being waited on. It is executed using the following command,

salt-run jobs.active

LOOKUP_JID Function

lookup_jid 运行会显示当前正在查找的工作数据。这些作业由主配置中的 keep_jobs 选项配置。它使用以下命令执行。

The lookup_jid runner will display the data for the current looking job. These jobs are configured via the keep_jobs option in the master configuration. It is executed using the following command.

salt-run jobs.lookup_jid <job id number>

LIST_JOBS Function

List_jobs 函数用于列出作业的作业数据。通过以下命令表示 −

The List_jobs function is used to list out the job data for jobs. It is expressed by the following command −

salt-run jobs.list_jobs

Job Scheduling

调度系统公开主上的任何运行函数或 Minion 上的任何运行程序的执行。

The schedule system exposes the execution of any execution function on minions or any runner on the master.

通过以下方法执行 −

It is performed by the following methods −

  1. Schedule − The schedule option in either the master or the minion config files.

  2. Minion pillar data − It refreshes the minion pillar data using the saltutil.refresh_pillar command.

  3. The schedule state or schedule module.

Salt 状态在 Minion 上执行。您可以传递位置参数,并在 config file 中提供 YAML dict 的命名参数,如下所示。

Salt states are executed on the minion. You can pass the positional arguments and provide a YAML dict of the named arguments in the config file as shown below.

schedule:
   job1:
      function: saltstate.sls
      seconds: 3600
      args:
         - httpd
      kwargs:
         test: True

在此, job1 将使用指定参数 httpd 每小时执行函数 saltstate.slstest: Truehttpd 命令的附加参数,该命令在 saltstate.sls 中定义。

Here, job1 will execute the function saltstate.sls with the specified arguments, httpd for every hour. The test: True is the additional argument for the httpd command that is defined in saltstate.sls.