saltstack 高级用法:常用模块和 jinja模版 (二)
# nginx sls文件 # cat nginx/install.slsinclude:
- modules.user.www
- modules.pcre.install
- modules.pkg.pkg-init
nginx-install:
file.managed:
- name: /usr/local/src/nginx-1.9.1.tar.gz
- source: salt://modules/nginx/files/nginx-1.9.1.tar.gz
- user: root
- group: root
- mode: 755
cmd.run:
- name: cd /usr/local/src && tar zxf nginx-1.9.1.tar.gz && cd nginx-1.9.1&& ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-http_dav_module --with-pcre=/usr/local/src/pcre-8.37 && make && make install && chown -R www:www /usr/local/nginx
- unless: test -d /usr/local/nginx
- require:
- file: nginx-install
- user: www-user-group
- cmd: pcre-source-install
- pkg: pkg-init
nginx-config:
file.managed:
- name: /usr/local/nginx/conf/nginx.conf
- source: salt://modules/nginx/files/nginx.conf
- user: root
- group: root
- mode: 755
- require:
- cmd: nginx-install
nginx-directory-online:
file.directory:
- name:/usr/local/nginx/conf/vhost_online
- require:
- cmd: nginx-install
nginx-directory-offline:
file.directory:
- name:/usr/local/nginx/conf/vhost_offline
- require:
- cmd: nginx-install
nginx-cmd:
file.managed:
- name: /etc/init.d/nginx
- source: salt://modules/nginx/files/nginx-init
- user: root
- group: root
- mode: 755
- require:
- cmd: nginx-install
cmd.run:
- name: chkconfig --add nginx
- unless: chkconfig --list|grep nginx
- require:
- file: nginx-directory-offline
- file: nginx-cmd
- file: nginx-config
- cmd: nginx-install
service.running:
- name: nginx
- enable: True
-> - require:
- cmd: nginx-cmd
- watch:
- file: nginx-config
# php 安装文件
# cat php/install.sls
include:
- modules.user.www
- modules.pkg.pkg-init
pkg-php:
pkg.installed:
- names:
- openssl-devel
- swig
- libjpeg-turbo
- libjpeg-turbo-devel
- libpng
- libpng-devel
- freetype
- freetype-devel
- libxml2
- libxml2-devel
- zlib
- zlib-devel
- libcurl
- libcurl-devel
php-source-install:
file.managed:
- name: /usr/local/src/php-5.6.9.tar.gz
- source: salt://modules/php/files/php-5.6.9.tar.gz
- user: root
- group: root
- mode: 755
cmd.run:
- name: cd /usr/local/src && tar zxf php-5.6.9.tar.gz && cd php-5.6.9&&./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-source-install
- user: www-user-group
- unless: test -d /usr/local/php-fastcgi
pdo-plugin:
cmd.run:
- name: cd /usr/local/src/php-5.6.9/ext/pdo_mysql/ && /usr/local/php-fastcgi/bin/phpize && ./configure --with-php-config=/usr/local/php-fastcgi/bin/php-config &&make&& make install
- unless: test -f /usr/local/php-fastcgi/lib/php/extensions/*/pdo_mysql.so
- require:
- cmd: php-source-install
php-ini:
file.managed:
- name: /usr/local/php-fastcgi/etc/php.ini
- source: salt://modules/php/files/php.ini-production
- user: root
- group: root
- mode: 644
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
service.running:
- name: php-fpm
- enable: True
-> - require:
- cmd: php-fastcgi-service
- watch:
- file: php-ini
- file: php-fpm
# cat php/php-redis.sls
redis-plugin:
file.managed:
- name: /usr/local/src/redis-2.2.7.tgz
- source: salt://modules/php/files/redis-2.2.7.tgz
- user: root
- group: root
- mode: 755
cmd.run:
- name: cd /usr/local/src && tar zxf redis-2.2.7.tgz && cd redis-2.2.7&& /usr/local/php-fastcgi/bin/phpize && ./configure --with-php-config=/usr/local/php-fastcgi/bin/php-config &&make&& make install
- unless: test -f /usr/local/php-fastcgi/lib/php/extensions/*/redis.so
require:
- file: redis-plugin
- cmd: php-install
redis-php-config:
file.append:
- name: /usr/local/php-fastcgi/etc/php.ini
- text:
- extension=redis.so
# cat php/php-memcache.sls
memcache-plugin:
file.managed:
- name: /usr/local/src/memcache-2.2.7.tgz
- source: salt://modules/php/files/memcache-2.2.7.tgz
- user: root
- group: root
- mode: 755
cmd.run:
- name: cd /usr/local/src && tar zxf memcache-2.2.7.tgz && cd memcache-2.2.7&& /usr/local/php-fastcgi/bin/phpize && ./configure --enable-memcache --with-php-config=/usr/local/php-fastcgi/bin/php-config &&make&& make install
- unless: test -f /usr/local/php-fastcgi/lib/php/extensions/*/memcache.so
require:
- file: memcache-plugin
- cmd: php-install
memcache-php-config:
file.append:
- name: /usr/local/php-fastcgi/etc/php.ini
- text:
- extension=memcache.so
# make模块
# cat pkg/pkg-init.sls
pkg-init:
pkg.installed:
- names:
- gcc
- gcc-c++
- glibc
- make
- autoconf
- openssl
- openssl-devel
# 增加www用户的模块
# cat user/www.sls
www-user-group:
group.present:
- name: www
- gid: 1000
user.present:
- name: www
- fullname: www
- shell: /sbin/nologin
- uid: 1000
- gid: 1000
#memcached 安装模块
# cat bbs/memcached.sls
include:
- modules.user.www
- modules.memcached.install
memcached-service:
cmd.run:
- name: /usr/local/memcached/bin/memcached -d -m 128 -p 11211 -c 8096 -u www
- unless: netstat -tnlpua|grep 11211
- require:
- cmd: memcached-install
- user: www-user-group
- group: www-user-group
# bbs模块
# cat bbs/web.sls
include:
- modules.nginx.install
- modules.php.install
- modules.php.php-memcache
- modules.php.php-redis
nginx-vhost-online:
file.managed:
- name: /usr/local/nginx/conf/vhost_online/nginx_bbs.conf
- source: salt://bbs/files/nginx_bbs.conf
- user: root
- group: root
- mode: 644
- require:
- cmd: nginx-install
- watch_in:
- service: nginx-cmd
nginx-test-index-html:
file.managed:
- name:/usr/local/nginx/html/index.html
- source: salt://bbs/files/index.html
- user: root
- group: root
- mode: 755
- template: jinja
- HOST: {{grains['fqdn']}}
页:
[1]