六:Saltstack之十五:saltstack一键部署编译版LHNMP

阅读(1,601)

一:本文的目的是实现生产环境下的LNMP环境的一键部署

#本文上接<<六:Saltstack之十四:saltstack系统初始化及minion文件备份>>

#本文的高级篇<<Saltstack之十六:saltstack一键部署Web环境>>

1.1:目录环境准备: #将不同功能的安装模块进行分类,方便后期进行调用

L:Centos 7.2

H:Haproxy 1.6.7

N:Nginx 1.8.1

M:Memcache 1.4.29

M:MySQL 5.6.31

P:Php 5.6.21

[root@saltmaster /srv/salt/prod]# mkdir haproxy  #前端负载均衡的目录
[root@saltmaster /srv/salt/prod]# mkdir keepalived #实现服务高可用目录
[root@saltmaster /srv/salt/prod]# mkdir nginx #web服务的目录
[root@saltmaster /srv/salt/prod]# mkdir php #php的目录
[root@saltmaster /srv/salt/prod]# mkdir memcached #memcache目录
[root@saltmaster /srv/salt/prod]# mkdir pkg #基础安装的目录

1.2:基础安装包准备:

# cd pkg/

# vim make.sls

make-pkg:
  pkg.installed:
    - pkgs:
      - gcc
      - gcc-c++
      - glibc
      - make
      - autoconf
      - openssl
      - openssl-devel
      - pcre
      - pcre-devel

1.3:haproxy安装:

1.3.1:准备源码包文件,上传到haproxy目录下:

#下载地址:http://www.haproxy.org/download/1.6/src/haproxy-1.6.7.tar.gz

# tar xvf haproxy-1.6.7.tar.gz

# cd haproxy-1.6.7

# make TARGET=linux2628 PREFIX=/usr/local/haproxy-1.6.7

# make install  PREFIX=/usr/local/haproxy-1.6.7 

# ln -sv /usr/local/haproxy-1.6.7/ /usr/local/haproxy

1.3.2:准备启动脚本:

# cp examples/haproxy.init  prod/haproxy/files 

#!/bin/sh
#
# chkconfig: - 85 15
# description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \
#              for high availability environments.
# processname: haproxy
# config: /etc/haproxy/haproxy.cfg
# pidfile: /var/run/haproxy.pid

# Script Author: Simon Matter <simon.matter@invoca.ch>
# Version: 2004060600

# Source function library.
if [ -f /etc/init.d/functions ]; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

# This is our service name
BASENAME=`basename $0`
if [ -L $0 ]; then
  BASENAME=`find $0 -name $BASENAME -printf %l`
  BASENAME=`basename $BASENAME`
fi

BIN=/usr/local/haproxy/sbin/$BASENAME

CFG=/etc/$BASENAME/$BASENAME.cfg
[ -f $CFG ] || exit 1

PIDFILE=/var/run/$BASENAME.pid
LOCKFILE=/var/lock/subsys/$BASENAME

RETVAL=0

start() {
  quiet_check
  if [ $? -ne 0 ]; then
    echo "Errors found in configuration file, check it with '$BASENAME check'."
    return 1
  fi

  echo -n "Starting $BASENAME: "
  daemon $BIN -D -f $CFG -p $PIDFILE
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch $LOCKFILE
  return $RETVAL
}

stop() {
  echo -n "Shutting down $BASENAME: "
  killproc $BASENAME -USR1
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
  [ $RETVAL -eq 0 ] && rm -f $PIDFILE
  return $RETVAL
}

restart() {
  quiet_check
  if [ $? -ne 0 ]; then
    echo "Errors found in configuration file, check it with '$BASENAME check'."
    return 1
  fi
  stop
  start
}

reload() {
  if ! [ -s $PIDFILE ]; then
    return 0
  fi

  quiet_check
  if [ $? -ne 0 ]; then
    echo "Errors found in configuration file, check it with '$BASENAME check'."
    return 1
  fi
  $BIN -D -f $CFG -p $PIDFILE -sf $(cat $PIDFILE)
}

check() {
  $BIN -c -q -V -f $CFG
}

quiet_check() {
  $BIN -c -q -f $CFG
}

rhstatus() {
  status $BASENAME
}

condrestart() {
  [ -e $LOCKFILE ] && restart || :
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  reload)
    reload
    ;;
  condrestart)
    condrestart
    ;;
  status)
    rhstatus
    ;;
  check)
    check
    ;;
  *)
    echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status|check}"
    exit 1
esac
 
exit $?

1.3.3:准备状态文件:

# vim haproxy/install.sls

include:
  - pkg.make #引用pkg目录下的make状态文件安装基础依赖环境关系

haproxy-install:
  file.managed:
    - name: /usr/local/src/haproxy-1.6.7.tar.gz #在客户端的位置
    - source: salt://haproxy/files/haproxy-1.6.7.tar.gz
    - mode: 755
    - user: root
    - group: root

  cmd.run: #执行状态模块
    - name: cd /usr/local/src && tar xf haproxy-1.6.7.tar.gz && cd haproxy-1.6.7 && make TARGET=linux2628 PREFIX=/usr/local/haproxy-1.6.7 && make install  PREFIX=/usr/local/haproxy-1.6.7 && ln -s /usr/local/haproxy-1.6.7/ /usr/local/haproxy &&
    - unless: test -L /usr/local/haproxy #如果unless返回为True就不执行cmd.run
    - require: #依赖关系
      - pkg: make-pkg  #依赖导入的pkg目录下的make-pkg状态ID
      - file: haproxy-install #依赖file模块下的haproxy-install

unles:如果后面的命令返回为True就不执行状态,否则每次执行状态都会执行该状态文件

onlyif:

1.3.4:执行haproxy状态文件:

# salt “saltminion*” state.sls haproxy.install saltenv=prod  #saltenv=prod为指定base环境

1.3.5:管理haproxy启动脚本:

/etc/init.d/haproxy:
  file.managed:
    - source: salt://haproxy/files/haproxy.init  #保存在prod环境下的haproxy/files目录
    - mode: 755
    - user: root
    - group: root
    - require_in: #执行到这里的时候要依赖先把haproxy-install执行成功
      - file: haproxy-install

1.3.6:内核优化,运行监听本地没有的IP地址,默认只能监听本地的IP地址:

net.ipv4.ip_nolocal_bind:
  sysctl.present:
    - value: 1

1.3.7:测试同步启动脚本:

# salt “saltminion*” state.sls haproxy.install saltenv=prod 

2:业务层引用,将目录重新分层进行引用,如负载层、web层、数据库层等:

2.1:目录创建,创建一个业务层的目录:

# mkdir modules   #在/srv/salt/prod目录下,modules目录保存所有的基础模块

# mv  modules/cluster/ . 

# mkdir cluster 

2.1.1:修改状态文件的路径:

# vim modules/haproxy/install.sls

include:
  - modules.pkg.make #引用pkg目录下的make状态文件安装基础依赖环境关系

haproxy-install:
  file.managed:
    - name: /usr/local/src/haproxy-1.6.7.tar.gz #在客户端的位置
    - source: salt://modules/haproxy/files/haproxy-1.6.7.tar.gz #保存源码的目录路径要改成base目录下的实际路径
    - mode: 755
    - user: root
    - group: root
  cmd.run: #执行状态模块
    - name: cd /usr/local/src && tar xvf  haproxy-1.6.7.tar.gz && cd haproxy-1.6.7 && make TARGET=linux2628 PREFIX=/usr/local/haproxy-1.6.7 && make install  PREFIX=/usr/local/haproxy-1.6.7 && ln -s /usr/local/haproxy-1.6.7 /usr/local/haproxy
    - unless: test -L /usr/local/haproxy #如果unless返回为True就不执行cmd.run
    - require: #依赖关系
      - pkg: make-pkg  #依赖导入的pkg目录下的make-pkg状态ID
      - file: haproxy-install #依赖file模块下的haproxy-install

/etc/init.d/haproxy:
  file.managed:
    - source: salt://modules/haproxy/files/haproxy.init
    - mode: 755
    - user: root
    - group: root
    - require_in: #执行到这里的时候要依赖先把haproxy-install执行成功
      - file: haproxy-install

net.ipv4.ip_nolocal_bind:
  sysctl.present:
    - value: 1

2.1.2:执行状态文件:

# salt “saltminion*” state.sls   modules.haproxy.install saltenv=prod

2.2:创建目录保存文件,用于保存分发的配置文件及相关资料

[root@saltmaster /srv/salt/prod/cluster]# pwd
/srv/salt/prod/cluster

#mkdir files  #在/srv/salt/prod/cluster

[root@saltmaster /srv/salt/prod/cluster]# cd files/

[root@saltmaster /srv/salt/prod/cluster/files]# vim  haproxy-outside.cfg #名称用于区分是web负载层的haproxy

global
maxconn 100000
chroot /usr/local/haproxy
uid 99
gid 99
daemon
nbproc 1
pidfile /usr/local/haproxy/logs/haproxy.pid
log 127.0.0.1 local3 info

defaults
option http-keep-alive
maxconn 100000
mode http
timeout connect 5000ms
timeout client  50000ms
timeout server 50000ms

listen stats
mode http
bind 0.0.0.0:8888
stats enable
stats uri     /haproxy-status
stats auth    admin:123456

frontend frontend_www_example_com
bind 192.168.10.102:80
mode http
option httplog
log global
    default_backend backend_www_example_com

backend backend_www_example_com
option forwardfor header X-REAL-IP
option httpchk HEAD / HTTP/1.0
balance source
server web-node1  192.168.10.101:8008 check inter 2000 rise 30 fall 15
server web-node2  192.168.10.102:8008 check inter 2000 rise 30 fall 15

2.3:编写haproxy的状态文件:
[root@saltmaster /srv/salt/prod/cluster/files]# cd ..
[root@saltmaster /srv/salt/prod/cluster]# vim haproxy-outside.sls

include:
  - modules.haproxy.install

haproxy-service:
  file.managed:
    - name: /etc/haproxy/haproxy.cfg
    - source: salt://cluster/files/haproxy-outside.cfg #刚才编写的haproxy配置文件的路径
    - user: root
    - group: root
    - mode: 644
  service.running:
    - name: haproxy
    - enable: True
    - reload: True
    - require:
      - cmd: haproxy-install
    - watch:
      - file: haproxy-service

2.4:编写topfile:

# vim /srv/salt/base/top.sls 

base:
  "*":
    - init.init
prod: #定义prod环境
  "saltminion*": #指定的主机
    - cluster.haproxy-outside #匹配的主机要执行的状态文件

2.5:执行高级状态:

# salt “saltminion*” state.highstate #此时在启动服务的时候会报错,因为现在还没有haproxy的服务启动,因此要改造一下安装haproxy的状态文件

2.6:改造haproxy状态文件如下:

# vim /srv/salt/prod/modules/haproxy/install.sls

include:
  - modules.pkg.make #引用pkg目录下的make状态文件安装基础依赖环境关系

haproxy-install:
  file.managed:
    - name: /usr/local/src/haproxy-1.6.7.tar.gz #在客户端的位置
    - source: salt://modules/haproxy/files/haproxy-1.6.7.tar.gz
    - mode: 755
    - user: root
    - group: root
  cmd.run: #执行状态模块
    - name: cd /usr/local/src && tar xvf  haproxy-1.6.7.tar.gz && cd haproxy-1.6.7 && make TARGET=linux2628 PREFIX=/usr/local/haproxy-1.6.7 && make install  PREFIX=/usr/local/haproxy-1.6.7 && ln -s /usr/local/haproxy-1.6.7 /usr/local/haproxy
    - unless: test -L /usr/local/haproxy #如果unless返回为True就不执行cmd.run
    - require: #依赖关系
      - pkg: make-pkg  #依赖导入的pkg目录下的make-pkg状态ID
      - file: haproxy-install #依赖file模块下的haproxy-install


haproxy-init:
  file.managed:
    - name: /etc/init.d/haproxy
    - source: salt://modules/haproxy/files/haproxy.init
    - mode: 755
    - user: root
    - group: root
    - require_in: #执行到这里的时候要依赖先把haproxy-install执行成功
      - file: haproxy-install
    - cmd.run:
      - name: chkconfig --add haproxy
      - unless: chkconfig  --list | grep haproxy #当执行失败的时候才执行cmd.run

net.ipv4.ip_nolocal_bind:
  sysctl.present:
    - value: 1

2.7:再次执行高级状态:

# salt “saltminion*” state.highstate  #如果提示haproxy.cfg文件出错,就检查是否有/etc/haproxy目录

2.8:测试,访问haproxy的状态页面:

2.8.1:登录界面,用户admin密码123456

2.8.2:状态界面:

三:通过saltstack编译安装memcache:

3.1:规划,源文件放在salt生产环境prod根目录modules中memcached中的files目录,instal.sls文件放在modules目录中memcached,后期会进行文件调用:

3.2:解决依赖关系,memcache依赖libevent:

# vim modules/memcached/libevent-install.sls 

include:
  - modules.pkg.make

libevent-install:
  file.managed:
    - name: /usr/local/src/libevent-2.0.21-stable.tar.gz
    - source: salt://modules/memcached/files/libevent-2.0.21-stable.tar.gz
    - unless: test -e /usr/local/src/libevent-2.0.21-stable.tar.gz #如果minion端此文件已经存在就不再执行
    - user: root
    - group: root
    - mode: 755
  cmd.run:
    - name: cd /usr/local/src && tar xf libevent-2.0.21-stable.tar.gz && cd libevent-2.0.21-stable && ./configure  --prefix=/usr/local/libevent && make && make install
    - unless: test -d /usr/local/libevent #如果minion已经端此目录已经存在就不执行cmd.run
    - require: #执行cmd.run之前先把依赖执行成功
      - pkg: make-pkg
      - file: libevent-install

3.3:安装memcache:

include:
  - modules.pkg.make
  - modules.memcached.libevent-install #执行的时候导入libevent的安装状态文件

memcache-install: #先把源文件传递给minion
  file.managed:
    - name: /usr/local/src/memcached-1.4.29.tar.gz #在客户端的位置
    - source: salt://modules/memcached/files/memcached-1.4.29.tar.gz #在salt master的源位置
    - user: root
    - group: root
    - mode: 755
  cmd.run: #执行远程命令
    - name: cd /usr/local/src && tar xf memcached-1.4.29.tar.gz && cd memcached-1.4.29 && ./configure  --prefix=/usr/local/memcached-1.4.29 --with-libevent=/usr/local/libevent  && make && make install && ln -sv /usr/local/memcached-1.4.29 /usr/local/memcached
    - unless: test -L  /usr/local/memcached #如果minion端此链接已经存在就不执行cmd.run
    - require:
      - pkg: make-pkg
      - file: libevent-install #先把libevent安装完成

3.4:执行安装memcache状态文件:

# salt “saltminion2*” state.sls modules.memcached.install  saltenv=prod 

3.5:启动memcache,可以写在状态文件启动也可以在minion远程启动,启动命令如下:

#/usr/local/memcached/bin/memcached  -d -m 1024  -u root -l192.168.10.103 x -p 12000 -c 1024 –P /tmp/memcached.pid 

-d  #表示启动一个守护进程
-m  #是分配给memcached使用的内存
-u  #运行memcached的用户
-l  #是memcached监听的ip
-p  #是memcached监听的端口
-c  #memcache运行的最大并发连接数
-P  #是设置memcache的pid文件

四:通过saltstack 编译安装Nginx:

4.1:目录规划:prod的主目录是/srv/salt/prod,nginx目录位于主目录下的modules/nginx,源码放在modules/nginx/files,安装文件为install.sls

4.2:编写install.sls:

include:
  - modules.pkg.make

nginx-install:
  file.managed:
    - name: /usr/local/src/nginx-1.8.1.tar.gz
    - source: salt://modules/nginx/files/nginx-1.8.1.tar.gz
    - user: root
    - group: root
    - mode: 755
  cmd.run:
     - name: cd /usr/local/src && tar  xvf nginx-1.8.1.tar.gz && cd nginx-1.8.1 && ./configure  --prefix=/usr/local/nginx-1.8.1  && make && make install && ln -s /usr/local/nginx-1.8.1 /usr/local/nginx && useradd nginx -s /sbin/nologin
     - unless: test -L /usr/local/nginx
     - require:
       - pkg: make-pkg
       - file: nginx-install

nginx-init:
  file.managed:
    - name: /etc/init.d/nginx
    - source: salt://modules/nginx/files/nginx
    - user: root
    - group: root
    - mode: 755
  cmd.run:
    - name: systemctl daemon-reload && chkconfig --add nginx   
    - unless: chkconfig --list | grep nginx     
    - require:
      - file: nginx-install
      - file: nginx-init

nginx-config:
  file.managed:
    - name: /usr/local/nginx/conf/nginx.conf
    - source: salt://modules/nginx/files/nginx.conf
    - user: root
    - group: root
    - mode: 644
    - require: #依赖于nginx-install
      - file: nginx-install
    - watch_in: #被nginx服务控制监控
      - service: nginx-service

nginx-service: #nginx服务启动
  service.running:
    - name: nginx
    - enable: True
    - reload: True
    - require:
      - file: nginx-config

4.3:准备配置文件即nginx.conf:

# cat  /srv/salt/prod/modules/nginx/files/nginx

user  nginx nginx;
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       6009;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

4.4:准备启动脚本:

#! /bin/bash
# Description: Startup script for webserver on CentOS. cp it in /etc/init.d and
# chkconfig --add nginx && chkconfig nginx on
# then you can use server command control nginx
#
# chkconfig: 2345 08 99
# description: Starts, stops nginx
set -e
PATH=$PATH:/usr/local/nginx/sbin/
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/usr/local/nginx/logs/nginx.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() {
$DAEMON -c $CONFIGFILE || echo -n " already running"
}
d_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
d_reload() {
kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
exit 0

4.5:将源码放在files目录,最终的文件如下:

# ls /srv/salt/prod/modules/nginx/files/

nginx  nginx-1.8.1.tar.gz  nginx.conf

4.6:执行nginx状态文件:

# salt “saltminion2*” state.sls modules.nginx.install  saltenv=prod #可以在客户端自动部署nginx,但是启动脚本在centos 7系统下只能是/etc/init.d/nginx启动

五:通过saltstack 安装MySQL:

5.1:环境规划:

#将mysql 5.6.31的安装包和配置文件以及启动脚本放在modules/mysql/files 

5.2:编写install.sls状态文件,mysql使用yum安装:

# vim modules/mysql/install.sls 

include:
 - modules.pkg.mysql

mysql-install:
  cmd.run:
    - name: yum install mariadb  mariadb-server -y && touch  /var/log/mysqld.log && chown  mysql.mysql /var/log/mysqld.log && mkdir -pv /var/run/mysqld &&  chown  mysql.mysql /var/run/mysqld/ -R

mysql-conf:
  file.managed:
    - name: /etc/my.cnf
    - source: salt://modules/mysql/files/my.cnf
    - require:
      - cmd: mysql-install

mysql-server:
  service.running:
    - name: mariadb
    - enable: True
    - watch:
      - cmd: mysql-install
      - file: mysql-conf

5.3:准备配置文件:

# vim modules/mysql/files/my.cnf

[mysqld]
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
datadir=/data/mysql
#socket = /tmp/mysql.sock
innodb_file_per_table=1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

5.4:测试安装:

# salt “saltminion2*” state.sls modules.mysql.install   saltenv=prod

六:五:通过saltstack 安装Php : 

6.1:规划:将php的源码包放在/srv/salt/prod/modules/php/files,安装的状态文件放在/srv/salt/prod/modules/php里面:

6.2:编写php的编译依赖环境make-php.sls状态文件:

[root@saltmaster /srv/salt/prod/modules/pkg]# vim make-php.sls

pkg-php:
  pkg.installed:
    - names:
      - swig
      - libjpeg-turbo
      - libjpeg-turbo-devel
      - libpng
      - libpng-devel
      - freetype
      - freetype-devel
      - libxml2
      - libxml2-devel
      - zlib
      - zlib-devel
      - libcurl
      - libcurl-devel

6.3:编写php启动用户php-user.sls状态文件:

www-user-group:
  group.present:
    - name: www
    - gid: 1000

  user.present:
    - name: www
    - fullname: www
    - shell: /sbin/nologin
    - uid: 1000
    - gid: 1000

6.4:编写编译安装php的install.sls状态文件:

include:
  - modules.pkg.make-php
  - modules.pkg.user-php

php-install:
  file.managed:
    - name: /usr/local/src/php-5.6.21.tar.gz
    - source: salt://modules/php/files/php-5.6.21.tar.gz
    - user: root
    - group: root
    - mode: 755
    - unless: test -e /usr/local/src/php-5.6.21.tar.gz
  cmd.run:
    - name: cd /usr/local/src && tar xf php-5.6.21.tar.gz && cd php-5.6.21 && ./configure --prefix=/usr/local/php-fastcgi --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --with-jpeg-dir --with-png-dir --with-zlib --enable-xml  --with-libxml-dir --with-curl --enable-bcmath --enable-shmop --enable-sysvsem  --enable-inline-optimization --enable-mbregex --with-openssl --enable-mbstring --with-gd --enable-gd-native-ttf --with-freetype-dir=/usr/lib64 --with-gettext=/usr/lib64 --enable-sockets --with-xmlrpc --enable-zip --enable-soap --disable-debug --enable-opcache --enable-zip --with-config-file-path=/usr/local/php-fastcgi/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www && make && make install
    - require:
      - file: php-install
      - user: www-user-group
    - unless: test -d /usr/local/php-fastcgi

6.5:管理配置文件php-fpm.conf 与php-fpm脚本:

6.5.1:启动脚本:

vim php/files/init.d.php-fpm

#! /bin/sh

### BEGIN INIT INFO
# Provides:          php-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO

prefix=/usr/local/php-fastcgi
exec_prefix=${prefix}

php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid


php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"


wait_for_pid () {
	try=0

	while test $try -lt 35 ; do

		case "$1" in
			'created')
			if [ -f "$2" ] ; then
				try=''
				break
			fi
			;;

			'removed')
			if [ ! -f "$2" ] ; then
				try=''
				break
			fi
			;;
		esac

		echo -n .
		try=`expr $try + 1`
		sleep 1

	done

}

case "$1" in
	start)
		echo -n "Starting php-fpm "

		$php_fpm_BIN --daemonize $php_opts

		if [ "$?" != 0 ] ; then
			echo " failed"
			exit 1
		fi

		wait_for_pid created $php_fpm_PID

		if [ -n "$try" ] ; then
			echo " failed"
			exit 1
		else
			echo " done"
		fi
	;;

	stop)
		echo -n "Gracefully shutting down php-fpm "

		if [ ! -r $php_fpm_PID ] ; then
			echo "warning, no pid file found - php-fpm is not running ?"
			exit 1
		fi

		kill -QUIT `cat $php_fpm_PID`

		wait_for_pid removed $php_fpm_PID

		if [ -n "$try" ] ; then
			echo " failed. Use force-quit"
			exit 1
		else
			echo " done"
		fi
	;;

	status)
		if [ ! -r $php_fpm_PID ] ; then
			echo "php-fpm is stopped"
			exit 0
		fi

		PID=`cat $php_fpm_PID`
		if ps -p $PID | grep -q $PID; then
			echo "php-fpm (pid $PID) is running..."
		else
			echo "php-fpm dead but pid file exists"
		fi
	;;

	force-quit)
		echo -n "Terminating php-fpm "

		if [ ! -r $php_fpm_PID ] ; then
			echo "warning, no pid file found - php-fpm is not running ?"
			exit 1
		fi

		kill -TERM `cat $php_fpm_PID`

		wait_for_pid removed $php_fpm_PID

		if [ -n "$try" ] ; then
			echo " failed"
			exit 1
		else
			echo " done"
		fi
	;;

	restart)
		$0 stop
		$0 start
	;;

	reload)

		echo -n "Reload service php-fpm "

		if [ ! -r $php_fpm_PID ] ; then
			echo "warning, no pid file found - php-fpm is not running ?"
			exit 1
		fi

		kill -USR2 `cat $php_fpm_PID`

		echo " done"
	;;

	*)
		echo "Usage: $0 {start|stop|force-quit|restart|reload|status}"
		exit 1
	;;

esac

 6.5.2:配置文件:

;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;

; All relative paths in this configuration file are relative to PHP's install
; prefix (/usr/local/php). This prefix can be dynamically changed by using the
; '-p' argument from the command line.

; Include one or more files. If glob(3) exists, it is used to include a bunch of
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used. They will be prefixed by:
;  - the global prefix if it's been set (-p argument)
;  - /usr/local/php otherwise
;include=etc/fpm.d/*.conf

;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;

[global]
; Pid file
; Note: the default prefix is /usr/local/php/var
; Default Value: none
;pid = run/php-fpm.pid

; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
; in a local file.
; Note: the default prefix is /usr/local/php/var
; Default Value: log/php-fpm.log
error_log = /tmp/php-fpm.log

; syslog_facility is used to specify what type of program is logging the
; message. This lets syslogd specify that messages from different facilities
; will be handled differently.
; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
; Default Value: daemon
;syslog.facility = daemon

; syslog_ident is prepended to every message. If you have multiple FPM
; instances running on the same server, you can change the default value
; which must suit common needs.
; Default Value: php-fpm
;syslog.ident = php-fpm

; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
;log_level = notice

; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of '0' means 'Off'.
; Default Value: 0
;emergency_restart_threshold = 0

; Interval of time used by emergency_restart_interval to determine when 
; a graceful restart will be initiated.  This can be useful to work around
; accidental corruptions in an accelerator's shared memory.
; Available Units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
;emergency_restart_interval = 0

; Time limit for child processes to wait for a reaction on signals from master.
; Available units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
;process_control_timeout = 0

; The maximum number of processes FPM will fork. This has been design to control
; the global number of processes when using dynamic PM within a lot of pools.
; Use it with caution.
; Note: A value of 0 indicates no limit
; Default Value: 0
; process.max = 128

; Specify the nice(2) priority to apply to the master process (only if set)
; The value can vary from -19 (highest priority) to 20 (lower priority)
; Note: - It will only work if the FPM master process is launched as root
;       - The pool process will inherit the master process priority
;         unless it specified otherwise
; Default Value: no set
; process.priority = -19

; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
;daemonize = yes
 
; Set open file descriptor rlimit for the master process.
; Default Value: system defined value
;rlimit_files = 1024
 
; Set max core size rlimit for the master process.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0

; Specify the event mechanism FPM will use. The following is available:
; - select     (any POSIX os)
; - poll       (any POSIX os)
; - epoll      (linux >= 2.5.44)
; - kqueue     (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)
; - /dev/poll  (Solaris >= 7)
; - port       (Solaris >= 10)
; Default Value: not set (auto detection)
;events.mechanism = epoll

; When FPM is build with systemd integration, specify the interval,
; in second, between health report notification to systemd.
; Set to 0 to disable.
; Available Units: s(econds), m(inutes), h(ours)
; Default Unit: seconds
; Default value: 10
;systemd_interval = 10

;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ; 
;;;;;;;;;;;;;;;;;;;;

; Multiple pools of child processes may be started with different listening
; ports and different management options.  The name of the pool will be
; used in logs and stats. There is no limitation on the number of pools which
; FPM can handle. Your system will tell you anyway 🙂

; Start a new pool named 'www'.
; the variable $pool can we used in any directive and will be replaced by the
; pool name ('www' here)
[www]

; Per pool prefix
; It only applies on the following directives:
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or /usr/local/php) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = www
group = www

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /usr/local/php-fastcgi/php-fpm.sock

; Set listen(2) backlog.
; Default Value: 65535 (-1 on FreeBSD and OpenBSD)
;listen.backlog = 65535

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions. 
; Default Values: user and group are set as the running user
;                 mode is set to 0660
listen.owner = www
listen.group = www
listen.mode = 0660
 
; List of ipv4 addresses of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
;listen.allowed_clients = 127.0.0.1

; Specify the nice(2) priority to apply to the pool processes (only if set)
; The value can vary from -19 (highest priority) to 20 (lower priority)
; Note: - It will only work if the FPM master process is launched as root
;       - The pool processes will inherit the master process priority
;         unless it specified otherwise
; Default Value: no set
; process.priority = -19

; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives. With this process management, there will be
;             always at least 1 children.
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
;  ondemand - no children are created at startup. Children will be forked when
;             new requests will connect. The following parameter are used:
;             pm.max_children           - the maximum number of children that
;                                         can be alive at the same time.
;             pm.process_idle_timeout   - The number of seconds after which
;                                         an idle process will be killed.
; Note: This value is mandatory.
pm = dynamic

; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 50

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 20

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 10

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 30

; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
;pm.process_idle_timeout = 10s;
 
; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
pm.max_requests = 50000

; The URI to view the FPM status page. If this value is not set, no URI will be
; recognized as a status page. It shows the following informations:
;   pool                 - the name of the pool;
;   process manager      - static, dynamic or ondemand;
;   start time           - the date and time FPM has started;
;   start since          - number of seconds since FPM has started;
;   accepted conn        - the number of request accepted by the pool;
;   listen queue         - the number of request in the queue of pending
;                          connections (see backlog in listen(2));
;   max listen queue     - the maximum number of requests in the queue
;                          of pending connections since FPM has started;
;   listen queue len     - the size of the socket queue of pending connections;
;   idle processes       - the number of idle processes;
;   active processes     - the number of active processes;
;   total processes      - the number of idle + active processes;
;   max active processes - the maximum number of active processes since FPM
;                          has started;
;   max children reached - number of times, the process limit has been reached,
;                          when pm tries to start more children (works only for
;                          pm 'dynamic' and 'ondemand');
; Value are updated in real time.
; Example output:
;   pool:                 www
;   process manager:      static
;   start time:           01/Jul/2011:17:53:49 +0200
;   start since:          62636
;   accepted conn:        190460
;   listen queue:         0
;   max listen queue:     1
;   listen queue len:     42
;   idle processes:       4
;   active processes:     11
;   total processes:      15
;   max active processes: 12
;   max children reached: 0
;
; By default the status page output is formatted as text/plain. Passing either
; 'html', 'xml' or 'json' in the query string will return the corresponding
; output syntax. Example:
;   http://www.foo.bar/status
;   http://www.foo.bar/status?json
;   http://www.foo.bar/status?html
;   http://www.foo.bar/status?xml
;
; By default the status page only outputs short status. Passing 'full' in the
; query string will also return status for each pool process.
; Example: 
;   http://www.foo.bar/status?full
;   http://www.foo.bar/status?json&full
;   http://www.foo.bar/status?html&full
;   http://www.foo.bar/status?xml&full
; The Full status returns for each process:
;   pid                  - the PID of the process;
;   state                - the state of the process (Idle, Running, ...);
;   start time           - the date and time the process has started;
;   start since          - the number of seconds since the process has started;
;   requests             - the number of requests the process has served;
;   request duration     - the duration in µs of the requests;
;   request method       - the request method (GET, POST, ...);
;   request URI          - the request URI with the query string;
;   content length       - the content length of the request (only with POST);
;   user                 - the user (PHP_AUTH_USER) (or '-' if not set);
;   script               - the main script called (or '-' if not set);
;   last request cpu     - the %cpu the last request consumed
;                          it's always 0 if the process is not in Idle state
;                          because CPU calculation is done when the request
;                          processing has terminated;
;   last request memory  - the max amount of memory the last request consumed
;                          it's always 0 if the process is not in Idle state
;                          because memory calculation is done when the request
;                          processing has terminated;
; If the process is in Idle state, then informations are related to the
; last request the process has served. Otherwise informations are related to
; the current request being served.
; Example output:
;   ************************
;   pid:                  31330
;   state:                Running
;   start time:           01/Jul/2011:17:53:49 +0200
;   start since:          63087
;   requests:             12808
;   request duration:     1250261
;   request method:       GET
;   request URI:          /test_mem.php?N=10000
;   content length:       0
;   user:                 -
;   script:               /home/fat/web/docs/php/test_mem.php
;   last request cpu:     0.00
;   last request memory:  0
;
; Note: There is a real-time FPM status monitoring sample web page available
;       It's available in: ${prefix}/share/fpm/status.html
;
; Note: The value must start with a leading slash (/). The value can be
;       anything, but it may not be a good idea to use the .php extension or it
;       may conflict with a real PHP file.
; Default Value: not set 
;pm.status_path = /status
 
; The ping URI to call the monitoring page of FPM. If this value is not set, no
; URI will be recognized as a ping page. This could be used to test from outside
; that FPM is alive and responding, or to
; - create a graph of FPM availability (rrd or such);
; - remove a server from a group if it is not responding (load balancing);
; - trigger alerts for the operating team (24/7).
; Note: The value must start with a leading slash (/). The value can be
;       anything, but it may not be a good idea to use the .php extension or it
;       may conflict with a real PHP file.
; Default Value: not set
;ping.path = /ping

; This directive may be used to customize the response of a ping request. The
; response is formatted as text/plain with a 200 response code.
; Default Value: pong
;ping.response = pong

; The access log file
; Default: not set
;access.log = log/$pool.access.log

; The access log format.
; The following syntax is allowed
;  %%: the '%' character
;  %C: %CPU used by the request
;      it can accept the following format:
;      - %{user}C for user CPU only
;      - %{system}C for system CPU only
;      - %{total}C  for user + system CPU (default)
;  %d: time taken to serve the request
;      it can accept the following format:
;      - %{seconds}d (default)
;      - %{miliseconds}d
;      - %{mili}d
;      - %{microseconds}d
;      - %{micro}d
;  %e: an environment variable (same as $_ENV or $_SERVER)
;      it must be associated with embraces to specify the name of the env
;      variable. Some exemples:
;      - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
;      - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
;  %f: script filename
;  %l: content-length of the request (for POST request only)
;  %m: request method
;  %M: peak of memory allocated by PHP
;      it can accept the following format:
;      - %{bytes}M (default)
;      - %{kilobytes}M
;      - %{kilo}M
;      - %{megabytes}M
;      - %{mega}M
;  %n: pool name
;  %o: output header
;      it must be associated with embraces to specify the name of the header:
;      - %{Content-Type}o
;      - %{X-Powered-By}o
;      - %{Transfert-Encoding}o
;      - ....
;  %p: PID of the child that serviced the request
;  %P: PID of the parent of the child that serviced the request
;  %q: the query string 
;  %Q: the '?' character if query string exists
;  %r: the request URI (without the query string, see %q and %Q)
;  %R: remote IP address
;  %s: status (response code)
;  %t: server time the request was received
;      it can accept a strftime(3) format:
;      %d/%b/%Y:%H:%M:%S %z (default)
;  %T: time the log has been written (the request has finished)
;      it can accept a strftime(3) format:
;      %d/%b/%Y:%H:%M:%S %z (default)
;  %u: remote user
;
; Default: "%R - %u %t \"%m %r\" %s"
;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
 
; The log file for slow requests
; Default Value: not set
; Note: slowlog is mandatory if request_slowlog_timeout is set
;slowlog = log/$pool.log.slow
 
; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_slowlog_timeout = 0
 
; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_terminate_timeout = 0
 
; Set open file descriptor rlimit.
; Default Value: system defined value
;rlimit_files = 1024
 
; Set max core size rlimit.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0
 
; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
; of its subdirectories. If the pool prefix is not set, the global prefix
; will be used instead.
; Note: chrooting is a great security feature and should be used whenever 
;       possible. However, all PHP paths will be relative to the chroot
;       (error_log, sessions.save_path, ...).
; Default Value: not set
;chroot = 
 
; Chdir to this directory at the start.
; Note: relative path can be used.
; Default Value: current directory or / when chroot
;chdir = /var/www
 
; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Note: on highloaded environement, this can cause some delay in the page
; process time (several ms).
; Default Value: no
;catch_workers_output = yes

; Clear environment in FPM workers
; Prevents arbitrary environment variables from reaching FPM worker processes
; by clearing the environment in workers before env vars specified in this
; pool configuration are added.
; Setting to "no" will make all environment variables available to PHP code
; via getenv(), $_ENV and $_SERVER.
; Default Value: yes
;clear_env = no

; Limits the extensions of the main script FPM will allow to parse. This can
; prevent configuration mistakes on the web server side. You should only limit
; FPM to .php extensions to prevent malicious users to use other extensions to
; exectute php code.
; Note: set an empty value to allow all extensions.
; Default Value: .php
;security.limit_extensions = .php .php3 .php4 .php5
 
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp

; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
;   php_value/php_flag             - you can set classic ini defines which can
;                                    be overwritten from PHP call 'ini_set'. 
;   php_admin_value/php_admin_flag - these directives won't be overwritten by
;                                     PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.

; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead.

; Note: path INI options can be relative and will be expanded with the prefix
; (pool, global or /usr/local/php)

; Default Value: nothing is defined by default except the values in php.ini and
;                specified at startup with the -d argument
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
;php_admin_value[error_log] = /var/log/fpm-php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M

6.5.3:install状态文件:

 #vim php/install.sls

include:
  - modules.pkg.make-php
  - modules.pkg.user-php

php-install:
  file.managed:
    - name: /usr/local/src/php-5.6.21.tar.gz
    - source: salt://modules/php/files/php-5.6.21.tar.gz
    - user: root
    - group: root
    - mode: 755
    - unless: test -e /usr/local/src/php-5.6.21.tar.gz
  cmd.run:
    - name: cd /usr/local/src && tar xf php-5.6.21.tar.gz && cd php-5.6.21 && ./configure --prefix=/usr/local/php-fastcgi --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --with-jpeg-dir --with-png-dir --with-zlib --enable-xml  --with-libxml-dir --with-curl --enable-bcmath --enable-shmop --enable-sysvsem  --enable-inline-optimization --enable-mbregex --with-openssl --enable-mbstring --with-gd --enable-gd-native-ttf --with-freetype-dir=/usr/lib64 --with-gettext=/usr/lib64 --enable-sockets --with-xmlrpc --enable-zip --enable-soap --disable-debug --enable-opcache --enable-zip --with-config-file-path=/usr/local/php-fastcgi/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www && make && make install 
    - require:
      - file: php-install
      - user: www-user-group
    - unless: test -d /usr/local/php-fastcgi

php-fpm:
  file.managed:
    - name: /usr/local/php-fastcgi/etc/php-fpm.conf
    - source: salt://modules/php/files/php-fpm.conf.default
    - user: root
    - group: root
    - mode: 644

php-fastcgi-service:
  file.managed:
    - name: /etc/init.d/php-fpm
    - source: salt://modules/php/files/init.d.php-fpm
    - user: root
    - group: root
    - mode: 755
  cmd.run:
    - name: chkconfig --add php-fpm
    - unless: chkconfig --list | grep php-fpm
    - require:
      - file: php-fastcgi-service

6.5.4:执行php的install.sls状态文件:

#  salt “saltminion2*” state.sls modules.php.install   saltenv=prod

七:编写top.sls,以便通过高级状态一键执行:

7.1:编写lnmp.sls状态文件,调用之前编写的服务安装状态文件:

# cd modules

# mkdir lnmp

 #cd lnmp

# vim lnmp.sls

include:
  - modules.haproxy.install
  - modules.memcached.install
  - modules.mysql.install
  - modules.nginx.install
  - modules.php.install

7.2:编写top file,调用lnmp.sls状态文件,目的是执行高级状态让的时候可以一键安装所有以上的服务:

# vim /srv/salt/base/top.sls

base:
  "*":
    - init.init
prod: #指定环境未prod
  "saltminion*": #为所有符合条件的的minion分配的状态文件
    - modules.lnmp.lnmp #列出指定的状态文件,可以是多个

7.3:为指定的minion执行高级状态,执行成功后会在minion端自动安装nginx/memcache/mysqlphp:

# salt “saltminion2*” state.highstate

#以上可能存在小bug,需要根据实际环境进行适当修改。


Warning: count(): Parameter must be an array or an object that implements Countable in /home/nginx/wordpress/wp-includes/class-wp-comment-query.php on line 405

发表评论

邮箱地址不会被公开。 必填项已用*标注