演示如下:
-
vagrant@saltminion1:/tmp$ touch talen.txt
-
vagrant@saltminion1:/tmp$ echo This is a test . > talen.txt
-
vagrant@saltmaster:/var/cache/salt/master$ sudo salt '*' test.ping
-
minion2:
-
True
-
minion1:
-
True
-
vagrant@saltmaster:/var/cache/salt/master$ sudo salt '*' cp.push /tmp/talen.txt
-
minion2:
-
False
-
minion1:
-
True
-
vagrant@saltmaster:/var/cache/salt/master$ cd /var/cache/salt/master/minions/minion
-
minion1/ minion2/
-
vagrant@saltmaster:/var/cache/salt/master/minions$ tree
-
.
-
├── minion1
-
│ ├── files
-
│ │ └── tmp
-
│ │ └── talen.txt
-
│ └── mine.p
-
└── minion2
-
└── mine.p
-
-
4 directories, 3 files
有时,我们需要传送在minion上产生的文件.
salt已经有从minion上传送文件到master的特性.默认因为安全性问题,没有启用.
修改master启用这个特性.
file_recv: True
-
vagrant@saltmaster:~ $ vim /etc/salt/master
-
-
# Allow minions to push files to the master. This is disabled by default, for
-
# security purposes.
-
#file_recv: False
-
file_recv: True
salt-cp cp模块是minion端的,其它函数功能参考
# File Server Backend
#文件服务后端
#
# Salt supports a modular fileserver backend system, this system allows
# the salt master to link directly to third party systems to gather and
# manage the files available to minions. Multiple backends can be
# configured and will be searched for the requested file in the order in which
# they are defined here. The default setting only enables the standard backend
# "roots" which uses the "file_roots" option.
#salt支持一个模块化的文件服务后端系统,这个系统允许master直接链接到第三方平台系统收集和管理minions上的文件.请求文件将按定义的多个后端的顺序查询.默认使用file_roots选项只启用了最基本的roots.
#fileserver_backend:
# - roots
#
# To use multiple backends list them in the order they are searched:
#fileserver_backend:
# - git
# - roots
#按顺序列出要查询的后端列表.
#
#如果你想让file_server允许追踪软链接文件系统树,取消下面的注释.默认是开启的,当前默认只应用于默认的文件服务后端.
# Uncomment the line below if you do not want the file_server to follow
# symlinks when walking the filesystem tree. This is set to True
# by default. Currently this only applies to the default roots
# fileserver_backend.
#fileserver_followsymlinks: False
#
# Uncomment the line below if you do not want symlinks to be
# treated as the files they are pointing to. By default this is set to
# False. By uncommenting the line below, any detected symlink while listing
# files on the Master will not be returned to the Minion.
#fileserver_ignoresymlinks: True
#
# By default, the Salt fileserver recurses fully into all defined environments
# to attempt to find files. To limit this behavior so that the fileserver only
# traverses directories with SLS files and special Salt directories like _modules,
# enable the option below. This might be useful for installations where a file root
# has a very large number of files and performance is impacted. Default is False.
# fileserver_limit_traversal: False
#
# The fileserver can fire events off every time the fileserver is updated,
# these are disabled by default, but can be easily turned on by setting this
# flag to True
#fileserver_events: False
如果想使用minion上的文件系统,简单启用两个参数
fileserver_backend:
- roots
- minion
file_recv: True
从下面的执行可以看到,当我们从minion1服务器上传文件到master后,minion1的上传目录/tmp已经可以在其它minions上看到了.
其它minions可以从minion1上共享的目录下载文件.
-
vagrant@saltmaster:~$ sudo salt '*' cp.list_master_dirs
-
minion2:
-
- .
-
- common
-
- minion1/tmp
-
minion1:
-
- .
-
- common
-
- minion1/tmp
-
vagrant@saltmaster:~$ sudo salt 'minion2' cp.get_file salt://minion1/tmp/talen.txt /tmp/talen.2.txt
-
minion2:
-
/tmp/talen.2.txt
-
vagrant@saltminion2:~$ ll /tmp/talen.2.txt
-
-rw-r--r-- 1 root root 17 Apr 27 03:47 /tmp/talen.2.txt
阅读(4175) | 评论(0) | 转发(0) |