当前位置:网站首页>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

边栏推荐
- Edge detection and connection of image segmentation realized by MATLAB
- 基于QTGUI图像界面的空战游戏设计
- leetcode day3 超过经理收入的员工
- WPF implements MessageBox message prompt box with mask
- Preliminary learning function (3rd blog)
- Leetcode Day5 delete duplicate email
- Thoroughly understand bit operations - shift left, shift right
- Saltstack system initialization
- Rust Getting Started Guide (rustup, cargo)
- Leetcode day3 find duplicate email addresses
猜你喜欢
随机推荐
Question bank and answers of the latest national fire-fighting facility operators (intermediate fire-fighting facility operators) in 2022
leetcode day3 超过经理收入的员工
STC12C5A60S2 function description (STC12C5A60S2 is triggered by default)
MySQL8 tmp_table_size和max_heap_table_size
数字图像理论知识(一)(个人浅析)
Codeignier framework implements restful API interface programming
Investment of 3.545 billion yuan! Gree Group participates in Xiaomi industry fund
Leetcode Day5 delete duplicate email
Netcoreapi operation excel table
Serial port receiving application ring buffer
Quickly install torch spark, torch geometric and other packages in moment pool cloud
11. Learn MySQL union operator
Test Development Notes
MIR专题征稿 | 常识知识与推理:表示、获取与应用 (10月31日截稿)
Redis笔记
美国将提供250亿美元补贴,鼓励英特尔等芯片制造商迁回产线
Cloud computing notes part.2 - Application Management
基于MATLAB的函数拟合
Cell综述:人类微生物组研究中的单细胞方法
串口接收应用——环形缓冲buffer






![[NPP installation plug-in]](/img/6f/97e53116ec4ebc6a6338d125ddad8b.png)


