基于saltstack实现LNMP部署

2024-02-20 04:48
文章标签 实现 部署 lnmp saltstack

本文主要是介绍基于saltstack实现LNMP部署,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

小述:

  • states是Saltstack系统中的配置语言,在日常运维中需要编写大量的states文件,states sls主使用YAML语言
一、实现目标
  • 在虚拟机上实现多机通过编写sls文件来全自动安装LNMP架构,并实现服务的自动启动,网站的正常运行等功能

1.环境设置

名称IP
saltstack-master192.168.85.129
saltstack-minion192.168.85.130

2.配置管理master和minion端

  • 客户端配置DNS解析等
    详细请点击

3.配置管理LAMP部署
准备模板文件等,详细内容如下

[master端]
[root@saltstack-master salt]# tree .
.
├── prod
│   ├── init
│   │   └── init.sls
│   ├── nginx
│   │   ├── files
│   │   │   ├── nginx-1.16.0.tar.gz
│   │   │   ├── nginx.conf
│   │   │   └── nginx.service
│   │   ├── install.sls
│   │   ├── service.sls
│   │   └── user.sls
│   ├── pcre
│   │   ├── files
│   │   │   └── pcre-8.39.tar.bz2
│   │   └── pcre.sls
│   ├── php
│   │   ├── files
│   │   │   ├── index.html
│   │   │   ├── php-5.6.29.tar.bz2
│   │   │   ├── php-5.6.29.tar.bz2.1
│   │   │   ├── php-5.6.29.tar.bz2.2
│   │   │   ├── php-5.6.29.tar.bz2.3
│   │   │   ├── php-fpm.conf
│   │   │   ├── php-fpm.service
│   │   │   └── php.ini
│   │   ├── install.sls
│   │   └── service.sls
│   └── web
│       ├── bbs.sls
│       ├── files
│       │   ├── bbs.conf
│       │   └── test.html
│       └── webroot.sls
└── top.sls10 directories, 24 files
[root@saltstack-master salt]# cat prod/init/init.sls 
dep-pkgs-install:pkg.installed:- names:- gcc- gcc-c++- glibc- make- bzip2- gzip- libjpeg-turbo- libjpeg-turbo-devel- libpng- libpng-devel- freetype- freetype-devel- libxml2- libxml2-devel- libcurl- libcurl-devel- libxslt-devel- openssl- openssl-devel- zlib- zlib-devel- swig
[root@saltstack-master salt]# cat prod/nginx/install.sls 
include:- init.init- pcre.pcre- nginx.usernginx-source-file:file.managed:- name: /usr/local/src/nginx-1.16.0.tar.gz- source: salt://nginx/files/nginx-1.16.0.tar.gzcmd.run:- name: cd /usr/local/src && tar -xf nginx-1.16.0.tar.gz && cd nginx-1.16.0 && ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --prefix=/usr/local/nginx --user=nginx --group=nginx --with-pcre=/usr/local/src/pcre-8.39 && make && make install- require:- user: user-group- pkg: dep-pkgs-install- cmd: pcre-install- file: nginx-source-file- unless: test -d /usr/local/nginx
[root@saltstack-master salt]# cat prod/nginx/service.sls
include:- nginx.installnginx-systemd:file.managed:- name: /lib/systemd/system/nginx.service- source: salt://nginx/files/nginx.service- user: root- group: root- mode: 755nginx-config:file.managed:- name: /usr/local/nginx/conf/nginx.conf- source: salt://nginx/files/nginx.conf- user: nginx- group: nginx- mode: 644- require:- cmd: nginx-source-filenginx-vhost-directory:file.directory:- name: /usr/local/nginx/conf/vhost- require:- cmd: nginx-source-filenginx-service:service.running:- name: nginx- enable: True- reload: True- require:- file: nginx-systemd- watch:- file: nginx-config
[root@saltstack-master salt]# cat prod/nginx/user.sls 
user-group:group.present:- name: nginx- gid: 2000user.present:- name: nginx- fullname: nginx- shell: /sbin/nologin- uid: 2000- gid: 2000
[root@saltstack-master salt]# cat prod/nginx/files/nginx.conf 
user nginx;
worker_processes auto;
error_log logs/error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 40000;events {use epoll;worker_connections 65535;
}http {include		mime.types;default_type 	application/octet-stream;sendfile 	on;tcp_nopush 	on;keepalive_timeout 20;gzip 		on;include /usr/local/nginx/conf/vhost/*.conf;server {listen 80;server_name localhost;location /nginx_status {stub_status on;access_log off;allow all;}}
}
[root@saltstack-master salt]# cat prod/nginx/files/nginx.service 
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/bin/rm -f /usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true[Install]
WantedBy=multi-user.target
[root@saltstack-master salt]# cat prod/pcre/pcre.sls 
pcre-tarfile:file.managed:- source: salt://pcre/files/pcre-8.39.tar.bz2- name: /usr/local/src/pcre-8.39.tar.bz2pcre-install:cmd.run:- name: cd /usr/local/src && tar xf pcre-8.39.tar.bz2 && tar xf pcre-8.39.tar.bz2 && cd pcre-8.39 && ./configure --prefix=/usr/local/pcre && make && make install- unless: test -d /usr/local/pcre- require:- file: pcre-tarfile[root@saltstack-master salt]# cat prod/php/install.sls 
include:- init.initphp-source-file:file.managed:- name: /usr/local/src/php-5.6.29.tar.bz2- source: salt://php/files/php-5.6.29.tar.bz2- user: root- group: root- mode: 755php-source-install:cmd.run:- name: cd /usr/local/src && tar -xf php-5.6.29.tar.bz2 && cd php-5.6.29 &&./configure --prefix=/usr/local/php --with-curl --with-
freetype-dir --with-gd --with-gettext --with-iconv-dir --with-jpeg-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysql --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --
enable-xml --enable-zip && make && make install- require:- pkg: dep-pkgs-install- file: php-source-file- unless: test -d /usr/local/php
[root@saltstack-master salt]# cat prod/php/service.sls 
include:- php.installphp-ini:file.managed:- name: /usr/local/php/lib/php.ini- source: salt://php/files/php.ini- user: root- group: root- mode: 644- require:- cmd: php-source-installphp-fpm:file.managed:- name: /usr/local/php/etc/php-fpm.conf- source: salt://php/files/php-fpm.conf- user: root- group: root- mode: 644- require:- cmd: php-source-installphp-systemd:file.managed:- name: /etc/systemd/system/php-fpm.service- source: salt://php/files/php-fpm.service- user: root- group: root- mode: 755php-service:service.running:- name: php-fpm- enable: True- reload: True- require:- file: php-systemd- watch:- file: php-ini- file: php-fpm
[root@saltstack-master salt]# cat prod/web/bbs.sls 
include:- nginx.service- php.install- web.webrootbbs-conf:file.managed:- name: /usr/local/nginx/conf/vhost/bbs.conf- source: salt://web/files/bbs.conf- require:- service: nginx-service- watch_in:- service: nginx-servicebbs-root:file.directory:- name: /webroot/bbsbbs-index:file.managed:- name: /webroot/bbs/index.php- source: salt://web/files/index.php- require:- file: bbs-root
[root@saltstack-master salt]# cat prod/web/files/bbs.conf 
server {listen 80;server_name bbs.t.com;root /webroot/bbs;index index.php index.html index.htm;location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;
}
[root@saltstack-master salt]# cat prod/web/files/test.html 
<?php
phpinfo();
?>
[root@saltstack-master salt]# cat prod/web/webroot.sls 
web-root:file.directory:- name: /webroot[root@saltstack-master salt]# cat top.sls 
prod:'saltstack-minion[1-2]':- match: pcre
- web.bbs
【minion端】

测试结果

[root@saltstack-minion1 ~]# systemctl status salt-minion.service 
● salt-minion.service - The Salt MinionLoaded: loaded (/usr/lib/systemd/system/salt-minion.service; enabled; vendor preset: disabled)Active: active (running) since Sun 2019-06-16 17:43:08 CST; 8h agoMain PID: 5710 (salt-minion)CGroup: /system.slice/salt-minion.service├─5710 /usr/bin/python /usr/bin/salt-minion└─5713 /usr/bin/python /usr/bin/salt-minion
......
[root@saltstack-minion1 ~]# ps -aux |grep nginx
root      14081  0.0  0.2 120796  2096 ?        Ss   Jun16   0:00 nginx: master process /usr/sbin/nginx
nginx     14082  0.0  0.3 121180  3128 ?        S    Jun16   0:00 nginx: worker process
二、结果

在这里插入图片描述
在这里插入图片描述

这篇关于基于saltstack实现LNMP部署的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/727094

相关文章

使用zip4j实现Java中的ZIP文件加密压缩的操作方法

《使用zip4j实现Java中的ZIP文件加密压缩的操作方法》本文介绍如何通过Maven集成zip4j1.3.2库创建带密码保护的ZIP文件,涵盖依赖配置、代码示例及加密原理,确保数据安全性,感兴趣的... 目录1. zip4j库介绍和版本1.1 zip4j库概述1.2 zip4j的版本演变1.3 zip4

MySQL 主从复制部署及验证(示例详解)

《MySQL主从复制部署及验证(示例详解)》本文介绍MySQL主从复制部署步骤及学校管理数据库创建脚本,包含表结构设计、示例数据插入和查询语句,用于验证主从同步功能,感兴趣的朋友一起看看吧... 目录mysql 主从复制部署指南部署步骤1.环境准备2. 主服务器配置3. 创建复制用户4. 获取主服务器状态5

python生成随机唯一id的几种实现方法

《python生成随机唯一id的几种实现方法》在Python中生成随机唯一ID有多种方法,根据不同的需求场景可以选择最适合的方案,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习... 目录方法 1:使用 UUID 模块(推荐)方法 2:使用 Secrets 模块(安全敏感场景)方法

Spring StateMachine实现状态机使用示例详解

《SpringStateMachine实现状态机使用示例详解》本文介绍SpringStateMachine实现状态机的步骤,包括依赖导入、枚举定义、状态转移规则配置、上下文管理及服务调用示例,重点解... 目录什么是状态机使用示例什么是状态机状态机是计算机科学中的​​核心建模工具​​,用于描述对象在其生命

Spring Boot 结合 WxJava 实现文章上传微信公众号草稿箱与群发

《SpringBoot结合WxJava实现文章上传微信公众号草稿箱与群发》本文将详细介绍如何使用SpringBoot框架结合WxJava开发工具包,实现文章上传到微信公众号草稿箱以及群发功能,... 目录一、项目环境准备1.1 开发环境1.2 微信公众号准备二、Spring Boot 项目搭建2.1 创建

IntelliJ IDEA2025创建SpringBoot项目的实现步骤

《IntelliJIDEA2025创建SpringBoot项目的实现步骤》本文主要介绍了IntelliJIDEA2025创建SpringBoot项目的实现步骤,文中通过示例代码介绍的非常详细,对大家... 目录一、创建 Spring Boot 项目1. 新建项目2. 基础配置3. 选择依赖4. 生成项目5.

golang程序打包成脚本部署到Linux系统方式

《golang程序打包成脚本部署到Linux系统方式》Golang程序通过本地编译(设置GOOS为linux生成无后缀二进制文件),上传至Linux服务器后赋权执行,使用nohup命令实现后台运行,完... 目录本地编译golang程序上传Golang二进制文件到linux服务器总结本地编译Golang程序

Linux下删除乱码文件和目录的实现方式

《Linux下删除乱码文件和目录的实现方式》:本文主要介绍Linux下删除乱码文件和目录的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux下删除乱码文件和目录方法1方法2总结Linux下删除乱码文件和目录方法1使用ls -i命令找到文件或目录

SpringBoot+EasyExcel实现自定义复杂样式导入导出

《SpringBoot+EasyExcel实现自定义复杂样式导入导出》这篇文章主要为大家详细介绍了SpringBoot如何结果EasyExcel实现自定义复杂样式导入导出功能,文中的示例代码讲解详细,... 目录安装处理自定义导出复杂场景1、列不固定,动态列2、动态下拉3、自定义锁定行/列,添加密码4、合并

mybatis执行insert返回id实现详解

《mybatis执行insert返回id实现详解》MyBatis插入操作默认返回受影响行数,需通过useGeneratedKeys+keyProperty或selectKey获取主键ID,确保主键为自... 目录 两种方式获取自增 ID:1. ​​useGeneratedKeys+keyProperty(推