1. 安装源
# yum install http://mirrors.sohu.com/fedora-epel/7/x86_64/e/epel-release-7-8.noarch.rpm
只需要一台安装master即可,其他的全部安装minion.
2.1 安装salt-master
# yum install salt-master
2.2 安装salt-minion
# yum install salt-minion
3. 配置saltstack
3.1 minion配置
# cat /etc/salt/minion
master 172.11.0.2
看清楚了master前面有两个空格,这行代码表示我要连接的saltstack的master是172.11.0.2
3.2 master配置
# cat /etc/salt/master
interface 172.11.0.2
master监听172.11.0.2,老样子前面也是有两个空格,否则启动的时候会报错.
4. 启动saltstack
4.1 启动minion
#systemctl start salt-minion
4.1 启动master
#systemctl start salt-master
5. 测试saltstack
接下来的命令都在master上执行
5.1 查看minion列表
# salt-key -L
AcceptedKeys:
UnacceptedKeys:
minion1
RejectedKeys:
True
Salt编写自定模块:
官网文档:http://docs.saltstack.com/ref/modules/index.html#grains-data
Master上创建存放模块的目录:
mkdir -pv /srv/salt/_modules
cd /srv/salt/_modules
在_modules目录下新建python文件作为自定义模块hello_module.py
#encoding = utf8
def say_hello():
return 'hello salt'
保存文件,然后执行同步modules命令 salt ‘*’ saltutil.sync_modules
[root@host109 _modules]# salt '*' saltutil.sync_modules
minion1:
- modules.hello_module
这样modules就算建好了,可以通过 salt ‘*’ hello_module.say_hello
来执行此自定义module
[root@host109 _modules]# salt '*' hello_module.say_hello
minion1:
- hello salt