Directory structure
|--Pillar| |--Nginx| | `--Nginx.sls #nginx变量 (key:value)| `--Top.sls '--Salt|--Init #初始化目录| `--Repos.sls #安装yum源|--roles #角色 (Nginx and 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 #引用角色的
Preparation phase
Specify the directory for the master-side pillar and salt files
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 # server_name target:/alidata1/nginx/conf/vhosts/zhai.conf # of the vhost that renders Nginx Specifies to copy the configuration file from the master to the minion called web_dir:/alidata1/www/timecash22/zhai.timecash.cn # Specify Web program path
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 Learning Series State installation nginx+php environment