標籤: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環境