IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> saltstack部署lnmp -> 正文阅读

[系统运维]saltstack部署lnmp

saltstack部署lnmp()

变量目录

[root@master ~]# cd /srv
[root@master srv]# ls
pillar  salt
[root@master srv]# tree pillar/
pillar/
├── base
│   ├── apache.sls
│   └── top.sls
└── prod         
    ├── mysql.sls
    ├── nginx.sls
    ├── php.sls
    └── top.sls

2 directories, 6 files
[root@master srv]# 

变量查看

[root@master srv]# cat pillar/prod/mysql.sls 
mysql_installdir: /usr/local
mysql_password: 123456
[root@master srv]# cat pillar/prod/nginx.sls 
nginx_installdir: /usr/local
[root@master srv]# cat pillar/prod/php.sls 
php_installdir: /usr/local
[root@master srv]# cat pillar/prod/top.sls 
prod:
  'minion':
    - nginx
    - mysql
    - php
[root@master srv]# 

文件目录

[root@master prod]# tree modules/
modules/
├── application
│   └── php
│       ├── files
│       │   ├── index.php
│       │   ├── install.sh
│       │   ├── oniguruma-devel-6.8.2-2.el8.x86_64.rpm
│       │   ├── php-8.0.10.tar.gz
│       │   ├── php-fpm
│       │   ├── php-fpm.conf
│       │   ├── php-fpm.service
│       │   └── www.conf
│       └── install.sls
├── database
│   └── mysql
│       ├── files
│       │   ├── install.sh
│       │   ├── mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
│       │   ├── mysqld.service.j2
│       │   └── mysql.server
│       └── install.sls
└── web
    ├── httpd     //忽略HTTP,因为lnmp只需要nginx
    │   ├── 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.j2
        └── install.sls

11 directories, 26 files
[root@master prod]# 

nginx

[root@master prod]# cd modules/web/nginx/
[root@master nginx]# ls
files  install.sls
[root@master nginx]# cat install.sls 
nginx-dep-package:
  pkg.installed:
    - pkgs:
      - pcre-devel
      - openssl
      - openssl-devel
      - gd-devel
      - gcc
      - gcc-c++
      - wget 
      - make 
      - ncurses-compat-libs
 

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

nginx-installsh:
  cmd.script:
    - name: salt://modules/web/nginx/files/install.sh {{ pillar['nginx_installdir'] }}
    - unless: test -d {{ pillar['nginx_installdir'] }}/nginx/


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


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


systemctl daemon-reload:
  cmd.run

 
[root@master nginx]# 

进入files查看里面得文件内容

[root@master nginx]# cd files/
[root@master files]# ls
install.sh  nginx-1.20.1.tar.gz  nginx.conf  nginx.service.j2
[root@master files]# cat install.sh 
#!/bin/bash

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

cd /usr/src/nginx-1.20.1/

./configure \
  --prefix=$1/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
[root@master files]# 

[root@master files]# cat nginx.service.j2 
[Unit]
Description=nginx server daemon
After=network.target

[Service]
Type=forking
ExecStart={{ pillar['nginx_installdir'] }}/nginx/sbin/nginx  
ExecStop={{ pillar['nginx_installdir'] }}/nginx/sbin/nginx  -s stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@master files]# 

[root@lnmp ~]# cat nginx.conf   //在配置文件里面修改一下得配置
 
        location ~ \.php$ {         //取消掉这里所有得注释
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;   //这里改成 $document_root
            include        fastcgi_params;
        }
        
        
                location / {
            root   html;
            index  index.php index.html index.htm;    //这里加上index.php
        }

mysql

查看状态文件

[root@master prod]# cd modules/database/mysql/
[root@master mysql]# ls
files  install.sls
[root@master mysql]# cat install.sls 
ncurses-compat-libs:
  pkg.installed

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

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



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

mysql-installsh:
  cmd.script:
    - name: salt://modules/database/mysql/files/install.sh {{ pillar['mysql_installdir'] }}
    - unless: test -d {{ pillar['mysql_installdir'] }}/mysql

trasfer-files:
  file.managed:
    - names:
        - {{ pillar['mysql_installdir'] }}/mysql/support-files/mysql.server:
          - source: salt://modules/database/mysql/files/mysql.server
        - /usr/lib/systemd/system/mysqld.service:
          - source: salt://modules/database/mysql/files/mysqld.service.j2
[root@master mysql]# 

进入files里面去查看脚本和配置文件

[root@master mysql]# cd files/
[root@master files]# 
[root@master files]# ls
install.sh  mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz  mysqld.service.j2  mysql.server
[root@master files]# cat install.sh 
#!/bin/bash

cd /usr/src
rm -rf mysql-5.7.34-linux-glibc2.12-x86_64
tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local

ln -s /usr/local/mysql-5.7.34-linux-glibc2.12-x86_64 $1/mysql

chown -R mysql.mysql /usr/local/mysql*

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data/


[root@master files]# cat mysqld.service.j2 
[Unit]
Description=mysql server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start 
Execstop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@master files]# 
[root@minion ~]# cd /usr/local/mysql/support-files/   
[root@minion support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@minion support-files]# 

注意:mysql.server这个配置文件我们可以直接在上面这个目录下面用scp复制过去,不需要做任何更改

php

[root@master prod]# cd modules/application/php/
[root@master php]# ls
files  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: yum -y provides oniguruma-devel 

yum -y install epel-release: 
  cmd.run

php-dep-package:
  pkg.installed:
    - pkgs:
      - sqlite-devel 
      - libzip-devel 
      - 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
      - readline 
      - readline-devel 
      - libxslt 
      - libxslt-devel 
      - libzip-devel
      - libsqlite3x-devel

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

php-install.sh:
  cmd.script:
    - name: salt://modules/application/php/files/install.sh {{ pillar['php_installdir'] }}
    - unless: test -d {{ pillar['php_installdir'] }}/php8

cp-files: 
  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
       - /usr/local/nginx/html/index.php:
         - srouce: salt://modules/application/php/files/index.php

#/usr/lib/systemd/system/php-fpm.service:
#  file.managed:
#    - source: salt://modules/application/php/files/php-fpm.service
#    - user: root
#    - group: root
#    - mode: '0644'
#    - template: jinja


php-fpm.service: 
  service.running: 
    - enable: true
    - reload: true
    - require:
      - cmd: php-install.sh
      - file: cp-files
    - watch: 
      - file: cp-files
[root@master php]# 

进入files里面去

[root@master files]# ls
index.php   oniguruma-devel-6.8.2-2.el8.x86_64.rpm  php-fpm       php-fpm.service
install.sh  php-8.0.10.tar.gz                       php-fpm.conf  www.conf
[root@master files]# cat index.php 
<?php
   phpinfo();
?>


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

cd /usr/src
rm -rf php-8.0.10
tar xf php-8.0.10.tar.gz 

cd php-8.0.10
./configure --prefix=$1/php8  \
  --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
  
[root@master files]# 

[root@master files]# cat php-fpm.service 
[Unit]
Description=php-fpm server daemon
After=network.target

[Service]
Type=forking
ExecStart=/etc/init.d/php-fpm start
Execstop=/etc/init.d/php-fpm stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@master files]# 
[root@master files]# ls    //剩余得配置文件在执行主机上解压好得目录里面有,只需要scp
index.php   oniguruma-devel-6.8.2-2.el8.x86_64.rpm  php-fpm       php-fpm.service
install.sh  php-8.0.10.tar.gz                       php-fpm.conf  www.conf

编写执行文件

[root@master prod]# ls
modules  zabbix
[root@master prod]# tree zabbix/
zabbix/
├── apache.sls
├── files
│   ├── index.php   
│   ├── install.sh
│   ├── my.cnf
│   ├── mysql.conf
│   ├── vhosts.conf
│   └── zabbix-5.4.4.tar.gz   //忽略
├── lnmp.sls
├── mysql.sls
├── nginx.sls
└── zabbix.sls

1 directory, 11 files
[root@master prod]# 

apache

[root@master prod]# ls
modules  zabbix
[root@master prod]# tree zabbix/
zabbix/
├── apache.sls    //忽略
├── files
│   ├── index.php
│   ├── install.sh
│   ├── my.cnf
│   ├── mysql.conf
│   ├── vhosts.conf
│   └── zabbix-5.4.4.tar.gz
├── lnmp.sls
├── mysql.sls
├── nginx.sls
└── zabbix.sls

1 directory, 11 files
[root@master prod]# 
[root@master zabbix]# cat mysql.sls 
include:
  - modules.database.mysql.install

lamp-dep-packages: 
  pkg.installed:
    - pkgs: 
      - ncurses-devel
      - openssl-devel
      - openssl
      - cmake
      - mariadb-devel

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

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

mysqld.service: 
  service.running: 
    - enable: true

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

include:
  - modules.web.nginx.install


nginx-service: 
  service.running: 
    - name: nginx
    - enable: true
[root@master zabbix]# 

因为php没有漏掉得步骤,所以在这里不需要弄php得

[root@master files]# ls
index.php  install.sh  my.cnf  mysql.conf  vhosts.conf  zabbix-5.4.4.tar.gz
[root@master files]# cat my.cnf 
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve


[root@master files]# cat mysql.conf 
/usr/local/mysql/lib

包含所有一键部署

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

网站测试

在这里插入图片描述

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2021-11-12 19:59:45  更:2021-11-12 20:00:42 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 23:26:32-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码