1
2
3
4
5
|
# salt-key –L #查看所有minion-key
# salt-key –a <keys-name> #接受某个minion-key
# salt-key –d <keys-name> #删除某个minion-key
# salt-key –A #接受所有的minion-key
# salt-key –D #删除所有的minion-key
|
1
2
3
4
|
# salt-run manage.up #显示当前活着的minion
# salt-run manage.down #显示未存活的minion
# salt-run manage.status #显示当前up和down 的minion
# salt-run manage.downremovekeys-True #显示未存活的minion,并将其移除
|
1
2
3
4
5
6
7
|
# vi /etc/salt/roster
db:
host: 192.168.18.212
user: root
passwd
: 123456
port: 22
timeout: 10
|
1
2
3
|
# salt-ssh 'db' test.ping
db:
True
|
1
2
3
|
# salt-ssh 'db' -r 'uptime'
# salt-ssh 'db' disk.usage #调用salt本身的模块
# salt-ssh 'db' grains.itemcpu_model #获取grains信息
|
1
2
3
4
5
|
# mkdir /srv/pillar
# vi /srv/pillar/top.sls
base:
'*'
:
- ip
|
1
2
|
# vi /srv/pillar/ip.sls
ip: {{ grains[
'ipv4'
][1] }}
|
1
2
3
4
5
6
7
8
9
|
# salt '*' pillar.item ip
host2:
----------
ip:
192.168.18.213
host1:
----------
ip:
192.168.18.212
|
1
2
3
4
5
6
7
8
9
|
# mkdir /srv/salt/zabbix
# vi /srv/salt/zabbix/agentd_conf.sls
zabbix:
file
.managed:
-
source
: salt:
//zabbix/zabbix_agentd
.conf
- name:
/usr/local/zabbix/conf/zabbix_agentd
.conf
- template: jinja
- defaults:
ip: {{ pillar[
'ip'
] }}
|
1
2
3
4
5
|
# vi /srv/salt/zabbix/zabbix_agentd.conf
LogFile=
/tmp/zabbix_agentd
.log
Server=192.168.18.214
ServerActive=127.0.0.1
Hostname={{ ip }}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# salt '*' state.sls zabbix.agentd_conf
host1:
----------
ID: zabbix
Function:
file
.managed
Name:
/usr/local/zabbix/conf/zabbix_agentd
.conf
Result: True
Comment: File
/usr/local/zabbix/conf/zabbix_agentd
.conf is
in
the correct state
Started: 11:48:35.261683
Duration: 139.733 ms
Changes:
Summary
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
host2:
----------
ID: zabbix
Function:
file
.managed
Name:
/usr/local/zabbix/conf/zabbix_agentd
.conf
Result: True
Comment: File
/usr/local/zabbix/conf/zabbix_agentd
.conf is
in
the correct state
Started: 11:31:41.906766
Duration: 141.928 ms
Changes:
Summary
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
|
1
2
3
4
5
6
7
8
9
10
11
|
# salt '*' cmd.run 'cat/usr/local/zabbix/conf/zabbix_agentd.conf'
host1:
LogFile=
/tmp/zabbix_agentd
.log
Server=192.168.18.214
ServerActive=127.0.0.1
Hostname=192.168.18.212
host2:
LogFile=
/tmp/zabbix_agentd
.log
Server=192.168.18.214
ServerActive=127.0.0.1
Hostname=192.168.18.213
|