saltstack进阶

1. masterless

1.1 应用场景

  • master 与 minion 网络不通或通信有延迟,即网络不稳定
  • 想在 minion 端直接执行状态

传统的 SaltStack 是需要通过 master 来执行状态控制 minion 从而实现状态的管理,但是当网络不稳定的时候,当想在minion本地执行状态的时候,当在只有一台主机的时候,想执行状态该怎么办呢?这就需要用到 masterless 了。

有了masterless,即使你只有一台主机,也能玩saltstack,而不需要你有N台主机架构。

1.2 masterless配置

1.2.1 修改配置文件minion

  • 注释master行
  • 取消注释file_client并设其值为local
  • 设置file_roots
  • 设置pillar_roots
[root@node2 ~]# vim /etc/salt/minion

# resolved, then the minion will fail to start.
# master: salt      //注释此行

file_client: local  //取消此行注释并将值设为local

file_roots:         //设置file_roots的路径和环境,可有多套环境
  base:
    - /srv/salt/

1.2.2 关闭salt-minion服务

使用 masterless 模式时是不需要启动任何服务的,包括salt-master和salt-minion。

[root@node2 ~]# systemctl stop salt-minion
[root@node2 ~]# systemctl disable salt-minion
Removed symlink /etc/systemd/system/multi-user.target.wants/salt-minion.service.
[root@node2 ~]# systemctl status salt-minion
● salt-minion.service - The Salt Minion
   Loaded: loaded (/usr/lib/systemd/system/salt-minion.service>
   Active: inactive (dead)
     Docs: man:salt-minion(1)
           file:///usr/share/doc/salt/html/contents.html
           https://docs.saltproject.io/en/latest/contents.html

11月 02 15:09:47 node2 salt-minion[443952]: To repair this iss>
11月 02 15:09:47 node2 salt-minion[443952]: Or restart the Sal>
11月 02 15:10:06 node2 systemd[1]: salt-minion.service: Main p>
11月 02 15:10:06 node2 systemd[1]: salt-minion.service: Failed>
11月 02 15:13:24 node2 systemd[1]: Starting The Salt Minion...
11月 02 15:13:24 node2 systemd[1]: Started The Salt Minion.
11月 29 22:35:49 node2 systemd[1]: Stopping The Salt Minion...
11月 29 22:35:49 node2 salt-minion[451713]: [WARNING ] Minion >
11月 29 22:35:50 node2 salt-minion[451713]: The Salt Minion is>
11月 29 22:35:50 node2 systemd[1]: Stopped The Salt Minion.

1.2.3 salt-call

masterless模式执行模块或状态时需要使用salt-call命令,而不再是salt或者salt-ssh。需要注意的是要使用salt-call的--local选项。

[root@node2 ~]# salt-call --local cmd.run 'df -h'
local:
    Filesystem             Size  Used Avail Use% Mounted o
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值