当前位置:网站首页>Deploy LNMP automatically with saltstack
Deploy LNMP automatically with saltstack
2022-07-28 19:54:00 【Amu 690】
List of articles
Environmental statement :
| host | IP | service |
|---|---|---|
| master | 192.168.91.135 | salt-matser |
| node1 | 192.168.91.137 | salt-minion |
One 、 The file is displayed in tree view format
[[email protected] prod]# tree lnmp/
lnmp/
|-- files
| |-- index.php
| |-- my.cnf
| `-- nginx.conf |-- install.sls |-- mysql.sls `-- nginx.sls
1 directory, 6 files
[[email protected] prod]# tree modules/
modules/
|-- application
| `-- php | |-- files | | |-- install.sh | | |-- oniguruma-devel-6.8.2-2.el8.x86_64.rpm | | |-- php-7.4.24.tar.xz | | |-- php-fpm | | |-- php-fpm.conf | | |-- php-fpm.service | | `-- www.conf
| `-- install.sls |-- database | `-- mysql
| |-- files
| | |-- install.sh
| | |-- my.cnf
| | |-- mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
| | |-- mysql.server
| | `-- mysqld.service | `-- install.sls
`-- web |-- apache | |-- config.sls | |-- files | | |-- apr-1.7.0.tar.gz | | |-- apr-util-1.6.1.tar.gz | | |-- httpd-2.4.51.tar.gz | | |-- httpd.conf | | |-- httpd.service | | |-- index.php | | `-- install.sh
| `-- install.sls `-- nginx
|-- files
| |-- install.sh
| |-- nginx-1.20.1.tar.gz
| `-- nginx.service `-- install.sls
11 directories, 27 files
Two 、 modify master The configuration file
[[email protected] prod]# vim /etc/salt/master
# highstate format, and is generally just key/value pairs.
pillar_roots:
base:
- /srv/pillar/base
prod: // Add these two lines
- /srv/pillar/prod
#
#ext_pillar:
// Create directory
[[email protected] prod]# cd /srv/pillar/
[[email protected] pillar]# mkdir prod
[[email protected] pillar]# systemctl restart salt-master.service
// Variable storage location
[[email protected] pillar]# tree prod/
prod/
|-- mysql.sls
|-- nginx.sls
|-- php.sls
`-- top.sls
0 directories, 4 files
3、 ... and 、nginx install
[[email protected] pillar]# cd
[[email protected] ~]# cat /srv/salt/prod/modules/web/nginx/install.sls
"Development Tools:
pkg.group_installed
usradd.nginx:
user.present:
- name: nginx
- shell: /sbin/nologin
- system: true
- createhome: false
nginx-depend-packages:
pkg.installed:
- pkgs:
- pcre-devel
- openssl
- openssl-devel
- gd-devel
- gcc
- gcc-c++
copy_nginx:
file.managed:
- names:
- /usr/src/nginx-1.20.1.tar.gz
- source: salt://modules/web/nginx/files/nginx-1.20.1.tar.gz
- /usr/lib/systemd/system/nginx.service:
- source: salt://modules/web/nginx/files/nginx.service
- template: jinjia
install_nginx:
cmd.script:
- name: salt://modules/web/nginx/files/install.sh {
{
pillar['php_dir'] }}
- unless: test -d {
{
pillar['php_dir'] }}
Four 、mysql install
[[email protected] ~]# cat /srv/salt/prod/modules/database/mysql/install.sls
ncurses-compat-libs:
pkg.installed
create-mysql-user:
user.present:
- name: mysql
- system: true
- createhome: false
- shell: /sbin/nologin
create-datadir:
file.directory:
- name: /opt/data
- user: mysql
- group: mysql
- mode: '0755'
/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'
install_mysql:
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
- user: root
- group: root
- mode: '0644'
- {
{
pillar['mysql_dir'] }}/support-files/mysql.server:
- source: salt://modules/database/mysql/files/mysqld.service
- user: mysql
- group: mysql
- mode: '0755'
- template: jinja
- require:
- cmd: install_mysql
5、 ... and 、php install
[[email protected] ~]# cat /srv/salt/prod/modules/application/php/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: rpm -q oniguruma-devel
depend-package-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-devel
- libzip-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'
install_php:
cmd.script:
- name: salt://modules/application/php/files/install.sh {
{
pillar['php_dir'] }}
- unless: test -d /usr/local/php
copy_config:
file.managed:
- names:
- /etc/init.d/php-fpm:
- source: salt://modules/application/php/files/php-fpm
- user: root
- group: root
- mode: '0755'
- {
{
pillar['php_dir'] }}/etc/php-fpm.conf:
- source: salt://modules/application/php/files/php-fpm.conf
- user: root
- group: root
- mode: '0644'
- {
{
pillar['php_dir'] }}/etc/php-fpm.d/www.conf:
- source: salt://modules/application/php/files/www.conf
- user: root
- group: root
- mode: '0644'
- /usr/lib/systemd/system/php-fpm.service:
- source: salt://modules/application/php/files/php-fpm.service
- user: root
- group: root
- mode: '0644'
- require:
- cmd: install_php
php-fpm.service:
service.running:
- enable: true
- reload: true
- require:
- cmd: install_php
- file: copy_config
- watch:
- file: copy_config
6、 ... and 、 To write lnmp Deployment file for
nginx
[[email protected] ~]# cat /srv/salt/prod/lnmp/nginx.sls
include:
- modules.web.nginx.install
copy_nginx_files:
file.managed:
- names:
- {
{
pillar['php_dir'] }}/conf/nginx.conf:
- source: salt://lnmp/files/nginx.conf
- user: root
- group: root
- mode: '0644'
- {
{
pillar['php_dir'] }}/html/index.php:
- source: salt://lnmp/files/index.php
- require:
- cmd: install_nginx
nginx:
service.running:
- enable: true
- reload: true
- require:
- cmd: install_nginx
- watch:
- file: copy_nginx_files
mysql
[[email protected] ~]# cat /srv/salt/prod/lnmp/mysql.sls
include:
- modules.database.mysql.install
copy_lnmp_mysql_file:
file.managed:
- user: root
- group: root
- mode: '0644'
- names:
- /etc/my.cnf:
- source: salt://lnmp/files/my.cnf
- require:
- cmd: install_mysql
mysqld:
service.running:
- enable: true
- reload: true
- require:
- cmd: install_mysql
- file: trasfer-files
- watch:
- file: copy_lnmp_mysql_file
set_mysql_password:
cmd.run:
- name: {
{
pillar['mysql_dir'] }}/bin/mysql -e "set password=password('123456');"
- require:
- service: mysqld
- unless: {
{
pillar['mysql_dir'] }}/bin/mysql -uroot -p123 -e "exit"
lnmp One key deployment
[[email protected] ~]# cat /srv/salt/prod/lnmp/install.sls
include:
- lnmp.nginx
- lnmp.mysql
- modules.application.php.install
View port number
[[email protected] ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
7、 ... and 、web Page access

边栏推荐
- Amazon launched Amazon one palm payment system, and the contactless palm vein recognition market is expected to explode
- OpenOCD如何通过stlink直接下载程序到stm32板子(已解决)
- Left alignment function of Lua language (handwriting)
- Salt SSH of saltstack
- Convertible bond concept table x notation gives you a convenient and fast experience!
- Basic concept and essence of Architecture
- In order to develop high-end photoresist, Jingrui Co., Ltd. invested 75million yuan to purchase SK Hynix ASML lithography machine
- Overcome the "fear of looking at teeth", and we use technology to change the industry
- MySQL命令语句(个人总结)
- Special draft of Mir | common sense knowledge and reasoning: representation, acquisition and application (deadline on October 31)
猜你喜欢
![[NPP installation plug-in]](/img/6f/97e53116ec4ebc6a6338d125ddad8b.png)
[NPP installation plug-in]

String中常用的API

How openocd directly downloads programs to STM32 board through stlink (solved)

How does app automated testing achieve H5 testing

How to write the SQL statement of time to date?

Implementation of markdown editor in editor.md

App自动化测试是怎么实现H5测试的

Servlet学习笔记

Android-第十三节03xUtils-数据库框架(增删改查)详解

High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation
随机推荐
彻底理解位运算——左移、右移
How does app automated testing achieve H5 testing
[network] cross area network communication learning classification and calculation of IPv4 address
MySQL performance testing tool sysbench learning
基于C语言的信息管理系统和小游戏
How many types of rain do you know?
The peak rate exceeds 2gbps! Qualcomm first passed 5g millimeter wave MIMO OTA test in China
Sprint for golden nine and silver ten, stay up at night for half a month, collect 1600 real interview questions from Android post of major manufacturers
leetcode day4 部门工资最高的员工
MySQL8 Status Variables: Internal Temporary Tables and Files
业务可视化-让你的流程图“Run“起来(4.实际业务场景测试)
MySQL 8 creates master-slave replication based on Clone
【经验之谈】关于维修电子设备的几点建议和经验
My second blog - C language
Business visualization - let your flowchart "run" (4. Actual business scenario test)
【NPP安装插件】
KPMG China: insights into information technology audit projects of securities fund management institutions
Redis notes
Preliminary learning function (3rd blog)
Saltstack system initialization