博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SaltStack项目实战(七)
阅读量:6794 次
发布时间:2019-06-26

本文共 9006 字,大约阅读时间需要 30 分钟。

上文 

四、memcached

1)创建www用户

mkdir -p /srv/salt/prod/modules/uservi /srv/salt/prod/modules/user/www.slswww-user-group:  group.present:    - name: www    - gid: 1000  user.present:    - name: www    - fullname: www    - shell: /sbin/nologin    - uid: 1000    - gid: 1000

2)libevent,将安装包放入/srv/salt/prod/modules/libevent/files

mkdir -p /srv/salt/prod/modules/libevent/filesvi /srv/salt/prod/modules/libevent/install.slslibevent-source-install:  file.managed:    - name: /usr/local/src/libevent-2.0.22-stable.tar.gz    - source: salt://modules/libevent/files/libevent-2.0.22-stable.tar.gz    - user: root    - group: root    - mode: 644  cmd.run:    - name: cd /usr/local/src && tar zxf libevent-2.0.22-stable.tar.gz && cd libevent-2.0.22-stable &&  ./configure --prefix=/usr/local/libevent && make && make install    - unless: test -d /usr/local/libevent    - require:      - file: libevent-source-install

3)创建files目录,将memcached-1.4.24.tar.gz安装包放入

mkdir -p /srv/salt/prod/modules/memcached/files

4)创建install.sls文件

vi /srv/salt/prod/modules/memcached/install.slsinclude:  - modules.libevent.installmemcached-source-install:  file.managed:    - name: /usr/local/src/memcached-1.4.24.tar.gz    - source: salt://modules/memcached/files/memcached-1.4.24.tar.gz    - user: root    - group: root    - mode: 644  cmd.run:    - name: cd /usr/local/src && tar zxf memcached-1.4.24.tar.gz && cd memcached-1.4.24&& ./configure --prefix=/usr/local/memcached --enable-64bit --with-libevent=/usr/local/libevent && make && make install    - unless: test -d /usr/local/memcached    - require:      - cmd: libevent-source-install      - file: memcached-source-install

5)负责业务部分的放入一个目录,如bbs

mkdir -p /srv/salt/prod/bbsvi /srv/salt/prod/bbs/memcached.slsinclude:  - modules.memcached.install  - modules.user.wwwmemcached-service:  cmd.run:    - name: /usr/local/memcached/bin/memcached -d -m 128 -p 11211 -c 8096 -u www    - unless: netstat -ntlp | grep 11211    - require:      - cmd: memcached-source-install      - user: www-user-group

6)将memcached加入top FILE

vi /srv/salt/base/top.slsbase:  '*':    - init.initprod:  'linux-node*':    - cluster.haproxy-outside    - cluster.haproxy-outside-keepalived  'linux-node2*':    - bbs.memcached

测试 salt "*" state.highstate test=True

执行 salt "*" state.highstate

 

五、php

1)php安装包和相关文件放入/srv/salt/prod/modules/php/files

mkdir -p /srv/salt/prod/modules/php/files

2)创建install.sls

vi /srv/salt/prod/modules/php/install.sls

include:   - modules.pkg.make  - modules.user.wwwpkg-php:  pkg.installed:    - names:      - swig      - libjpeg-turbo      - libjpeg-turbo-devel      - libpng      - libpng-devel      - freetype      - freetype-devel      - libxml2      - libxml2-devel      - zlib      - zlib-devel      - libcurl      - libcurl-develphp-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-fastcgipdo-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-installphp-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: 644php-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

创建php-memcache.sls

vi /srv/salt/prod/modules/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

创建php-redis.sls

vi /srv/salt/prod/modules/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

执行命令:salt '*' state.sls modules.php.install saltenv=prod

 

六、nginx

1)nginx安装包和相关文件放入/srv/salt/prod/modules/nginx/files

mkdir -p /srv/salt/prod/modules/nginx/files

 

2)创建install.sls

vi /srv/salt/prod/modules/nginx/install.sls

include:  - modules.pkg.make  - modules.user.wwwnginx-source-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 && make && make install && chown -R www:www /usr/local/nginx    - unless: test -d /usr/local/nginx    - require:      - user: www-user-group      - file: nginx-source-install      - pkg: make-pkg

创建service.sls

vi /srv/salt/prod/modules/nginx/service.sls

include:  - modules.nginx.installnginx-init:  file.managed:    - name: /etc/init.d/nginx    - source: salt://modules/nginx/files/nginx-init    - mode: 755    - user: root    - group: root  cmd.run:    - name: chkconfig --add nginx    - unless: chkconfig --list | grep nginx    - require:      - file: nginx-init/usr/local/nginx/conf/nginx.conf:  file.managed:    - source: salt://modules/nginx/files/nginx.conf    - user: www    - group: www    - mode: 644 nginx-service:  service.running:    - name: nginx    - enable: True    - reload: True    - require:      - cmd: nginx-init    - watch:      - file: /usr/local/nginx/conf/nginx.conf      - file: nginx-onlinenginx-online:  file.directory:    - name: /usr/local/nginx/conf/vhost_onlinenginx-offline:  file.directory:    - name: /usr/local/nginx/conf/vhost_offline

执行命令:salt '*' state.sls modules.nginx.install saltenv=prod

4)/srv/salt/prod/bbs/files/nginx-bbs.conf

server {        listen         8080;        root /usr/local/nginx/html;        index index.htm index.html index.php;        location ~ \.php$            {              fastcgi_pass unix:/usr/local/php-fastcgi/php-fpm.sock;              fastcgi_index index.php;              include fastcgi.conf;        } }

5)/srv/salt/prod/bbs目录下创建web.sls

include:  - modules.php.install  - modules.php.php-memcache  - modules.php.php-redis  - modules.nginx.servicebbs-php:  file.managed:    - name: /usr/local/php-fastcgi/etc/php.ini    - source: salt://bbs/files/php.ini-production    - user: root    - group: root    - mode: 644  service.running:    - name: php-fpm    - enable: True    - require:      - cmd: php-fastcgi-service    - watch:      - file: bbs-phpweb-bbs:  file.managed:    - name: /usr/local/nginx/conf/vhost_online/bbs.conf    - source: salt://bbs/files/nginx-bbs.conf    - user: root    - group: root    - mode: 644    - require:      - service: bbs-php    - watch_in:      - service: nginx-service

执行命令:salt '*' state.sls bbs.web saltenv=prod

6)将php、nginx加入top FILE

vi /srv/salt/base/top.sls

base:  '*':    - init.initprod:  'linux-node*':    - cluster.haproxy-outside    - cluster.haproxy-outside-keepalived    - bbs.web  'linux-node2*':    - bbs.memcached

测试 salt "*" state.highstate test=True

执行 salt "*" state.highstate

 

转载地址:http://lyrgo.baihongyu.com/

你可能感兴趣的文章
时间戳格式化
查看>>
我的友情链接
查看>>
Tablacus Script Control 64
查看>>
Vim for C Programmers
查看>>
第六章 嫉妒、欺骗、背叛
查看>>
【未解决】js对象字面量、eval()方法
查看>>
安装php加速器Zend guard loader出现无法加载,没有找到php5.dll 的错误
查看>>
关于OpenCV 3.1的搭建使用经验
查看>>
唯品会的订单分库分表实践总结以及关键步骤
查看>>
solaris 开启ftp服务 通过xftp登陆ftp服务器
查看>>
explorer.exe
查看>>
maven 发布项目到docker
查看>>
我的友情链接
查看>>
sed 详细用法
查看>>
保护你的/wp-admin/文件夹
查看>>
tk.mapper 通用 mapper 动态表名查询
查看>>
12个优秀的国外Material Design网站案例
查看>>
MYSQL添加用户、建表、权限
查看>>
java之抽象类
查看>>
[2]工欲善其事必先利其器-------UML中的几种常见关系(二)
查看>>