satlstack 部署lnmp
目录
/srv/salt/base/
[root@master ~]# tree /srv/salt/base/
/srv/salt/base/
├── lnmp
│ └── mian.sls
└── modules
├── application
│ └── php
│ ├── file
│ │ ├── install.sh
│ │ ├── oniguruma-devel-6.8.2-2.el8.x86_64.rpm
│ │ ├── php-7.4.25.tar.gz
│ │ ├── php-8.0.10.tar.gz
│ │ ├── php-fpm
│ │ ├── php-fpm.conf
│ │ ├── php-fpm.service.j2
│ │ └── www.conf
│ └── install.sls
├── database
│ └── mysql
│ ├── file
│ │ ├── install.sh
│ │ ├── my.cnf.j2
│ │ ├── mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
│ │ ├── mysql.conf
│ │ ├── mysqld.service.j2
│ │ └── mysql.server
│ └── install.sls
└── web
├── apache
│ ├── file
│ │ ├── apr-1.7.0.tar.gz
│ │ ├── apr-util-1.6.1.tar.gz
│ │ ├── httpd-2.4.48.tar.gz
│ │ ├── httpd.conf
│ │ ├── httpd.service
│ │ ├── index.php
│ │ └── install.sh
│ └── install.sls
└── nginx
├── file
│ ├── index.php
│ ├── install.sh
│ ├── nginx-1.20.1.tar.gz
│ └── nginx.conf.j2
└── install.sls
nginx
/srv/salt/base/modules/web/nginx/install.sls
[root@master ~]# cat /srv/salt/base/modules/web/nginx/install.sls
nginx-pkg:
pkg.installed:
- pkgs:
- pcre-devel
- openssl
- openssl-devel
- gd-devel
- gcc
- gcc-c++
- make
nginx-user:
user.present:
- name: nginx
- shell: /sbin/nologin
- system: true
- createhome: false
nginx-download:
file.managed:
- names:
- /usr/src/nginx-1.20.1.tar.gz:
- source: salt://modules/web/nginx/file/nginx-1.20.1.tar.gz
nginx-loglib:
file.directory:
- name: /var/log/nginx
- user: nginx
- group: nginx
- mode: '0755'
- makedirs: true
nginx-install:
cmd.script:
- name: salt://modules/web/nginx/file/install.sh
- unless: tese -d /usr/local/nginx
nginx-conf:
file.managed:
- names:
- /usr/local/nginx/conf/nginx.conf:
- source: salt://modules/web/nginx/files/nginx.conf.j2
- user: root
- group: root
- mode: '0644'
- template: jinja
- require:
- cmd: nginx-install
/srv/salt/base/modules/web/nginx/file/install.sh
[root@master ~]# cat /srv/salt/base/modules/web/nginx/file/install.sh
#! /bin/bash
cd /usr/src/
rm -rf /usr/local/nginx-1.20.1
tar xf nginx-1.20.1.tar.gz
cd /usr/src/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
echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
mysql
/srv/salt/base/modules/database/mysql/install.sls
[root@master ~]# cat /srv/salt/base/modules/database/mysql/install.sls
mysql-pkg:
pkg.installed:
- pkgs:
- ncurses-devel
- openssl-devel
- openssl
- cmake
- mariadb-devel
- ncurses-compat-libs
mysql-user:
user.present:
- name: mysql
- shell: /sbin/nologin
- createhome: false
- system: true
mysql-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/file/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
- user: mysql
- group: mysql
- mode: '0644'
mysql-install:
cmd.script:
- name: salt://modules/database/mysql/file/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/file/mysql.server
- /usr/lib/systemd/system/mysqld.service:
- source: salt://modules/database/mysql/file/mysqld.service.j2
- template: jinja
- require:
- cmd: mysql-install
/srv/salt/base/modules/database/mysql/file/install.sh
[root@master ~]# cat /srv/salt/base/modules/database/mysql/file/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
$1/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data/
echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
php
/srv/salt/base/modules/application/php/install.sls
[root@master ~]# cat /srv/salt/base/modules/application/php/install.sls
/usr/src/oniguruma-devel-6.8.2-2.el8.x86_64.rpm:
file.managed:
- source: salt://modules/application/php/file/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: rpm -q oniguruma-devel
php-pkg-install:
pkg.installed:
- pkgs:
- libxml2
- libxml2-devel
- bzip2
- openssl
- openssl-devel
- bzip2-devel
- libcurl
- libcurl-devel
- libicu-devel
- libjpeg
- libjpeg-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-devel
- oniguruma
- libzip-devel
/usr/src/php-7.4.25.tar.gz:
file.managed:
- source: salt://modules/application/php/file/php-7.4.25.tar.gz
- user: root
- group: root
- mode: '0644'
php-install:
cmd.script:
- name: salt://modules/application/php/file/install.sh
- unless: test -d /usr/local/php7
copysoft:
file.managed:
- names:
- /etc/init.d/php-fpm:
- source: salt://modules/application/php/file/php-fpm
- user: root
- group: root
- mode: '0755'
- /usr/local/php7/etc/php-fpm.conf:
- source: salt://modules/application/php/file/php-fpm.conf
- /usr/local/php7/etc/php-fpm.d/www.conf:
- source: salt://modules/application/php/file/www.conf
- /usr/lib/systemd/system/php-fpm.service:
- source: salt://modules/application/php/file/php-fpm.service.j2
- template: jinja
- require:
- cmd: php-install
/srv/salt/base/modules/application/php/file/install.sh
[root@master ~]# cat /srv/salt/base/modules/application/php/file/install.sh
#! /bin/bash
cd /usr/src/
rm -rf php-7.4.25
tar xf php-7.4.25.tar.gz
cd php-7.4.25
./configure --prefix=/usr/local/php7 --with-config-file-path=/etc --enable-fpm --disable-debug --disable-rpath --enable-shared --enable-soap --with-openssl --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --enable-gd --with-jpeg --with-zlib-dir --with-freetype --with-gettext --enable-mbstring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-simplexml --enable-sockets --with-zip --enable-mysqlnd-compression-support --with-pear --enable-pcntl --enable-posix && make && make install
/srv/salt/base/lnmp/mian.sls
[root@master ~]# cat /srv/salt/base/lnmp/mian.sls
include:
- modules.web.nginx.install
- modules.database.mysql.install
- modules.application.php.install
nginx-start:
cmd.run:
- name: nginx -s reload
- require:
- file: nginx-conf
- watch:
- file: nginx-conf
test-index.php:
file.managed:
- names:
- /usr/local/nginx/html/index.php:
- source: salt://modules/web/nginx/file/index.php
- user: nginx
- group: nginx
- mode: '0644'
provides-mysql-file:
file.managed:
- user: root
- group: root
- mode: '0644'
- names:
- /etc/my.cnf:
- source: salt://modules/database/mysql/file/my.cnf
- /etc/ld.so.conf.d/mysql.conf:
- source: salt://modules/database/mysql/file/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
mysqld-set-password:
cmd.run:
- name: /usr/local/mysql/bin/mysql -e "set password = password('xu1');"
- require:
- service: mysqld.service
- unless: /usr/local/mysql/bin/mysql -uroot -pxu1 -e "exit"
php-fpm.service:
service.running:
- enable: true
- restart: true
- require:
- cmd: php-install
- file: copy-php
- watch:
- file: copy-php
执行
salt '*' state.sls lnmp.mian