saltstack部署LNMP

saltstack部署LNMP

[root@master ~]# tree /srv/salt/prod/
/srv/salt/prod/
├── LNMP
│   ├── files
│   │   ├── index.php
│   │   ├── my.cnf
│   │   └── mysql.conf
│   ├── lnmp.sls
│   ├── mysql.sls
│   └── nginx.sls
├── modules
│   ├── application
│   │   └── php
│   │       ├── files
│   │       │   ├── index.php
│   │       │   ├── install.sh
│   │       │   ├── oniguruma-devel-6.8.2-2.el8.x86_64.rpm
│   │       │   ├── php-8.0.11.tar.xz
│   │       │   ├── php-fpm
│   │       │   ├── php-fpm.conf
│   │       │   ├── php-fpm.service
│   │       │   └── www.conf
│   │       └── install.sls
│   ├── database
│   │   └── mysql
│   │       ├── files
│   │       │   ├── install.sh
│   │       │   ├── mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
│   │       │   ├── mysqld.service.j2
│   │       │   └── mysql.server
│   │       └── install.sls
│   └── web
│       ├── apache
│       │   ├── files
│       │   │   ├── apr-1.7.0.tar.gz
│       │   │   ├── apr-util-1.6.1.tar.gz
│       │   │   ├── httpd-2.4.49.tar.gz
│       │   │   ├── httpd.conf
│       │   │   ├── httpd.service
│       │   │   └── install.sh
│       │   └── install.sls
│       └── nginx
│           ├── files
│           │   ├── install.sh
│           │   ├── nginx-1.20.1.tar.gz
│           │   ├── nginx.conf
│           │   └── nginx.service
│           └── install.sls
└── zabbix
    ├── apache.sls
    ├── files
    │   ├── index.php
    │   ├── install.sh
    │   ├── my.cnf
    │   ├── mysql.conf
    │   ├── php.ini
    │   ├── vhosts.conf
    │   ├── zabbix-5.4.4.tar.gz
    │   └── zabbix_server.conf
    ├── install.sls
    ├── lamp.sls
    └── mysql.sls

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

[root@master nginx]# cat install.sls 
nginx-dep-pkg:
  pkg.installed:
    - pkgs:
      - pcre-devel
      - openssl
      - openssl-devel
      - gd-devel
      - gcc
      - gcc-c++
      - make

nginx:
  user.present:
    - shell: /sbin/nologin
    - createhome: false
    - system: true

/usr/src/nginx-1.20.1.tar.gz:
  file.managed:
    - source: salt://modules/web/nginx/files/nginx-1.20.1.tar.gz

/usr/lib/systemd/system/nginx.service:
  file.managed:
    - source: salt://modules/web/nginx/files/nginx.service
    - user: root
    - group: root
    - mode: '0644'

salt://modules/web/nginx/files/install.sh:
  cmd.script:
    - unless: test -d /usr/local/nginx

/usr/local/nginx/conf/nginx.conf:
  file.managed:
    - source: salt://modules/web/nginx/files/nginx.conf

/srv/salt/prod/modules/web/nginx/files/install.sh

[root@master nginx]# cat files/install.sh 
#!/bin/bash

rm -rf /var/log/nginx
mkdir -p /var/log/nginx
chown -R nginx.nginx /var/log/nginx

cd /usr/src/
tar xf nginx-1.20.1.tar.gz

cd nginx-1.20.1

./configure \
        --prefix=/usr/local/nginx \
        --user=nginx \
        --group=nginx \
        --with-debug \
        --with-http_ssl_module \
        --with-http_realip_module \
        --with-http_image_filter_module \
        --with-http_gunzip_module \
        --with-http_gzip_static_module \
        --with-http_stub_status_module \
        --http-log-path=/var/log/nginx/access.log \
        --error-log-path=/var/log/nginx/error.log && \
        make && make install

systemctl daemon-reload

/srv/salt/prod/modules/database/mysql/install.sls

[root@master mysql]# cat install.sls 
ncurses-compat-libs:
  pkg.installed

create-mysqluser:
  user.present:
    - name: mysql
    - system: true
    - createhome: false
    - shell: /sbin/nologin

create-datadir:
  file.directory:
    - name: /opt/data
    - user: mysql
    - group: mysql
    - mode: '0755'
    - makedirs: true

/usr/src/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz:
  file.managed:
    - source: salt://modules/database/mysql/files/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
    - user: root
    - group: root
    - mode: '0644'

mysql-install:
  cmd.script:
    - name: salt://modules/database/mysql/files/install.sh
    - unless: test -d /usr/local/mysql

trasfer-files:
  file.managed:
    - names:
      - /usr/local/mysql/support-files/mysql.server:
        - source: salt://modules/database/mysql/files/mysql.server
      - /usr/lib/systemd/system/mysqld.service.j2:
        - source: salt://modules/database/mysql/files/mysqld.service
        - template: jinjia
    - require:
      - cmd: mysql-install

/srv/salt/prod/modules/database/mysql/files/install.sh

[root@master mysql]# cat files/install.sh 
#!/bin/bash

cd /usr/src/
tar xf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz -C /usr/local
ln -s /usr/local/mysql-5.7.35-linux-glibc2.12-x86_64 /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql*
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/usr/local/mysql/
echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysqld.sh

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

[root@master php]# cat install.sls 
/usr/src/oniguruma-devel-6.8.2-2.el8.x86_64.rpm:
  file.managed:
    - source: salt://modules/application/php/files/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
    - user: root
    - group: root
    - mode: '0644'
  cmd.run:
    - name: yum -y install /usr/src/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
    - unless: rqm -q oniguruma-devel

dep-pkg-install:
  pkg.installed:
    - pkgs:
      - libxml2
      - libxml2-devel
      - openssl
      - openssl-devel
      - bzip2
      - bzip2-devel
      - libcurl
      - libcurl-devel
      - libicu-devel
      - libjpeg-turbo
      - libjpeg-turbo-devel
      - libpng
      - libpng-devel
      - openldap-devel
      - pcre-devel
      - freetype 
      - freetype-devel
      - gmp
      - gmp-devel
      - libmcrypt 
      - libmcrypt-devel
      - readline
      - readline-devel
      - libxslt
      - libxslt-devel
      - mhash
      - mhash-devel
      - php-mysqlnd
      - libsqlite3x
      - libsqlite3x-devel 
      - oniguruma
      - libzip-devel
      - make 

/usr/src/php-8.0.11.tar.xz:
  file.managed:
    - source: salt://modules/application/php/files/php-8.0.11.tar.xz
    - user: root
    - group: root
    - mode: '0644'

php-install:
  cmd.script:
    - name: salt://modules/application/php/files/install.sh
    - unless: test -d /usr/local/php8

copysoft:
  file.managed:
    - names:
      - /etc/init.d/php-fpm:
        - source: salt://modules/application/php/files/php-fpm
        - user: root
        - group: root
        - mode: '0755'
      - /usr/local/php8/etc/php-fpm.conf:
        - source: salt://modules/application/php/files/php-fpm.conf
      - /usr/local/php8/etc/php-fpm.d/www.conf:
        - source: salt://modules/application/php/files/www.conf
      - /usr/lib/systemd/system/php-fpm.service:
        - source: salt://modules/application/php/files/php-fpm.service
    - require:
      - cmd: php-install

php-fpm.service:
  service.running:
    - enable: true
    - reload: true
    - require:
      - cmd: php-install
      - file: copysoft
    - watch:
      - file: copysoft

/srv/salt/prod/modules/application/php/files/install.sh

[root@master php]# cat files/install.sh 
#!/bin/bash

cd /usr/src
rm -rf php-8.0.11
tar xf php-8.0.11.tar.xz
cd php-8.0.11
./configure --prefix=/usr/local/php8  \
        --with-config-file-path=/etc \
        --enable-fpm \
        --enable-inline-optimization \
        --disable-debug \
        --disable-rpath \
        --enable-shared \
        --enable-soap \
        --with-openssl \
        --enable-bcmath \
        --with-iconv \
        --with-bz2 \
        --enable-calendar \
        --with-curl \
        --enable-exif  \
        --enable-ftp \
        --with-gd \
        --with-jpeg-dir \
        --with-png-dir \
        --with-zlib-dir \
        --with-freetype-dir \
        --with-gettext \
        --enable-json \
        --enable-mbstring \
        --enable-pdo \
        --with-mysqli=mysqlnd \
        --with-pdo-mysql=mysqlnd \
        --with-readline \
        --enable-shmop \
        --enable-simplexml \
        --enable-sockets \
        --enable-zip \
        --enable-mysqlnd-compression-support \
        --with-pear \
        --enable-pcntl \
        --enable-posix  && \
        make && make install

/srv/salt/prod/LNMP/nginx.sls

[root@master LNMP]# cat nginx.sls 
"Development Tools":
  pkg.group_installed

include:
  - modules.web.nginx.install

/usr/local/nginx/html/index.php:
  file.managed:
    - source: salt://LNMP/files/index.php
    - user: root
    - group: root
    - mode: '0644'
    - require:
      - cmd: salt://modules/web/nginx/files/install.sh

nginx-service:
  service.running:
    - name: nginx
    - enable: true
    - reload: true
    - require:
      - file: /usr/local/nginx/conf/nginx.conf
    - watch:
      - file: /usr/local/nginx/conf/nginx.conf

/srv/salt/prod/LNMP/mysql.sls

[root@master LNMP]# cat mysql.sls 
lamp-dep-pkg:
  pkg.installed:
    - pkgs:
      - ncurses-devel
      - openssl-devel
      - openssl
      - cmake  
      - mariadb-devel

include:
  - modules.database.mysql.install

provides-mysql-file:
  file.managed:
    - user: root
    - group: root
    - mode: '0644'
    - names: 
      - /etc/my.cnf:
        - source: salt://LNMP/files/my.cnf
      - /etc/ld.so.conf.d/mysql.conf:
        - source: salt://LNMP/files/mysql.conf

/usr/local/include/mysql:
  file.symlink:
    - target: /usr/local/mysql/include

mysqld.service:
  service.running:
    - enable: true
    - reload: true
    - require:
      - cmd: mysql-install
      - file: trasfer-files
    - watch:
      - file: provides-mysql-file

mysql-set-password:
  cmd.run:
    - name: /usr/local/mysql/bin/mysql -e "set password = password('1');"
    - require:
      - service: mysqld.service
    - unlesss: /usr/local/mysql/bin/mysql -uroot -p123456 -e "exit"

/srv/salt/prod/LNMP/lnmp.sls

[root@master LNMP]# cat lnmp.sls 
include:
  - LNMP.nginx
  - LNMP.mysql
  - modules.application.php.install

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值