Saltstack 简明教程
SaltStack - Using MinionFS as the File Server
MinionFS 是 Salt 为 Minion 提供的特殊文件服务器,用于在它们之间交换文件。MinionFS 提供的文件是 Minion 有意共享的文件。要共享文件,Minion 必须遵循以下步骤。
The MinionFS is a special file server provided by Salt for the minions to exchange the files between them. The files served by the MinionFS are the files intentionally shared by minions. To share the files, a Minion has to follow steps given below.
-
Source minion has to push the file to the salt master using the cp.push function.
-
Once the files are pushed by the source minion, the deployed files can be accessed by any other minion using the MinionFS file server.
Enable Pushing
默认情况下,禁用 Minion 将文件推送到主机。要接受来自 Minion 的文件,主机在配置文件中需要有 “file_recv” 选项,并且其值必须设置为 True 。默认情况下,“file_recv” 的值是 false 。
By default, pushing the files by minions to a master is disabled. To accept the files from minions, the master needs to have the “file_recv” option in the config file and its value must be set to True. By default, the value if “file_recv” is false.
file_recv: True
启用该选项后,重启主机服务。
Once the option is enabled, restart the master service.
Pushing Files
Minion 可以将文件推送到主机。它由 cp.push 函数执行。此 cp.push 函数提供了一个简单的机制,供 Minion 使用 Minion id 推送文件。
Minions can push the files to the master. It is performed by the cp.push function. This cp.push function provides an easy mechanism to push the files by minion using the minion id.
salt 'minion-id' cp.push /path/to/the/file
这里,Minion id 用于识别哪个 Minion 正在推送文件。此命令将把文件存储在 master’s cachedir 下的 minions 子目录中。 通常,路径为 – /var/cache/salt/master/minions。
Here, the minion-id is used to identify which minion is pushing the file. This command will store the file in a subdirectory named minions under the master’s cachedir. Usually, the path is – /var/cache/salt/master/minions.
对于 Minion, m1 和文件 – /var/log/mylog.txt,文件将存储在 – /var/cache/salt/master/minions/m1/var/log/mylog.txt 中。
For minion, m1 and the file – /var/log/mylog.txt, the file will be stored in the – /var/cache/salt/master/minions/m1/var/log/mylog.txt.
Enable MinionFS
要启用 MinionFS,只需在文件服务器后端设置中添加 minion ,如下面的代码块所示。
To enable the MinionFS, simply add minion in the fileserver backend setting as shown in the following code block.
fileserver_backend:
- roots
- minion
启用 MinionFS 后,Minion 推送的文件可用为 −
Once MinionFS is enabled, the minion pushed files are available as −
salt://<minion-id>/path/to/pushed/file
对于minion m1 和推送文件 – /var/log/mylog.txt, 将从 salt://m1/var/log/mylog.txt 提供推送文件。
For minion, m1 and the pushed file – /var/log/mylog.txt, the pushed file will be served from salt://m1/var/log/mylog.txt.
可使用以下配置在特殊目录中装载此 minionFS。它会将 minionFS 文件与其它文件分开,并帮助整理 minion 文件。
This minionFS can be mounted in a special directory using the following configuration. It will separate the minionFS files from other files and will help in organizing the minion files.
minionfs_mountpoint: salt://minionfs
对于以上配置,该文件将作为 minionfs 目录中的一项展示为 – salt://minionfs/m1/var/log/mylog.txt
For the above configuration, the file will available under the minionfs directory as – salt://minionfs/m1/var/log/mylog.txt
MinionFS Advanced Options
MinionFS 还提供选项,以启用/禁用特定 minion 中推送文件的可用性。这些选项是 minionfs_whitelist ,用于启用 minion; minionfs_blacklist ,用于禁用 minion。
The MinionFS also provides an option to enable / disable the availability of pushed files from a certain minion. The options are minionfs_whitelist, to enable minions and minionfs_blacklist, to disable the minions.
minionfs_whitelist:
- webserver
- develop*
- ‘mail\d+.mysite.com'
minionfs_blacklist:
- testing
在以上配置中,除了 testing 之外,所有 minion 都被允许使用 minionFS 共享文件。
In the above configuration, all minions except testing are allowed to share the file using minionFS.
-
Webserver1
-
Minions whose ids matches the regular expression develop *
-
Minions whose ids matches the regular expression mail\d+.mysite.com.
-
Testing
在下一章中,我们将学习如何使用 Salt 进行 Cron。
In the next chapter, we will learn how to use Cron with Salt.