centos7 saltstack快速安装+自定义模块实例

1. 安装源

# yum install http://mirrors.sohu.com/fedora-epel/7/x86_64/e/epel-release-7-8.noarch.rpm

      2. 安装saltstack

只需要一台安装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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值