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

1 Nginx状态文件

[root@master web]# tree nginx/
nginx/
├── files
│   ├── install.sh
│   ├── my.cnf
│   ├── mysql.conf
│   ├── nginx-1.20.1.tar.gz
│   ├── nginx.conf
│   └── nginx.service
└── install.sls

[root@master web]# cat nginx/install.sls 
install-epel:
  cmd.run:
    - name: yum -y install epel-release
    - unless: rpm -q epel-release-8-11.el8.noarch

"Development Tools":
  pkg.group_installed

nginx-dep-package:
  pkg.installed:
    - pkgs:
      - pcre-devel 
      - openssl 
      - openssl-devel 
      - gd-devel 
      - gcc 
      - gcc-c++ 
      - make

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

/var/log/nginx:
  file.directory:
    - user: root
    - group: root
    - mkdor: '0644'
    - makedirs: true

/usr/src/nginx-1.20.1.tar.gz:
  file.managed:
    - source: salt://modules/web/nginx/files/nginx-1.20.1.tar.gz
    - user: root
    - group: root
    - mode: '0644'

compile-nginx:
  cmd.script:
    - name: install.sh
    - source: salt://modules/web/nginx/files/install.sh
    - unless: test -d /usr/local/nginx    
    - require:
      - file: /usr/src/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'

nginx-service:
  service.running:
    - name: nginx
    - require:
      - cmd: compile-nginx

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

cd /usr/src
rm -rf nginx-1.20.1
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

2 mysql状态文件

[root@master database]# tree mysql/
mysql/
├── files
│   ├── install.sh
│   ├── mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
│   ├── mysqld.service
│   └── mysql.server
└── install.sls


[root@master database]# cat mysql/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=/opt/data/

echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh

sed -ri "s#^(basedir=).*#\1/usr/local/mysql#g" /usr/local/mysql/support-files/mysql.server
sed -ri "s#^(datadir=).*#\1/opt/data#g" /usr/local/mysql/support-files/mysql.server


3 php状态文件

[root@master prod]# cat lnmp/php.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: rpm -q oniguruma-devel-6.8.2-2.el8.x86_64.rpm

dep-package-install:
  pkg.installed:
    - pkgs:
      - libxml2 
      - libxml2-devel 
      - openssl 
      - openssl-devel 
      - bzip2 
      - bzip2-devel 
      - libcurl 
      - libcurl-devel 
      - libicu-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
      - libzip-devel
      - libsqlite3x-devel

/usr/src/php-7.4.24.tar.xz:
  file.managed:
    - source: salt://modules/application/php/files/php-7.4.24.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
    - require:
      - file: /usr/src/php-7.4.24.tar.xz

copy-php:
  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: copy-php
    - watch:
      - file: copy-php

4 部署Lnmp的状态文件

[root@master prod]# tree lnmp/
lnmp/
├── files
│   ├── index.php
│   ├── my.cnf
│   ├── mysql.conf
│   └── nginx.conf
├── main.sls
├── mysql.sls
├── nginx.sls
└── php.sls

[root@master prod]# cat lnmp/main.sls 
include:
  - lnmp.nginx
  - lnmp.mysql
  - lnmp.php



[root@master prod]# cat lnmp/nginx.sls 
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: compile-nginx

/usr/local/nginx/conf/nginx.conf:
  file.managed:
    - source: salt://lnmp/files/nginx.conf
    - user: root
    - group: root
    - mode: '0644'
    - require:
      - cmd: compile-nginx

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


[root@master prod]# cat lnmp/mysql.sls 
lamp-dep-package:
  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
    - require:
      - cmd: mysql-install

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

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

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

在这里插入图片描述

  系统运维 最新文章
配置小型公司网络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:01:46 
 
开发: 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:46:17-

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