saltstack的部署安装[二]
环境
[root@linux-node1 ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core)
编写YAML。下面这个脚本是lamp完成后的样子。
[root@linux-node1 ~]# vim /srv/salt/base/web/lamp.sls
lamp-install: id不能重复
pkg.installed: 方法
- pkgs: 模块。pkg指定需要安装的包
- httpd
- php
- php-pdo
- php-mysql
apache-config:
file.managed: 文件模块
- name: /etc/httpd/conf/httpd.conf 目的路径
- source: salt://web/files/httpd.conf 源路径,用salt指定配置文件存放的路径
- user: root
- group: root
- mode: 644
- watch_in: 被监控
- service: lamp-service
apache-conf:
file.recurse: 递归
- name: /etc/httpd/conf.d
- source: salt://web/files/apache-conf.d
- watch_in:
- service: lamp-service
apache-auth:
pkg.installed:
- name: httpd-tools
- require_in: require_in我被某个状态依赖。 require我依赖某个状态
- cmd: apache-auth
cmd.run:
- name: htpasswd -bc /etc/httpd/conf/htpasswd_file admin admin
- unless: test -f /etc/httpd/conf/htpasswd_file unless 如果条件为真,就是0 那么cmd.run不执行
- watch_in:
- service: lamp-service
/etc/php.ini: id的另一种写法,不用name
file.managed:
- source: salt://web/files/php.ini
- user: root
- group: root
- mode: 644
- watch_in:
- service: lamp-service
lamp-service:
service.running: service.dead关闭服务
- name: httpd
- enable: True 开机自启动,disable
- reload: True 监控变化,如果文件发生变化就重启
- watch: watch我关注某个状态,watch_in我被某个状态关注
- pkg: lamp-install
- pkg: apache-auth
- file: apache-config
- file: apache-conf
对应的目录结构如下
[root@linux-node1 ~]# tree /srv/
/srv/
└── salt
├── base
│ └── web
│ ├── files
│ │ ├── apache-conf.d
│ │ │ ├── autoindex.conf
│ │ │ ├── php.conf
│ │ │ ├── README
│ │ │ ├── userdir.conf
│ │ │ └── welcome.conf
│ │ ├── httpd.conf
│ │ └── php.ini
│ └── lamp.sls
├── dev
├── prod
└── test
8 directories, 8 files
使用网页权限管理的配置
[root@linux-node1 ~]# vim /srv/salt/base/web/files/httpd.conf
<Directory "/var/www/html/admin">
AllowOverride All
<Directory "/var/www/html/admin">
AllowOverride All
Order allow,deny
Allow from All
AuthUserFile /etc/httpd/conf/htpasswd_file
AuthName "hehe"
AuthType Basic
Require user admin
</Directory>

浙公网安备 33010602011771号