SaltStack 实践课程二 PHP+NGINX

Posted Alex0425

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SaltStack 实践课程二 PHP+NGINX相关的知识,希望对你有一定的参考价值。

1.查看file_roots

file_roots:
  base:
    - /srv/salt/
  dev:
    - /srv/salt/dev/
  prod:
    - /srv/salt/prod/

2.目录结构如下

[[email protected] prod]# pwd
/srv/salt/prod
[[email protected] prod]# tree 
.
|-- nginx
|   `-- files
|       `-- nginx-1.9.15.tar.gz
|-- pcre
|   |-- files
|   |   `-- pcre-8.38.tar.gz
|   `-- install.sls
`-- php
    `-- files
        `-- php-7.0.6.tar.gz

3.在/srv/salt/prod/pcre/目录下面新建文件install.sls

pcre-source-install:
  file.managed:
    - name: /usr/local/src/pcre-8.38.tar.gz
    - source: salt://pcre/files/pcre-8.38.tar.gz
    - user: root
    - group: root
    - mode: 755
  cmd.run:
    - name: cd /usr/local/src && tar zxf pcre-8.38.tar.gz && cd pcre-8.38 && ./configure --prefix=/usr/local/pcre && make && make install
    - unless: test -d /usr/local/pcre 
    - require:
      - file: pcre-source-install

4.执行安装命令

[[email protected] pcre]# salt ‘saltstack1‘ state.sls pcre.install env=prod
saltstack1:
----------
          ID: pcre-source-install
    Function: file.managed
        Name: /usr/local/src/pcre-8.38.tar.gz
      Result: True
     Comment: File /usr/local/src/pcre-8.38.tar.gz is in the correct state
     Started: 16:10:24.148959
    Duration: 41.8 ms
     Changes:   
----------
          ID: pcre-source-install
    Function: cmd.run
        Name: cd /usr/local/src && tar zxf pcre-8.38.tar.gz && cd pcre-8.38 && ./configure --prefix=/usr/local/pcre && make && make install
      Result: True
     Comment: unless execution succeeded
     Started: 16:10:24.192646
    Duration: 8.637 ms
     Changes:   

Summary for saltstack1
------------
Succeeded: 2
Failed:    0
------------
Total states run:     2

 5.安装nginx源码,在/srv/salt/prod/nginx/目录下新建install.sls文件

include:
- pcre.install
nginx-source-install:
file.managed:
- name: /usr/local/src/nginx-1.9.15.tar.gz
- source: salt://nginx/files/nginx-1.9.15.tar.gz
- user: root
- group: root
- mode: 755
cmd.run:
- name: cd /usr/local/src/ && tar zxf nginx-1.9.15.tar.gz && cd nginx-1.9.15 && ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-http_dav_module --with-pcre=/usr/local/src/pcre-8.38 && make && make install
- unless: test -d /usr/local/nginx
- require:
- file: nginx-source-install
- cmd: pcre-source-install

以上是关于SaltStack 实践课程二 PHP+NGINX的主要内容,如果未能解决你的问题,请参考以下文章

saltstack部署nginx+php

SaltStack学习系列之State安装Nginx+PHP环境

<Docker + Bamboo + Saltstack持续集最佳实践 > 本周三晚在线公开课

Saltstack自动部署Haproxy+keepalived+nginx+memcache+php(fastcgi)

SaltStack之项目实践

运维自动化Saltstack配置管理实践