saltstack源码编译安装lnmp

环境

redhat 6.5
master:server1(172.25.60.1/24)
minion:server2(172.25.60.2/24)
selinux=disabled
iptables=off

master :/etc/salt/master

 file_roots:
   base:
     - /srv/salt/

minion:/etc/salt/minion

master: server1

总体架构

/srv/salt/

|-- mysql
|   |-- files
|   |   |-- cmake-2.8.12.2-4.el6.x86_64.rpm
|   |   |-- my.cnf
|   |   |-- mysql-boost-5.7.17.tar.gz
|   |   `-- mysql.init
|   |-- install.sls
|   `-- service.sls
|-- nginx
|   |-- files
|   |   |-- nginx-1.12.0.tar.gz
|   |   |-- nginx.conf
|   |   `-- nginx.init
|   |-- install.sls
|   `-- service.sls
|-- php
|   |-- files
|   |   |-- libmcrypt-2.5.8-9.el6.x86_64.rpm
|   |   |-- libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
|   |   |-- php-5.6.20.tar.bz2
|   |   |-- php-fpm.conf
|   |   |-- php-fpm.init
|   |   `-- php.ini
|   |-- install.sls
|   `-- service.sls
|-- pkgs
|   |-- make.sls
|   |-- mysqlmake.sls
|   `-- phpmake.sls
|-- top.sls
`-- users
    |-- mysql.sls
    `-- nginx.sls

pkgs依赖性包的配置

/srv/salt/pkgs
这里写图片描述

nginx的依赖包
/srv/salt/pkgs/make.sls

make:
  pkg.installed:
    - pkgs:
      - gcc
      - openssl-devel
      - pcre-devel

mysql的依赖性包
/srv/salt/pkgs/mysqlmake.sls

mysqlmake:
  pkg.installed:
    - pkgs:
      - gcc
      - openssl-devel
      - pcre-devel
      - gcc-c++
      - ncurses-devel

php的依赖性包
/srv/salt/pkgs/phpmake.sls

phpmake:
  pkg.installed:
    - pkgs:
      - gcc
      - openssl-devel
      - pcre-devel
      - libxml2-devel
      - curl-devel
      - libjpeg-turbo-devel
      - freetype-devel
      - gmp-devel
      - net-snmp-devel
      - bison
      - libpng-devel

users用户的配置

这里写图片描述

mysql用户配置:
/srv/users/mysql.sls

mysql:
  user.present:
    - uid: 27
    - shell: /sbin/nologin
    - createhome: False
    - home: /usr/local/lnmp/mysql

  cmd.run:
    - name : sed -i 's/mysql:x:27:27::\/usr\/local\/lnmp\/mysql\/:\/sbin\/nologin/mysql:x:27:27::\/usr\/local\/lnmp\/mysql\/data:\/sbin\/nologin/g' /etc/passwd

nginx用户配置:
/srv/users/nginx.sls

nginx:
  user.present:
    - uid: 800
    - shell: /sbin/nologin
    - createhome: False
    - home: /usr/local/nginx

nginx

这里写图片描述

##nginx的安装
/srv/salt/nginx/install.sls

include:
  - pkgs.make
  - users.nginx

/mnt/nginx-1.12.0.tar.gz:
  file.managed:
    - source: salt://nginx/files/nginx-1.12.0.tar.gz

nginx-install:
  cmd.run:
    - name: cd /mnt && tar zxf nginx-1.12.0.tar.gz && cd nginx-1.12.0 && sed -i.bak 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g/g' auto/cc/gcc && ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module && make && make install
    - creates: /usr/local/nginx
    - require:
      - pkg: make
      - user: nginx
      - file: /mnt/nginx-1.12.0.tar.gz

##nginx的服务配置
/srv/salt/nginx/service.sls

include:
  - nginx.install

/etc/init.d/nginx:
  file.managed:
    - source: salt://nginx/files/nginx.init
    - mode: 755

/usr/local/nginx/conf/nginx.conf:
  file.managed:
    - source: salt://nginx/files/nginx.conf
    - mode: 644
    - user: root

nginx-service:
  service.running:
    - name: nginx
    - enable: True
    - reload: True
    - watch:
      - file: /usr/local/nginx/conf/nginx.conf
    - requires:
      - file: /etc/init.d/nginx
      - cmd: nginx-install 

PHP

php配置安装结构

这里写图片描述

##php的安装
/srv/salt/php/install.sls

include:
  - pkgs.phpmake

/mnt/php-5.6.20.tar.bz2:
  file.managed:
    - source: salt://php/files/php-5.6.20.tar.bz2

/mnt/libmcrypt-2.5.8-9.el6.x86_64.rpm:
  file.managed:
    - source: salt://php/files/libmcrypt-2.5.8-9.el6.x86_64.rpm

/mnt/libmcrypt-devel-2.5.8-9.el6.x86_64.rpm:
  file.managed:
    - source: salt://php/files/libmcrypt-devel-2.5.8-9.el6.x86_64.rpm

lib-install:
  cmd.run:
    - name: cd /mnt && yum install libmcrypt-*

php-install:
  cmd.run:
    - name: cd /mnt && tar jxf php-5.6.20.tar.bz2 && cd php-5.6.20 && ./configure --prefix=/usr/local/lnmp/php  --with-config-file-path=/usr/local/lnmp/php/etc   --with-mysql=mysqlnd  --with-mysqli=mysqlnd  --with-pdo-mysql=mysqlnd  --with-openssl  --with-snmp  --with-zlib  --with-gd  --with-libxml-dir  --with-curl --with-png-dir  --with-jpeg-dir  --with-freetype-dir  --with-gmp --with-gettext  --enable-inline-optimization  --enable-soap  --enable-ftp  --enable-sockets  --enable-mbstring  --enable-fpm  --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash && make && make install && echo "PATH=$PATH:/usr/local/lnmp/php" >> /root/.bash_profile && source /root/.bash_profile
    - creates: /usr/local/lnmp/php
    - require:
      - pkg: phpmake
      - file: /mnt/php-5.6.20.tar.bz2

##php服务设置
/srv/salt/php/service.sls

include:
  - php.install

/etc/init.d/php-fpm:
  file.managed:
    - source: salt://php/files/php-fpm.init
    - mode: 755
    - user: root

/usr/local/lnmp/php/etc/php.ini:
  file.managed:
    - source: salt://php/files/php.ini
    - mode: 644
    - user: root

/usr/local/lnmp/php/etc/php-fpm.conf:
  file.managed:
    - source: salt://php/files/php-fpm.conf
    - mode: 644
    - user: root

php-service:
  cmd.run:
    - names:
      - /sbin/chkconfig --add php-fpm
#      - /sbin/chkconfig --level 36 php-fpm on
      - /etc/init.d/php-fpm restart

mysql

这里写图片描述

##mysql的安装
/srv/salt/mysql/install.sls

include:
  - pkgs.mysqlmake
  - users.mysql

/mnt/mysql-boost-5.7.17.tar.gz:
  file.managed:
    - source: salt://mysql/files/mysql-boost-5.7.17.tar.gz

/mnt/cmake-2.8.12.2-4.el6.x86_64.rpm:
  file.managed:
    - source: salt://mysql/files/cmake-2.8.12.2-4.el6.x86_64.rpm

cmake-install:
  cmd.run:
    - name: cd /mnt && yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y

nginx-install:
  cmd.run:
    - name: cd /mnt && tar zxf mysql-boost-5.7.17.tar.gz && cd mysql-5.7.17 && cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0 && make && make install && echo "PATH=$PATH:/usr/local/lnmp/mysql/bin" >> /root/.bash_profile  && source /root/.bash_profile
    - creates: /usr/local/lnmp/mysql
    - require:
      - pkg: mysqlmake
      - user: mysql
      - file: /mnt/mysql-boost-5.7.17.tar.gz

/srv/salt/mysql/service.sls

include:
  - mysql.install

/etc/init.d/mysqld:
  file.managed:
    - source: salt://mysql/files/mysql.init
    - mode: 755

/etc/my.cnf:
  file.managed:
    - source: salt://mysql/files/my.cnf
    - mode: 644
    - user: root

mysql-boot:
  cmd.run:
    - names:
      - mysqld --initialize --user=mysql > /mnt/pass
      - cat /mnt/pass | grep root@localhost | awk '{print $11}' > /mnt/password
      - chown mysql.root /usr/local/lnmp/mysql/data -R

mysql-service:
  service.running:
    - name: mysql
    - enable: True
    - reload: True
    - watch:
      - file: /etc/my.cnf
    - requires:
      - file: /etc/init.d/mysqld
      - cmd: mysql-install
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值