1-1 SaltStack课程大纲

1-2 SaltStack快速入门-远程执行

salt的运行方式
- Local
- Master/Minion
- Salt SSH
saltstack三大功能
远程执行
配置管理
云管理
安装epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
在管理端安装:
[root@saltstack-node1 ~]# yum install salt-master salt-minion -y
[root@saltstack-node1 ~]# /etc/init.d/salt-master start
Starting salt-master daemon: [ OK ]
[root@saltstack-node1 ~]# chkconfig salt-master on
[root@saltstack-node1 ~]# chkconfig salt-minion on
~]# cd /etc/salt/
salt]# ll
total 64
-rw-r----- 1 root root 29543 Mar 23 2016 master
-rw-r----- 1 root root 26365 Mar 23 2016 minion
drwxr-xr-x 3 root root 4096 Sep 10 05:47 pki 启动创建的,认证后存放密钥的目录
[root@saltstack-node1 ~]# vim /etc/salt/minion
master: 192.168.52.21
[root@saltstack-node1 ~]# /etc/init.d/salt-minion start
在客户端安装:
[root@saltstack-node2 ~]# yum install salt-minion -y
[root@saltstack-node2 ~]# chkconfig salt-minion on
~]# cd /etc/salt/
[root@saltstack-node2 salt]# ll
total 28
-rw-r----- 1 root root 26365 Mar 23 2016 minion
salt]# vim minion
master: 192.168.56.21
salt]# /etc/init.d/salt-minion start
进行认证:
[root@saltstack-node1 salt]# salt-key
Accepted Keys:
Denied Keys:
Unaccepted Keys:
saltstack-node2.example.com
Rejected Keys:
[root@saltstack-node1 salt]# salt-key -a saltstack-node2.example.com
The following keys are going to be accepted:
Unaccepted Keys:
saltstack-node2.example.com
Proceed? [n/Y] y
Key for minion saltstack-node2.example.com accepted.
[root@saltstack-node1 ~]# salt-key
Accepted Keys:
saltstack-node2.example.com
Denied Keys:
Unaccepted Keys:
Rejected Keys:
[root@saltstack-node1 salt]# salt-key -A
The following keys are going to be accepted:
Unaccepted Keys:
saltstack-node1.example.com
Proceed? [n/Y] y
Key for minion saltstack-node1.example.com accepted.
[root@saltstack-node1 ~]# salt-key
Accepted Keys:
saltstack-node1.example.com
saltstack-node2.example.com
Denied Keys:
Unaccepted Keys:
Rejected Keys:
Salt的远程执行
语法:salt 目标 模块.方法
- 目标(Targeting)
- 模块(Module)
- 返回(Returnners)
[root@saltstack-node1 ~]# salt "*" test.ping
saltstack-node2.example.com:
True
saltstack-node1.example.com:
True
[root@saltstack-node1 ~]# salt '*' cmd.run 'df -h'
saltstack-node2.example.com:
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 19G 855M 18G 5% /
tmpfs 491M 12K 491M 1% /dev/shm
/dev/sda1 240M 27M 201M 12% /boot
saltstack-node1.example.com:
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 19G 856M 18G 5% /
tmpfs 491M 16K 491M 1% /dev/shm
/dev/sda1 240M 27M 201M 12% /boot
[root@saltstack-node1 ~]# salt 'saltstack-node1.example.com' cmd.run 'uptime'
saltstack-node1.example.com:
06:22:52 up 49 min, 1 user, load average: 0.00, 0.04, 0.05
1-3 SaltStack快速入门-配置管理
[root@saltstack-node1 ~]# vim /etc/salt/master
file_roots:
base:
- /srv/salt
[root@saltstack-node1 ~]# /etc/init.d/salt-master restart
~]# mkdir -p /srv/salt
~]# cd /srv/salt/
配置一个入口top.sls文件:
[root@saltstack-node1 salt]# vim top.sls
base: 在base目录下
'*': 对所有机器
- apache 执行apache模块
编写apache模块:
[root@saltstack-node1 salt]# vim apache.sls
apache-service:
pkg.installed:
- names:
- httpd
- httpd-devel
service.running:
- name: httpd
- enable: True
[root@saltstack-node1 salt]# salt '*' state.highstate