saltstack源码编译安装lnmp

来源:互联网 发布:js求数组最大值 编辑:程序博客网 时间:2024/05/16 06:53

环境

master:server1(172.25.50.1/24)
minion:server2(172.25.50.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.gznginx-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: rootnginx-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.rpmlib-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: rootphp-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.rpmcmake-install:  cmd.run:    - name: cd /mnt && yum install cmake-2.8.12.2-4.el6.x86_64.rpm -ynginx-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: rootmysql-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 -Rmysql-service:  service.running:    - name: mysql    - enable: True    - reload: True    - watch:      - file: /etc/my.cnf    - requires:      - file: /etc/init.d/mysqld      - cmd: mysql-install
原创粉丝点击