saltstack自动化编译安装php
本帖最后由 yun 于 2019-8-29 13:41 编辑环境: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、部署php(这里个人是编译安装)
首先下载源码包:
wget https://www.php.net/distributions/php-5.6.40.tar.gz
初始化安装:(/srv/salt/prod/init/install.sls)pkg-init-install:
pkg.installed:
- names:
- gcc
- gcc-c++
- glibc
- make
- automake
- autoconf
- libjpeg-turbo-devel
- libpng
- libpng-devel
- freetype-devel
- libxml2
- libxml2-devel
- zlib
- zlib-devel
- libcurl
- libcurl-devel
- openssl
- openssl-devel
- swig
- cmake
- ncurses-devel
- libmcrypt
- libmcrypt-devel
- libtool-ltdl-devel
- bison
- git
- gd
- gd-devel
- mcrypt
- libXpm
- libXpm-devel
- libevent
- libevent-devel
php安装:(/srv/salt/prod/php.sls)include:
- init.install
php-source:
file.managed:
- name: /usr/local/src/php-5.6.40.tar.gz
- source: salt://files/php-5.6.40.tar.gz
- user: root
- group: root
- mode: 644
- unless: test -f /usr/local/src/php-5.6.40.tar.gz
php-install:
cmd.run:
- name: cd /usr/local/src && tar xf php-5.6.40.tar.gz && cd php-5.6.40 && ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-zlib=/usr/local/zlib --enable-mbstring=all --enable-mbregex --enable-shared --enable-fpm && make && make install
- unless: test -d /usr/local/php
- require:
- pkg: pkg-init-install
- file: php-source
php-ini:
file.managed:
- name: /usr/local/php/etc/php.ini
- source: salt://files/php.ini-development
- user: root
- group: root
- mode: 644
- require:
- cmd: php-install
- watch_in:
- service: php-service
php-fpm-conf:
file.managed:
- name: /usr/local/php/etc/php-fpm.conf
- source: salt://files/php-fpm.conf
- user: root
- group: root
- mode: 644
/etc/init.d/php-fpm:
file.managed:
- source: salt://files/init.d.php-fpm
- user: root
- group: root
- mode: 755
- require:
- cmd: php-install
user-create:
cmd.run:
- name: groupadd www && useradd -r -g www www -s /sbin/nologin
- unless: id www
php-chkconfig:
cmd.run:
- name: chkconfig --add php-fpm
- unless: chkconfig --list | grep php-fpm
- require:
- file: /etc/init.d/php-fpm
php-service:
service.running:
- name: php-fpm
- enable: True
- require:
- file: /etc/init.d/php-fpm
- watch:
- file: php-fpm-conf
nginx-php:
file.managed:
- name: /usr/local/nginx/conf/enable-php.conf
- source: salt://files/enable-php.conf
- user: root
- group: root
- mode: 644
- require:
- service: php-service
下面正式安装:
安装之前最好先进行测试安装,检查有没有错误,因为在生产环境下直接执行安装错误,会导致对外服务的相关组件有可能出现问题,所以先进性测试安装salt '*' state.sls php env=prod test=True这里我测试没有问题,就直接安装了salt '*' state.sls php env=prod查看php服务
至此就结束了。原创不易,转载请注明原创来处,谢谢!
相关文章:
saltstack自动化安装编译mysql
saltstack自动化安装部署nginx
页:
[1]