Saltstack_使用指南14_无master

 

1. 主机规划

 

salt 版本

1 [root@salt100 ~]# salt --version
2 salt 2018.3.3 (Oxygen)
3 [root@salt100 ~]# salt-minion --version
4 salt-minion 2018.3.3 (Oxygen)

 

salt 无master文档

standalone_minion

https://docs.saltstack.com/en/latest/topics/tutorials/standalone_minion.html

 

salt-call

https://docs.saltstack.com/en/latest/ref/cli/salt-call.html    

 

注意★★★★★

salt处于无master【masterless】模式时,不要运行salt-minion守护进程。否则salt-minion将尝试去连接master并失败。salt-call命令独立存在,不需要salt-minion守护进程。

 

2. 无master操作步骤

备注:此次是在salt01上操作

 

1、关闭salt-minion、关闭开机自启动

1 systemctl stop salt-minion.service    
2 systemctl disable salt-minion.service    

 

2、minion端配置修改

1 [root@salt01 ~]# vim /etc/salt/minion 
2 ………………
3 # Set the file client. The client defaults to looking on the master server for
4 # files, but can be directed to look at the local file directory setting
5 # defined below by setting it to "local". Setting a local file_client runs the
6 # minion in masterless mode.
7 #file_client: remote
8 file_client: local  # 从默认的 remote改为local
9 ………………

备注:salt-call 会读取该配置文件,因此该配置文件必须改。

 

3、file_roots和pillar_roots设置

使用默认的即可,不需要设置

 

4、External pillars设置

无master模式支持External pillars

 

3. 无master模式测试

3.1. 常规信息

1 [root@salt01 ~]# salt-call  test.ping
2 local:
3     True
4 [root@salt01 ~]# salt-call grains.items  # 查看所有grains信息

 

3.2. grains设置

 1 [root@salt01 ~]# vim /etc/salt/minion 
 2 ………………
 3 # Custom static grains for this minion can be specified here and used in SLS
 4 # files just like all other grains. This example sets 4 custom grains, with
 5 # the 'roles' grain having two values that can be matched against.
 6 grains:
 7   roles:
 8     - webserver03
 9     - memcache03
10   os: redhat03
11   tree: tree001
12 ………………
13 [root@salt01 ~]# salt-call saltutil.sync_grains  # 刷新 grains【实际可以不进行此操作,因为是本地读取】
14 local:
15 ##### 查看grains结果
16 [root@salt01 ~]# salt-call grains.item tree
17 local:
18     ----------
19     tree:
20         tree001
21 [root@salt01 ~]# salt-call grains.item roles
22 local:
23     ----------
24     roles:
25         - webserver03
26         - memcache03
27 [root@salt01 ~]# salt-call grains.item roles:1  # 读取列表中的下标为1的数据
28 local:
29     ----------
30     roles:1:
31         memcache03

 

3.3. pillar设置

 1 [root@salt01 pillar]# pwd
 2 /srv/pillar
 3 [root@salt01 pillar]# cat top.sls 
 4 base:
 5   '*':
 6     - web_pillar.user
 7 [root@salt01 pillar]# cat web_pillar/user.sls 
 8 tree:
 9   tree01:
10     - name01: zhang01
11     - name02: zhang02
12   tree02:
13     - my_user1: salt0-01
14     - my_user2: salt0-02
15 [root@salt01 ~]# salt-call saltutil.sync_pillar  # 刷新【实际可以不进行此操作,因为是本地读取】
16 local:
17 ###### pillar数据查询
18 [root@salt01 ~]# salt-call pillar.items
19 local:
20     ----------
21     tree:
22         ----------
23         tree01:
24             |_
25               ----------
26               name01:
27                   zhang01
28             |_
29               ----------
30               name02:
31                   zhang02
32         tree02:
33             |_
34               ----------
35               my_user1:
36                   salt0-01
37             |_
38               ----------
39               my_user2:
40                   salt0-02
41 [root@salt01 ~]# salt-call pillar.item tree:tree01
42 local:
43     ----------
44     tree:tree01:
45         |_
46           ----------
47           name01:
48               zhang01
49         |_
50           ----------
51           name02:
52               zhang02
53 [root@salt01 ~]# salt-call pillar.item tree:tree01:name01
54 local:
55     ----------
56     tree:tree01:name01:
57         zhang01

 

注意这几个的区别【取列表信息】

 1 [root@salt01 pillar]# salt-call pillar.item tree:tree01
 2 local:
 3     ----------
 4     tree:tree01:
 5         |_
 6           ----------
 7           name01:
 8               zhang01
 9         |_
10           ----------
11           name02:
12               zhang02
13 [root@salt01 pillar]# salt-call pillar.item tree:tree01:0
14 local:
15     ----------
16     tree:tree01:0:
17         ----------
18         name01:
19             zhang01
20 [root@salt01 pillar]# salt-call pillar.item tree:tree01:name01
21 local:
22     ----------
23     tree:tree01:name01:
24         zhang01
25 [root@salt01 pillar]# salt-call pillar.item tree:tree01:0:name01
26 local:
27     ----------
28     tree:tree01:0:name01:
29         zhang01

 

———————————————END———————————————

 

posted on 2019-05-28 20:47  踏歌行666  阅读(353)  评论(0编辑  收藏  举报

导航