salt 文件push使用方法


MINIONFS BACKEND WALKTHROUGH

启用文件传输,有时候我们需要将minion端生成的一些文件收集到master端

配置
master端的相关配置:
(1)配置接收minion端文件,基于安全原因默认是关闭的
    file_recv: True
(2)cachedir配置文件保存在master端的路径
    默认存放在/master/minions/minion-id/files路径下

指令:salt 'minion-id' cp.push /path/to/the/file



MINIONFS BACKEND

MINIONFS master端配置

fileserver_backend:
- roots
- minion

file_recv: True

fileserver_backend在文件服务器那一部分讲过,roots是设置本地的文件服务器的目录环境,
同样的fileserver_backend可以将从minion端拉取过来的文件通过文件服务器发布出去,pull
到其他minion上。

以下有两个常用的方法:
(1)查看master端有哪些可以推送的文件
    salt '*' cp.list_master_dirs
(2)将某一minion下的文件或目录pull到其他minion上
    salt 'minion2' cp.get_file salt://minion1/opt/1.txt /opt/1.txt



使用minionFS进行公钥分发实例:

被连接方:minion-destination,存放公钥,存放在/root/.ssh/authorized_keys
连接方:minion-source,存放私钥,存放在/root/.ssh/id_rsa
(1)在目标主机上创建密钥存放目录
    salt 'XX' file.mkdir dir_path=/root/.ssh user=root group=root mode=700
(2)在minion-source主机上生成密钥对
    salt 'minion-source' cmd.run 'ssh-keygen -N "" -f /root/.ssh/id_rsa'
(3)将minion-source上的公钥push到master端
    salt 'minion-source' cp.push /root/.ssh/id_rsa.pub
(4)分发minion-source主机上的公钥到minion-destination主机上的指定目录
    salt 'minion-destination' cp.get_file salt://minion-source/root/.ssh/id_rsa.pub /root/.ssh/authorized_keys



参考链接:
http://m.blog.chinaunix.net/uid-21142030-id-5710194.html
http://docs.saltstack.cn/topics/tutorials/minionfs.html

原文地址:https://www.cnblogs.com/solitarywares/p/7436902.html