自动化部署apache
1、修改master配置文件
[root@server1 salt]# cd /etc/salt/
[root@server1 salt]# vim master
674 file_roots:
675 base:
676 - /srv/salt
[root@server1 salt]# systemctl restart salt-master
2、创建sls
[root@server1 salt]# mkdir /srv/salt
[root@server1 salt]# cd /srv/salt
[root@server1 salt]# pwd
/srv/salt
[root@server1 salt]# mkdir apache
[root@server1 salt]# cd apache/
[root@server1 apache]# vim install.sls
apache-install:
pkg.installed:
- pkgs:
- httpd
- php
service.running:
- name: httpd
- enable: true
[root@server1 apache]# salt server2 state.sls apache.install ##推送安装

server2上查看http,是开机自启动的
[root@server2 salt]# systemctl is-enabled httpd
enabled
在server2上查看树状结构
[root@server2 salt]# cd /var/cache/salt/
[root@server2 salt]# yum install tree -y
[root@server2 salt]# tree

3、修改默认发布目录
1)写发布页面
[root@server1 apache]# mkdir files
[root@server1 apache]# cd files/
[root@server1 files]# pwd
/srv/salt/apache/files
[root@server1 files]# vim index.html
server2
2)修改sls文件
[root@server1 files]# cd ..
[root@server1 apache]# vim install.sls
apache-install:
pkg.installed:
- pkgs:
- httpd
- php
service.running:
- name: httpd
- enable: true
file.managed:
- source: salt://apache/files/index.html
- name: /var/www/html/index.html
3)推送
[root@server1 apache]# salt server2 state.sls apache.install
4)测试
[root@server1 apache]# curl server2
server2
