当前位置:网站首页>saltstack部署lnmp
saltstack部署lnmp
2022-06-11 06:46:00 【在你书包里拉屎】
saltstack部署lnmp
添加变量
配置文件修改
[[email protected] ~]# vim /etc/salt/master
# highstate format, and is generally just key/value pairs.
pillar_roots: ##添加该内容
base:
- /srv/pillar/base
prod:
- /srv/pillar/prod
#
#ext_pillar:
# - hiera: /etc/hiera.yaml
# - cmd_yaml: cat /etc/salt/yaml
添加变量
[[email protected] ~]# ls /srv/pillar/prod/
mysql.sls nginx.sls php.sls top.sls
[[email protected] ~]# cat /srv/pillar/prod/mysql.sls
mysql_installdir: /usr/local
mysql_password: 123
[[email protected] ~]# cat /srv/pillar/prod/nginx.sls
nginx_installdir: /usr/local
[[email protected] ~]# cat /srv/pillar/prod/php.sls
php_installdir: /usr/local
php_start: /etc/init.d
[[email protected] ~]# cat /srv/pillar/prod/top.sls
prod:
'node1':
- nginx
- mysql
- php
##查看
[[email protected] prod]# salt node1 pillar.items
node1:
----------
mysql_installdir:
/usr/local
mysql_password:
12345
nginx_installdir:
/usr/local
php_installdir:
/usr/local
php_start:
/etc/init.d
nginx
[[email protected] nginx]# tree
.
├── files
│ ├── install.sh
│ ├── nginx-1.20.1.tar.gz
│ └── nginx.service.j2
└── install.sls
1 directory, 4 files
[[email protected] nginx]# cat install.sls
nginc-dev-package:
pkg.installed:
- pkgs:
- pcre-devel
- openssl
- openssl-devel
- gd-devel
- gcc
- gcc-c++
- make
- wget
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
- 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
systemctl daemon-reload:
cmd.run
[[email protected] nginx]# cat 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="{
{ pillar['nginx_installdir'] }}"/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
[[email protected] nginx]# cat files/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
mysql
[[email protected] mysql]# tree
.
├── files
│ ├── install.sh
│ ├── mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
│ ├── mysqld.service.j2
│ └── mysql.server
└── install.sls
1 directory, 5 files
[[email protected] mysql]# cat install.sls
ncurses-compat-libs:
pkg.installed
create-mysql-user:
user.present:
- name: mysql
- createhome: false
- system: true
- shell: /sbin/nologin
create-datadir:
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
- unless: test -d {
{ pillar['mysql_installdir'] }}/mysql
{
{ pillar['mysql_installdir'] }}/mysql/support-files/mysql.server:
file.managed:
- source: salt://modules/database/mysql/files/mysql.server
/usr/lib/systemd/system/mysqld.service:
file.managed:
- source: salt://modules/database/mysql/files/mysqld.service.j2
- template: jinja
[[email protected] mysql]# cat files/install.sh
cd /usr/src
tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local
ln -s mysql-5.7.34-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/mysqld.sh
[[email protected] mysql]# cat files/mysqld.service.j2
[Unit]
Description=Mysql server daemon
After=network.target
[Service]
Type=forking
ExecStart={
{ pillar['mysql_installdir'] }}/mysql/support-files/mysql.server start
ExecStop={
{ pillar['mysql_installdir'] }}/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
php
[[email protected] php]# tree
.
├── files
│ ├── install.sh
│ ├── oniguruma-devel-6.8.2-2.el8.x86_64.rpm
│ ├── php-7.4.24.tar.gz
│ ├── php-fpm
│ ├── php-fpm.conf
│ ├── php-fpm.service
│ ├── php.ini
│ └── www.conf
└── install.sls
1 directory, 9 files
[[email protected] 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
dnf -y install epel-release:
cmd.run
dep-pkckages-install:
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
- libmcrypt
- libmcrypt-devel
- readline
- readline-devel
- libxslt
- libxslt-devel
- mhash
- mhash-devel
/usr/src/php-7.4.24.tar.gz:
file.managed:
- source: salt://modules/application/php/files/php-7.4.24.tar.gz
- user: root
- group: root
- mode: '0644'
php-installsh:
cmd.script:
- name: salt://modules/application/php/files/install.sh
- unless: test -d {
{ pillar['php_installdir'] }}/php7
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/php7/etc/php-fpm.conf:
- source: salt://modules/application/php/files/php-fpm.conf
- /usr/local/php7/etc/php-fpm.d/www.conf:
- source: salt://modules/application/php/files/www.conf
- /etc/php.ini:
- source: salt://modules/application/php/files/php.ini
/usr/lib/systemd/system/php-fpm.service:
file.managed:
- source: salt://modules/application/php/files/php-fpm.service.j2
- template: jinja
php-fpm.service:
service.running:
- enable: true
- reload: true
- require:
- cmd: php-installsh
- file: copy-php
[[email protected] php]# cat files/install.sh
#!/bin/bash
cd /usr/src
rm -rf php-7.4.24
tar xf php-7.4.24.tar.gz -C /usr/local
cd /usr/local/php-7.4.24
./configure --prefix=/usr/local/php7 \
--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
[[email protected] php]# cat files/php-fpm.service.j2
[Unit]
Description=php-fpm server daemon
After=network.target
[Service]
Type=forking
ExecStart={
{ pillar['php_start'] }}/php-fpm start
ExecStop={
{ pillar['php_start'] }}/php-fpm stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
lnmp
[[email protected] lnmp]# cat main.sls
include:
- lnmp.nginx
- lnmp.mysql
- modules.application.php.install
##nginx
[[email protected] lnmp]# cat nginx.sls
"Development Tools":
pkg.group_installed
include:
- modules.web.nginx.install
/var/log/nginx:
file.directory:
- user: nginx
- group: nginx
- mode: '0755'
- makedirs: true
{
{ pillar['nginx_installdir'] }}/nginx/html/index.php:
file.managed:
- source: salt://zabbix/files/index.php
- user: nginx
- group: nginx
- mode: '0644'
{
{ pillar['nginx_installdir'] }}/nginx/conf/nginx.conf:
file.managed:
- source: salt://zabbix/files/nginx.conf
- user: root
- group: root
- mode: '0644'
zabbix-nginx-service:
service.running:
- name: nginx
- enable: true
- reload: true
- watch:
- file: {
{ pillar['nginx_installdir'] }}/nginx/conf/nginx.conf
- require:
- cmd: nginx-installsh
- file: {
{ pillar['nginx_installdir'] }}/nginx/conf/nginx.conf
##mysql
[[email protected] lnmp]# cat mysql.sls
lamp-dep-package:
pkg.installed:
- pkgs:
- ncurses-devel
- openssl-devel
- openssl
- cmake
- mariadb-devel
- ncurses-compat-libs
include:
- modules.database.mysql.install
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
- unless: test -d /usr/local/mysql
mysqld-start:
service.running:
- name: mysqld
- enable: true
- require:
- cmd: mysql-installsh
set-password:
cmd.run:
- name: /usr/local/mysql/bin/mysql -e "set password=password('{
{ pillar['mysql_password'] }}');"
- require:
- service: mysqld-start
- unless: /usr/local/mysql/bin/mysql -uroot -p{
{ pillar['mysql_password'] }} -e "exit"

边栏推荐
- 538. convert binary search tree to cumulative tree
- Zabbix 监控主机是否在线
- JS implementation of graphic merging and sorting process [source code attached]
- Differences between FindIndex and indexof
- 网狐游戏服务器房间配置向导服务定制功能页实现
- 【Matlab图像加密解密】混沌序列图像加密解密(含相关性检验)【含GUI源码 1862期】
- Wan Zichang's article shows you promise
- Oracle prompt invalid number
- socket. IO cross domain stepping pit
- Pytest自动化测试-简易入门教程(01)
猜你喜欢

235-二叉搜索树的最近公共祖先

Warning: Each child in a list should have a unique “key“ prop.

socket. IO cross domain stepping pit

572. subtree of another tree

About the designer of qtcreator the solution to the problem that qtdesigner can't pull and hold controls normally

网狐游戏服务器房间配置向导服务定制功能页实现
![Quick sorting of graphic array [with source code]](/img/ef/b1b98db5b16f0c4efc8d3c5247e8b0.jpg)
Quick sorting of graphic array [with source code]

PHP laravel8 send email

563. 二叉树的坡度

Jenkins different styles of project construction
随机推荐
3.1 测试函数的命名规则
Differences between FindIndex and indexof
Illustration of JS implementation from insertion sort to binary insertion sort [with source code]
解决ffmpeg获取AAC音频文件duration不准
022-Redis数据库0基础入门
Detailed explanation of mutual call between C language and Lua
June training (day 11) - matrix
解决ffmpeg獲取AAC音頻文件duration不准
【概率论与数理统计】猴博士 笔记 p41-44 统计量相关小题、三大分布的判定、性质、总体服从正态分布的统计量小题
开源漫画服务器Mango
AppClips&Tips(持续更新)
JS judge whether the year is a leap year and the number of days in the month
Practice: how to reasonably design functions to solve practical problems in software development (II) -- improving reusability
100. 相同的树
Throttling and anti shake
How exactly does instanceof judge the reference data type!
Lazy load
网狐游戏服务器房间配置约战定制功能实现
Count the time-consuming duration of an operation (function)
563. slope of binary tree