/etc/salt/master配置文件说明1
2
3
4
5
6
7
8
9
10
11
12
13
14
| CentOS-6.8
405 # Example:
406 # file_roots:
407 # base: ##基础环境 #base 默认存在.不能修改(修改配置文件,必须重启!)
408 # -/srv/salt/ ##此目录需要创建(根路径)
409 # dev: ##开发环境
410 # -/srv/salt/dev/services
411 # - /srv/salt/dev/states
412 # prod: ##生产环境
413 # -/srv/salt/prod/services
414 # -/srv/salt/prod/states
CentOS-7
应该是453-465
|
mini配置文件说明1
2
3
4
5
6
| [iyunv@backup ~]# egrep -v "^#|^$"/etc/salt/minion
master:172.16.1.61 ==》注意后面的空格(下同)
id:backup
注释:
vim /etc/salt/minion
master: m01
|
#16行 master: 领主机的IP或主机名 :后面必须要有1个空格 如果填写主机名需要内网要有dns解析 id: nfs01 #101行id: 下属名称,可以不配置,默认使用主机名称,会在/etc/salt/生成一个minion_id的文件,查看此文件显示本机主机名 #如果需要修改主机名,此文件必须删掉。因为salt会在读取文件时首先读取此文件minion_id 主机名不能使用下划线
1、远程执行1
2
3
| [iyunv@m01 ~]# salt 'web01' test.ping #salt '*'test.ping
web01:
True
|
#salt 命令
# * 为目标
#test 是一个模块命令(方法)
#ping是test的一个参数 测试所有主机是否存活 --master与minion之前的通信 与ping ip不一样。ping 为icmp
1.1、运行shell命令cmd.run不可执行交互式的命令,如vim,ssh
1
2
3
4
5
6
7
8
9
10
11
| [iyunv@m01 ~]# salt '*' cmd.run 'df -h'
web02:
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 19G 1.6G 17G 9% /
tmpfs 491M 12K 491M 1% /dev/shm
/dev/sda1 190M 33M 147M 19% /boot
web01:
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 19G 1.5G 7G 9% /
tmpfs 491M 12K 491M 1% /dev/shm
/dev/sda1 190M 33M 147M 19% /boot
|
1.2、使用salt复制文件1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| ## salt-cp '主机' 源文件目的地
管理机(m01):
[iyunv@m01 ~]# mkdir -p /server/scripts
[iyunv@m01 ~]# cd /server/scripts/
[iyunv@m01 scripts]# echo"test">test.txt
[iyunv@m01 scripts]# salt-cp '*' /server/scripts/test.txt /server/
{'web01': {'/server/test.txt': True},
'web02':{'/server/test.txt': True},}
被管理机(web01):
[iyunv@web01 ~]# tree /server/
/server/
├── scripts
└── test.txt
1 directory, 1 file
[iyunv@web01 ~]#
[iyunv@m01 scripts]# touch 888.txt
[iyunv@m01 scripts]# salt-cp 'web01' 888.txt/server/
{'web01': {'/server/888.txt': True}}
[iyunv@m01 scripts]#
查证
[iyunv@web01 ~]# ls /server/
666.txt 888.txt scripts test.txt
[iyunv@web01 ~]#
|
|