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

边栏推荐
- June training (day 11) - matrix
- PHP laravel8 send email
- Resolve typeerror: ctx injections. tableRoot.$ scopedSlots[ctx.props.column.slot] is not a function
- Biweekly investment and financial report: capital rush yuan universe game
- JVM from getting started to abandoning 1: memory model
- Redux learning (I) -- the process of using Redux
- 235-二叉搜索树的最近公共祖先
- UEFI查找PCI设备
- 动态import
- Vulhub 8.1-backdoor vulnerability recurrence
猜你喜欢

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

Mediaextractor source code analysis of multimedia framework analysis (1)

572. subtree of another tree
![[]==![]](/img/65/ab724c74b080da319ed5c01c93fdb7.png)
[]==![]

100. same tree

JS judge whether the year is a leap year and the number of days in the month
![Quick sorting of graphic array [with source code]](/img/ef/b1b98db5b16f0c4efc8d3c5247e8b0.jpg)
Quick sorting of graphic array [with source code]

【Matlab WSN通信】A_Star改进LEACH多跳传输协议【含源码 487期】

Solve the problem that ffmpeg obtains aac audio files with incorrect duration

617. merge binary tree
随机推荐
Training and testing of super score model in mmediting
Zabbix 监控主机是否在线
解决ffmpeg獲取AAC音頻文件duration不准
Scripy web crawler series tutorials (I) | construction of scripy crawler framework development environment
搜狐员工遭遇工资补助诈骗 黑产与灰产有何区别 又要如何溯源?
不引入第三个变量,交换两个值
Mongodb installation
Redux learning (I) -- the process of using Redux
JS implementation of Hill sort of graphic insertion sort [with source code]
socket. IO cross domain stepping pit
arguments......
【Matlab图像加密解密】混沌序列图像加密解密(含相关性检验)【含GUI源码 1862期】
必读1:格局越大的人,越懂得说话
Handwriting promise [02] - asynchronous logic implementation
JS two methods to determine whether there are duplicate values in the array
563. slope of binary tree
Redux learning (II) -- encapsulating the connect function
【Matlab WSN通信】A_Star改进LEACH多跳传输协议【含源码 487期】
Implementation of customization function page of online Fox game server room configuration wizard service
235-二叉搜索树的最近公共祖先