黑帽联盟
标题:
saltstack自动化安装部署nginx
[打印本页]
作者:
yun
时间:
2019-8-27 17:19
标题:
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/ 这个目录下面,大家直接下载即可:
nginx.zip
(3.54 MB, 下载次数: 0)
2019-8-29 13:29 上传
点击文件名下载附件
下载积分: 黑币 -1
2019-8-29 13:30 上传
下载附件
(14.45 KB)
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)
2019-8-27 16:00 上传
下载附件
(7.18 KB)
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)
2019-8-27 15:59 上传
下载附件
(7.16 KB)
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-install
复制代码
zlib安装:(/srv/salt/prod/zlib.sls)
2019-8-27 16:02 上传
下载附件
(7.74 KB)
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)
2019-8-27 16:03 上传
下载附件
(7.81 KB)
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
复制代码
这里我测试没有问题,就直接安装了
2019-8-27 16:06 上传
下载附件
(4.08 KB)
salt '*' state.sls nginx env=prod
复制代码
查看nginx服务,或者查看80端口起没起来
2019-8-27 17:16 上传
下载附件
(8.83 KB)
2019-8-27 17:16 上传
下载附件
(7.79 KB)
访问http://172.31.225.250 和 http://172.31.225.251
2019-8-27 17:18 上传
下载附件
(27.16 KB)
2019-8-27 17:18 上传
下载附件
(27.42 KB)
至此就结束了。原创不易,转载请注明原创来处,谢谢!
相关文章:
saltstack自动化编译安装php
saltstack自动化安装编译mysql
欢迎光临 黑帽联盟 (https://bbs.cnblackhat.com/)
Powered by Discuz! X2.5