mrbear 发表于 2018-1-3 22:26:56

Saltstack批量编译部署nginx(多模块)

include:- soft.modules      #包含模块配置文件  
#
nginx.tar.gz  
nginx_source:
  file.managed:
  - name: /tmp/nginx-1.12.0.tar.gz      #标识文件所在位置
  - unless: test -e /tmp/nginx-1.12.0.tar.gz    #检测文件是否存在,只在第一次检测
  - source: salt://nginx/files/nginx-1.12.0.tar.gz    #把maser上的文件传过去
  
#extract
  
extract_nginx:
  cmd.run:
  - cwd: /tmp      #进入/tmp目录
  - names:
  - tar zxvf nginx-1.12.0.tar.gz      #解压
  - unless: test -d /tmp/nginx-1.12.0.tar.gz
  - require:
  - file: nginx_source      #这个命令必须在上面的函数执行成功后才继续执行
  
#user
  
nginx_user:
  user.present:      #用户创建
  - name: nginx
  - createhome: False      #不用家目录
  - gid_from_name: True
  - shell: /sbin/nologin      #指定shell
  
#nginx_pkgs
  
nginx_pkg:
  pkg.installed:      #安装必备组件
  - pkgs:
  - gcc
  - gcc-c++
  - epel-release
  - openssl-devel
  - pcre-devel
  - zlib-devel
  - gd-devel
  - lua-devel
  
#nginx_compile
  
nginx_compile:      #nginx进行编译
  
cmd.run:
  - cwd: /tmp/nginx-1.12.0
  - names:
  - ./configure --prefix=/usr/local/nginx--user=nginx--group=nginx --with-file-aio
  --with-http_ssl_module --with-http_realip_module --with-http_addition_module
  --with-http_image_filter_module --with-http_gzip_static_module
  --with-http_stub_status_module --with-mail --with-mail_ssl_module
  --with-pcre --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib
  --with-http_sub_module --add-module=/soft/ngx_cache_purge-2.3
  --add-module=/soft/ngx_devel_kit-0.3.0rc1
  --add-module=/soft/echo-nginx-module-master
  --add-module=/soft/lua-nginx-module-master && make && make install
  - require:
  - cmd: extract_nginx
  - pkg:nginx_pkg
  #- unless: test -d /usr/local/nginx/    #检测或不检测目录是否存在
  
#cache_dir
  
cache_dir:
  cmd.run:
  - names:      #创建虚拟主机目录,把nginx目录权限给相关用户
  - mkdir -p /usr/local/nginx/conf/vhosts && chown -R nginx.nginx /usr/local/nginx/
  - require:
  - cmd: nginx_compile
  - unless: test -d /usr/local/nginx/conf/vhosts/
  #vhosts
  
file.managed:
  - name: /usr/local/nginx/conf/nginx.conf    #修改后的配置文件复制过去
  - source: salt://nginx/files/nginx.conf
  #- unless: test -e /usr/local/nginx/conf/nginx.conf    #建议不进行检测,如果检测,有这个文件将不会进行更新
  

  
/usr/local/nginx/conf/proxy.conf:
  file.managed:
  - name: /usr/local/nginx/conf/proxy.conf
  - source: salt://nginx/files/proxy.conf
  #- unless: test -e /usr/local/nginx/conf/proxy.conf
页: [1]
查看完整版本: Saltstack批量编译部署nginx(多模块)