Saltstack 简明教程
SaltStack - Salt Package Manager
Salt 配方使用包管理器打包并分发到 Salt 主控。这个概念受到 RPM 、 Yum 和 Pacman 的影响。配方使用 Salt 状态、支柱、文件模板和其他文件,然后将其打包到一个文件中。
Salt formulas are packaged and distributed to Salt masters using the package manager. This concept was influenced from RPM, Yum and Pacman packaging systems. Salt state, pillar, file templates and other files are used by the formula and then packaged into a single file.
在创建配方包后,将其复制到存储库系统以使其可供 Salt 主控使用。在转到包管理器之前,让我们先了解如何使用 Salt 基本命令安装“nginx”包。
After a formula package is created, it is copied to the Repository System to make it to use for Salt masters. Before moving to the package manager, let us have a look at how to install an “nginx” package using the Salt basic command.
以下语法用于安装“nginx”包。
The following syntax is used to install a “nginx” package.
root@saltmaster:/home/vagrant# salt '*' pkg.install nginx
这里, pkg.install nginx 命令用于安装一个包。在执行后,您将看到以下响应。
Here, the pkg.install nginx command is used to install a package. After execution, you will see the following response.
它将生成以下 output −
It will produce the following output −
minion2:
----------
httpd:
----------
new:
1
old:
httpd-cgi:
----------
new:
1
old:
libxslt1.1:
----------
new:
1.1.28-2build1
old:
nginx:
----------
new:
1.4.6-1ubuntu3.7
old:
nginx-common:
----------
new:
1.4.6-1ubuntu3.7
old:
nginx-core:
----------
new:
1.4.6-1ubuntu3.7
old:
minion1:
----------
httpd:
----------
new:
1
old:
httpd-cgi:
----------
new:
1
old:
libxslt1.1:
----------
new:
1.1.28-2build1
old:
nginx:
----------
new:
1.4.6-1ubuntu3.7
old:
nginx-common:
----------
new:
1.4.6-1ubuntu3.7
old:
nginx-core:
----------
new:
1.4.6-1ubuntu3.7
old:
现在,您已经安装了一个包。要启动该包的服务,请使用下面给出的命令。
Now, you have installed a package. To start the services for that package, use the command given below.
root@saltmaster:/home/vagrant# salt '*' service.start nginx
运行此命令后,结果如下所示的代码块所示。
After running this command, the result looks as shown in the code block below.
minion1:
True
minion2:
True
因此,我们使用基本命令安装并启动了“nginx”包的服务。现在让我们讨论如何在 Salt 包管理器中构建和安装包。
Therefore, we have installed and started the services for the “nginx” package using the basic command. Let us now discuss how to build and install packages in the Salt package manager.
Building Packages
可以在你可以安装 Salt 的任何系统上构建包。有三种类型的包,如下所示。
Packages can be built on any system where you can install Salt. There are three type of packages and they are follows.
-
Formula
-
Reactor
-
Conf
现在让我们了解如何使用 Fomula 文件构建包。
Let us now understand how to build packages using the Fomula File.
Formula File
默认情况下,包中的大多数文件都位于 – /srv/spm/salt/ 目录中,但支柱文件可以放置在 – /srv/spm/pillar/ 目录中。配方文件描述了这个包。
Most files from the package are located at the – /srv/spm/salt/ directory by default, but the pillar file can be placed in the – /srv/spm/pillar/ directory. The Formula file describes the package.
Example
name: apache
os: RedHat
os_family: RedHat
version: 201607
release: 2
summary: Formula for installing Apache
description: Formula for installing Apache
在此,
Here,
-
Name − The name of the package. Here, the package name is apache.
-
os − It is used to know which operating systems can support this package.
-
os_family − It is used to know which operating system families can support this package.
-
Version − The version of the package. It is specified in an YYYYMM format.
-
Release − This field refers primarily to a release of a version.
-
Summary − Short lines description of the package.
-
Description − A more detailed description of the package.
REACTOR
反应器文件驻留在 /srv/spm/reactor/ 目录中。
The reactor files resides in the /srv/spm/reactor/ directory.
CONF
此类包中的文件是 Salt 的配置文件,这些文件通常存在于 /etc/salt/ 目录中。其他应用程序的配置文件可以使用 Salt 状态处理,并且应该使用 Salt 状态处理(使用公式类型的包)。
The files in this type of a package are configuration files for Salt, which normally live in the /etc/salt/ directory. Configuration files for packages other than Salt can and should be handled with a Salt State (using a formula type of package).
让我们继续执行以下步骤来构建一个软件包。
Let us continue with the following steps to build a package.
-
Create a FORMULA file and place it in the root of the package folder.
-
Assemble the formula files in a folder on the build system.
-
Run spm build. The package is built and placed in the /srv/spm_build folder. The following command is used to build a package.
spm build /path/to/salt-packages-source/formula
-
Now, copy the .spm file to a folder on the repository system.
-
You can share the srv/spm_build folder on the network, or copy the files to your FTP or the Webserver.
-
Generate repo metadata using the following command.
spm create_repo /srv/spm_build
Installing Packages
本部分解释了如何安装 Salt 软件包管理器软件包。
This section explains about installing Salt package manager packages.
Configure Remote Repositories
要配置远程存储库,Salt Master 需要通过配置过程来了解存储库所在位置。
To configure remote repositories, the Salt Master needs to know where the repository is through a configuration process.
文件位于 /etc/salt/spm.repos.d/spm.repo 目录中。
Files are in the /etc/salt/spm.repos.d/spm.repo directory.
Example
file_repository:
url: https://spm.example.com/
此处,该文件包含存储库的名称和指向存储库的链接。您还可以使用 http、https、ftp 或文件路径。要使用文件路径,您可以使用以下 URL 访问它: [role="bare"] [role="bare"]file:///srv/spm_build 。
Here, the file contains the name of the repository and the link to the repository. You can also use http, https, ftp, or the file path. To use file path, you can access it using the URL: [role="bare"]file:///srv/spm_build.
Update Metadata
在 Salt master 上配置存储库后,使用以下命令下载存储库元数据。
After the repository is configured on the Salt master, repository metadata is downloaded using the command below.
spm update_repo
Update File Roots
SPM 软件包位于 srv/spm/salt 目录中。将以下路径添加到 Salt master 上的文件根目录中,
The SPM packages are located in the srv/spm/salt directory. Add the following path to the file roots on the Salt master,
file_roots:
base:
1. /srv/salt
2. /srv/spm/salt
现在,重新启动 salt master。
Now, restart the salt master.