saltstack自动化安装部署nginx
本帖最后由 yun 于 2019-8-29 13:44 编辑环境:centos6.7
172.31.225.250 node1.example.com
172.31.225.251 node2.example.com
我们所需要用到的相关文件都在 /srv/salt/prod/files/ 这个目录下面,大家直接下载即可:
master相关配置:(/etc/salt/master)
file_roots:
base:
- /srv/salt/base
dev:
- /srv/salt/dev
prod:
- /srv/salt/prod
pillar_roots:
base:
- /srv/salt/base/pillar
dev:
- /srv/salt/dev/pillar
prod:
- /srv/salt/prod/pillar开始部署lnmp,个人建议一个一个的部署,不要把nginx、php、mysql都部署在一个文件,这样的话,针对minion端,可以针对性的部署相应的服务
1、部署nginx(这里个人是编译安装)
首先下载源码包:
wget http://nginx.org/download/nginx-1.16.1.tar.gz
初始化安装:(/srv/salt/prod/init/install.sls)
pkg-init-install:
pkg.removed:
- names:
- gcc
- gcc-c++
- glibc
- make
- autoconf
- libjpeg-turbo-devel
- libpng
- libpng-devel
- freetype-devel
- libxml2
- libxml2-devel
- zlib
- zlib-devel
- libcurl
- libcurl-devel
- openssl
- openssl-devel
- swig
pcre安装:(/srv/salt/prod/pcre.sls)
include:
- init.install
pcre-install:
file.managed:
- name: /usr/local/src/pcre-8.43.tar.gz
- source: salt://files/pcre-8.43.tar.gz
- user: root
- group: root
- mode: 644
cmd.run:
- name: cd /usr/local/src/ && tar xf pcre-8.43.tar.gz && cd pcre-8.43 && ./configure --prefix=/usr/local/pcre && make && make install
- unless: test -d /usr/local/pcre
- require:
- pkg: pkg-init-install
- file: pcre-installzlib安装:(/srv/salt/prod/zlib.sls)
include:
- init.install
zlib-install:
file.managed:
- name: /usr/local/src/zlib-1.2.11.tar.gz
- source: salt://files/zlib-1.2.11.tar.gz
- user: root
- group: root
- mode: 644
cmd.run:
- name: cd /usr/local/src/ && tar xf zlib-1.2.11.tar.gz && cd zlib-1.2.11 && ./configure --prefix=/usr/local/zlib && make && make install
- unless: test -d /usr/local/zlib
- require:
- pkg: pkg-init-install
- file: zlib-install
nginx安装:(/srv/salt/prod/nginx.sls)
include:
- init.install
- pcre
- zlib
nginx-source:
file.managed:
- name: /usr/local/src/nginx-1.16.1.tar.gz
- source: salt://files/nginx-1.16.1.tar.gz
- user: root
- group: root
- mode: 644
user-create:
cmd.run:
- name: useradd www -s /sbin/nologin && useradd -G www www
- unless: id www
- require_in:
- cmd: nginx-install
nginx-install:
cmd.run:
- name: cd /usr/local/src/ && tar xf nginx-1.16.1.tar.gz && cd nginx-1.16.1 && ./configure --prefix=/usr/local/nginx --user=www --group=www --with-pcre=/usr/local/src/pcre-8.43 --with-zlib=/usr/local/src/zlib-1.2.11 --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-http_dav_module && make && make install
- unless: test -d /usr/local/nginx
- require:
- pkg: pkg-init-install
- file: nginx-source
- cmd: pcre-install
- watch:
- cmd: zlib-install
nginx-conf:
file.managed:
- name: /usr/local/nginx/conf/nginx.conf
- source: salt://files/nginx.conf
- user: root
- group: root
- mode: 644
- require:
- cmd: nginx-install
nginx-init:
file.managed:
- name: /etc/init.d/nginx
- source: salt://files/nginx-test
- user: root
- group: root
- mode: 755
- require_in:
- service: nginx-service
nginx-service:
service.running:
- name: nginx
- enable: True
- require:
- cmd: nginx-install
- watch:
- file: nginx-conf
nginx-chkconfig:
cmd.run:
- name: chkconfig --add nginx
- unless: chkconfig --list | grep nginx
- require:
- service: nginx-service
下面正式安装:
安装之前最好先进行测试安装,检查有没有错误,因为在生产环境下直接执行安装错误,会导致对外服务的相关组件有可能出现问题,所以先进性测试安装salt '*' state.sls nginx env=prod test=True这里我测试没有问题,就直接安装了
salt '*' state.sls nginx env=prod查看nginx服务,或者查看80端口起没起来
访问http://172.31.225.250 和 http://172.31.225.251
至此就结束了。原创不易,转载请注明原创来处,谢谢!
相关文章:
saltstack自动化编译安装php
saltstack自动化安装编译mysql
页:
[1]