Saltstack 简明教程
SaltStack - Git as a File Server
Git 是一个开源分布式版本控制系统。它可用于跟踪任何文件中的更改。Salt 使用 Git 文件服务器从 Git 存储库发送文件。你可以将 Git 配置到 fileserver_backend 列出选项,如果你需要配置一个或多个存储库,则可以使用 gitfs_remotes 选项进行配置。
Git is an open-source distributed version control system. It can be used to keep a track of changes in any files. Salt sends files from Git repositories using the Git file server. You can configure Git to the fileserver_backend list option and if you need to configure one or more repositories, you can do so by using the gitfs_remotes option.
本章介绍如何安装和配置 Git 文件服务器。在进行安装之前,你必须具备以下先决条件:
This chapter explains about how to install and configure the Git file server. Before moving towards the installation, you must have the following prerequisites.
Salt Server Prerequisites for Using Git
最低要求的盐服务器使用 Git 作为文件服务器如下 −
The minimal requirement for the salt server to use Git as the file server is as follows −
-
pygit2
-
Dulwich
使用主配置文件中的 gitfs_provider 参数配置 Pygit2 和 Dulwich。如果在主文件中未配置 gitfs_provider ,则 Salt 将优先选择 pygit2(如果可用合适的版本),其次是 GitPython 和 Dulwich 。
Pygit2 and Dulwich are configured using the gitfs_provider parameter in the master config file. If gitfs_provider is not configured in the master file then Salt will prefer pygit2, if the suitable version is available, followed by GitPython and Dulwich.
Install pygit2
以下命令用于在 Fedora 和 Ubuntu 系统中安装 pygit2 −
The following commands are used to install pygit2 in the Fedora and Ubuntu based systems −
-
Fedora-based system
yum install python-pygit2
-
Ubuntu-based system
apt-get install python-pygit2
此处,pygit2 的最低受支持版本为 0.20.3。
Here, the minimum supported version of pygit2 is 0.20.3.
Install GitPYTHON
可以使用 yum / apt command 轻松在主设备上安装 GitPython,如下所示。
GitPython can be easily installed on the master using the yum / apt command as shown below.
-
Fedora-based system
yum install GitPython
-
Ubuntu-based system
apt-get install python-git
Install DULWICH
使用 yum 命令,可以将 Dulwich 轻松安装到主服务器。
Dulwich can be easily installed on the master using the yum command.
-
Fedora-based system
yum install python-dulwich
-
Ubuntu-based system
apt-get install python-dulwich
现在,我们已经安装 Git 文件服务器的所有依赖项。现在让我们使用 fileserver_backend 文件中的 master config 部分配置该 Git 文件服务器。
Now, we have installed all the dependencies for the Git file server. Let us now configure this Git file server using the fileserver_backend section in the master config file.
Backend Configuration
为了使用 Git 文件服务器,你需在主配置文件中的 fileserver_backend 列表中添加 Git。详述如下−
In order to use the Git file server, you need to add Git in the fileserver_backend list in the master config file. It is described as follows −
fileserver_backend:
- git
让我们进一步了解如何在远程配置中配置 Git 文件服务器。
Let us further understand how to configure the Git file server in a remote configuration.
gitfs_remotes Configuration
你可以为 master 文件中的 gitfs_remotes 配置指定任何一个或全部 URL,如 git://、https://、file:// 或 ssh://。这用于搜索请求的文件。
You can specify any one or all of the URLs such as git://, https://, file://, or ssh:// for the gitfs_remotes configuration in the master file. This is used to search for the requested files.
简单的 https URL 规范如下所示。
The simple https URL specification is defined below.
gitfs_remotes:
- https://github.com
可以在如下所示,完成 ssh 配置。
The ssh configuration can be done as shown below.
gitfs_remotes:
- git@github.com:user1/sample.git
- ssh://user@domain.tld/path/to/sample.git
现在,我们已经使用两个配置选项 fileserver_backend 和 gitfs_remotes 配置了 Git 文件服务器。
Now, we have configured the Git file server using the two options fileserver_backend and gitfs_remotes.
Multiple Remotes Configuration
以下命令用于主文件中的 gitfs_remotes 中的多次配置。
The following command is used for multiple configuration in gitfs_remotes in the master file.
gitfs_remotes:
- git://github.com/sample/sample1.git
- https://github.com/sample/sample2.git
- file:///root/user/sample
这里,版本库 sample1.git, sample2.git, 和 sample.doc 可能有以下文件。
Here, the repositories sample1.git, sample2.git, and sample.doc may have the following files.
sample1.git:
top.sls
sample2.git
edit/vimrc
sample.doc
edit/vimrc