SaltStack學習系列之State安裝Nginx+PHP環境

來源:互聯網
上載者:User

標籤:min   blog   srv   evel   grains   cal   repo   ora   mini   

目錄結構

|-- pillar|   |-- nginx|   |   `-- nginx.sls   #nginx變數(key:value)|   `-- top.sls`-- salt|-- init    #初始化目錄    |   `-- repos.sls  #安裝yum源    |-- roles   #角色(nginx和php)    |   |-- nginx   #Nginx    |   |   |-- config.sls    #copy和利用pillar渲染設定檔    |   |   |-- files         #存放需要copy和渲染到用戶端的檔案    |   |   |   |-- fastcgi_params    |   |   |   |-- jim_fix_params    |   |   |   |-- nginx-1.8.1.tar.gz    |   |   |   |-- nginx.conf    |   |   |   |-- test.php    |   |   |   `-- vhosts.conf    |   |   |-- install.sls    #安裝Nginx    |   |   `-- service.sls    #啟動Nginx    |   |-- php      #PHP                           |   |   |-- config.sls     #COPY設定檔從master端到minion端    |   |   |-- files          #存放需要copy到用戶端的檔案    |   |   |   |-- php-fpm.conf    |   |   |   |-- php.ini    |   |   |   `-- timecash.conf    |   |   |-- install.sls     #安裝PHP    |   |   `-- service.sls     #啟動PHP    |   `-- user     #建立啟動php和nginx的使用者    |       `-- www.sls         #建立www使用者    `-- top.sls       #引用角色的

準備階段

指定master端pillar和salt檔案的目錄

vim /etc/salt/masterpillar_roots:  base:    - /srv/pillarfile_roots:  base:    - /srv/salt

pillar

/srv/salt/pillar/nginx/nginx.sls

vim  srv/pillar/nginx/nginx.slsvhost:    server_name: zhai.timecash.cn                       #渲染nginx的vhost的server_name    target: /alidata1/nginx/conf/vhosts/zhai.conf       #指定從master端把設定檔copy到minion叫的名字    web_dir: /alidata1/www/timecash22/zhai.timecash.cn  #指定web程式路徑

init

/srv/salt/init/repos.sls

vim /srv/salt/init/repos.slsyum_epel_repo_release:    pkg.installed:        - sources:            - epel-release:  https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm        - unless: rpm -qa|grep epel-release-7-10yum_webtatic_repo_release:    pkg.installed:        - sources:            - webtatic-replase: https://mirror.webtatic.com/yum/el7/webtatic-release.rpm        - unless: rpm -qa |grep webtatic-release-7-3.noarch

roles

nginx

/srv/salt/roles/nginx/install.sls

 vim /srv/salt/roles/nginx/install.slsnginx_source:  file.managed:    - name: /tmp/nginx-1.8.1.tar.gz    - unless: test -d /tmp/nginx-1.8.1.tar.gz    - user: root    - group: root    - makedirs: True    - source: salt://roles/nginx/files/nginx-1.8.1.tar.gznginx_extract:  cmd.run:    - cwd: /tmp    - names:      - tar -zxf nginx-1.8.1.tar.gz    - unless: test -d /tmp/nginx-1.8.1.tar.gz    - require:      - file: nginx_sourcenginx_pkg:  pkg.installed:    - pkgs:      - gcc      - gcc-c++      - openssl-devel      - pcre-devel      - zlib-develnginx_compile:  cmd.run:    - cwd: /tmp/nginx-1.8.1    - names:      - ./configure --user=www --prefix=/alidata1/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_realip_module      - make      - make install    - require:      - cmd: nginx_extract      - pkg: nginx_pkg    - unless: test -d /usr/local/nginx

/srv/salt/roles/nginx/config.sls

vim /srv/salt/roles/nginx/config.slsnginx-conf:  file.managed:    - name: /alidata1/nginx/conf/nginx.conf    - source: salt://roles/nginx/files/nginx.conf    - user: root    - group: root    - template: jinja    - defaults:      num_cpus: {{ grains[‘num_cpus‘] }}vhost-conf:  file.managed:    - name: {{ pillar[‘vhost‘][‘target‘]  }}    - source: salt://roles/nginx/files/vhosts.conf    - template: jinja    - defaults:      server_name: {{ pillar[‘vhost‘][‘server_name‘]  }}      num: {{ pillar[‘vhost‘][‘server_name‘]  }}fastcgi-params:  file.managed:    - name: /alidata1/nginx/conf/fastcgi_params    - source: salt://roles/nginx/files/fastcgi_params    - user: root    - group: rootjim-fix-params:  file.managed:    - name: /alidata1/nginx/conf/jim_fix_params    - source: salt://roles/nginx/files/jim_fix_params    - user: root    - group: rootcreate_dir:  cmd.run:    - names:      - mkdir -p /alidata1/nginx/conf/vhosts/      - mkdir -p {{ pillar[‘vhost‘][‘web_dir‘]  }}

php

/srv/salt/roles/php/install.sls

vim /srv/salt/roles/php/install.slsphp_pkg:  pkg.installed:    - pkgs:      - gcc      - gcc-c++      - autoconf      - automake      - zlib      - zlib-devel      - openssl      - openssl-devel      - pcre      - pcre-develphp_install:  pkg.installed:    - pkgs:      - php56w.x86_64      - php56w-bcmath.x86_64      - php56w-cli.x86_64      - php56w-common.x86_64      - php56w-devel.x86_64      - php56w-fpm.x86_64      - php56w-gd.x86_64      - php56w-mbstring.x86_64      - php56w-mcrypt.x86_64      - php56w-mysql.x86_64      - php56w-opcache.x86_64      - php56w-pdo.x86_64      - php56w-soap.x86_64      - php56w-xml.x86_64      - php56w-xmlrpc.x86_64

/srv/salt/roles/php/config.sls

vim /srv/salt/roles/php/config.slsphp_log_dir:  file.directory:    - name: /alidata1/php/logs/    - user: root    - group: root    - makedirs: Truerm_default_config:  cmd.run:    - name: rm -rf /etc/php-fpm.d/www.confphp-ini:  file.managed:    - name: /etc/php.ini    - source: salt://roles/php/files/php.ini    - user: root    - group: rootphp-fpm-conf:  file.managed:    - name: /etc/php-fpm.conf    - source: salt://roles/php/files/php-fpm.conf    - user: root    - group: roottimecash-conf:  file.managed:    - name: /etc/php-fpm.d/timecash.conf    - source: salt://roles/php/files/timecash.conf    - user: root    - group: root

top

/srv/salt/top.sls

vim /srv/salt/top.slsbase:  ‘*‘:    - roles.nginx.install    - roles.nginx.config    - roles.php.install    - roles.php.config

 

SaltStack學習系列之State安裝Nginx+PHP環境

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.