saltstack部署lnmp
2021/11/11 23:13:57
本文主要是介绍saltstack部署lnmp,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
部署LNMP
文件结构
[root@master prod]# tree lnmp/ lnmp/ ├── files │ ├── index.php │ ├── my.cnf │ └── nginx.conf ├── install.sls ├── mysql.sls └── nginx.sls [root@master prod]# tree modules/ modules/ ├── app │ └── 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 │ │ ├── mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz │ │ ├── mysqld.service │ │ └── mysql.server │ └── install.sls └── web ├── apache │ ├── files │ │ ├── apr-1.7.0.tar.gz │ │ ├── apr-util-1.6.1.tar.gz │ │ ├── httpd-2.4.48.tar.gz │ │ ├── httpd.conf │ │ ├── httpd.service │ │ ├── index.php │ │ └── install.sh │ └── install.sls └── nginx ├── files │ ├── install.sh │ ├── nginx-1.21.3.tar.gz │ └── nginx.service └── install.sls
修改master配置文件
[root@master ~]# vim /etc/salt/master pillar_roots: base: - /srv/pillar/base prod: - /srv/pillar/prod [root@master ~]# mkdir -p /srv/pillar/prod [root@master ~]# systemctl restart salt-master.service [root@master prod]# tree . ├── mysql.sls ├── nginx.sls ├── php.sls └── top.sls
nginx安装
[root@master nginx]# cat install.sls usradd.nginx: user.present: - name: nginx - shell: /sbin/nologin - system: true - createhome: false 'Development Tools': pkg.group_installed nginx-dep-packages: pkg.installed: - pkgs: - pcre-devel - openssl - openssl-devel - gd-devel - gcc - gcc-c++ copy_nginx: file.managed: - names: - /usr/src/nginx-1.21.3.tar.gz: - source: salt://modules/web/nginx/files/nginx-1.21.3.tar.gz - /usr/lib/systemd/system/nginx.service: - source: salt://modules/web/nginx/files/nginx.service - template: jinja install-nginx: cmd.script: - name: salt://modules/web/nginx/files/install.sh {{ pillar['install_dir'] }} - unless: test -d {{ pillar['install_dir'] }}
mysql安装
[root@master mysql]# cat install.sls mysql: user.present: - shell: /sbin/nologin - system: true - createhome: false ncurses-compat-libs: pkg.installed /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 /opt/data: file.directory: - user: mysql - group: mysql - mode: '755' install-mysql: cmd.script: - name: salt://modules/database/mysql/files/install.sh - unless: test -d /usr/local/mysql copy-mysql-soft: file.managed: - names: - /usr/lib/systemd/system/mysqld.service: - source: salt://modules/database/mysql/files/mysqld.service - user: root - group: root - mode: 644 - {{ pillar['mysql_dir'] }}/support-files/mysql.server: - source: salt://modules/database/mysql/files/mysql.server - user: mysql - group: mysql - mode: 755 - template: jinja - require: - cmd: install-mysql
php安装
[root@master php]# cat install.sls php-dep-packages: 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/oniguruma-devel-6.8.2-2.el8.x86_64.rpm: file.managed: - source: salt://modules/app/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 /usr/src/php-7.4.24.tar.xz: file.managed: - source: salt://modules/app/php/files/php-7.4.24.tar.xz install-php: cmd.script: - name: salt://modules/app/php/files/install.sh {{ pillar['php_dir'] }} - unless: test -d /usr/local/php copy-php-soft: file.managed: - names: - /etc/init.d/php-fpm: - source: salt://modules/app/php/files/php-fpm - user: root - group: root - mode: '0755' - {{ pillar['php_dir'] }}/etc/php-fpm.conf: - source: salt://modules/app/php/files/php-fpm.conf - {{ pillar['php_dir'] }}/etc/php-fpm.d/www.conf: - source: salt://modules/app/php/files/www.conf - /usr/lib/systemd/system/php-fpm.service: - source: salt://modules/app/php/files/php-fpm.service - require: - cmd: install-php php-fpm.service: service.running: - enable: true - reload: true - require: - cmd: install-php - file: copy-php-soft - watch: - file: copy-php-soft
部署lnmp文件配置
[root@master lnmp]# cat nginx.sls include: - modules.web.nginx.install copy_nginx_files: file.managed: - names: - {{ pillar['install_dir'] }}/conf/nginx.conf: - source: salt://lnmp/files/nginx.conf - user: root - group: root - mode: 644 - {{ pillar['install_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 [root@master lnmp]# cat 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: copy-mysql-soft - watch: - file: copy-lnmp-mysql-file set-mysql-passwd: cmd.run: - name: {{ pillar['mysql_dir'] }}/bin/mysql -e "set password=password('123');" - require: - service: mysqld - unless: {{ pillar['mysql_dir'] }}/bin/mysql -uroot -p123 -e "exit" [root@master lnmp]# cat install.sls include: - lnmp.nginx - lnmp.mysql - modules.app.php.install
这篇关于saltstack部署lnmp的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-26MATLAB 中 A(7)=[];什么意思?-icode9专业技术文章分享
- 2024-11-26UniApp 中如何实现使用输入法时保持页面列表不动的效果?-icode9专业技术文章分享
- 2024-11-26在 UniApp 中怎么实现输入法弹出时禁止页面向上滚动?-icode9专业技术文章分享
- 2024-11-26WebSocket是什么,怎么使用?-icode9专业技术文章分享
- 2024-11-26页面有多个ref 要动态传入怎么实现?-icode9专业技术文章分享
- 2024-11-26在 UniApp 中实现一个底部输入框的常见方法有哪些?-icode9专业技术文章分享
- 2024-11-26RocketMQ入门指南:搭建与使用全流程详解
- 2024-11-26RocketMQ入门教程:轻松搭建与使用指南
- 2024-11-26手写RocketMQ:从入门到实践的简单教程
- 2024-11-25【机器学习(二)】分类和回归任务-决策树(Decision Tree,DT)算法-Sentosa_DSML社区版