IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> PHP知识库 -> SaltSatck-zabbix部署-优化部署 -> 正文阅读

[PHP知识库]SaltSatck-zabbix部署-优化部署

zabbix部署

因为zabbix是用php语言开发的,所以必须先部署lamp架构,使其能够支持运行php网页

  • pillar结构
[root@master pillar]# tree 
.
├── base
└── prod
    ├── apache.sls
    ├── mysql.sls
    ├── top.sls
    └── zabbix.sls

[root@master prod]# cat top.sls 
prod:
  'node':
    - apache
    - zabbix
    - mysql
   
[root@master pillar]# salt '*' pillar.items
node:
    ----------
    data_dir:
        /opt/data
    extracted_dir:
        /usr/src
    install_dir:
        /usr/local/apache
    mysql_install_dir:
        /usr/local
  • salt://modules.web.apache.install
[root@master apache]# cat install.sls 
"Development Tools":
  pkg.group_installed
   
httpd-dep-packages:
  pkg.installed:
    - pkgs:
      - openssl-devel
      - pcre-devel
      - expat-devel
      - libtool
      - gcc
      - gcc-c++
      - make

create-httpd-user:
  user.present:
    - name: apache
    - shell: /sbin/nologin
    - createhome: false
    - system: true

copy-software:
  file.managed:
    - names:
      - /usr/src/apr-1.7.0.tar.gz:
        - source: salt://modules/web/apache/file/apr-1.7.0.tar.gz
      - /usr/src/apr-util-1.6.1.tar.gz:
        - source: salt://modules/web/apache/file/apr-util-1.6.1.tar.gz
      - /usr/src/httpd-2.4.48.tar.gz:
        - source: salt://modules/web/apache/file/httpd-2.4.48.tar.gz

httpd-install:
  cmd.script:
    - name: salt://modules/web/apache/file/install.sh {{ pillar['install_dir'] }}
    - unless: test -d /usr/local/apache

{{ pillar['install_dir'] }}/conf/httpd.conf:
  file.managed:
    - source: salt://modules/web/apache/file/httpd.conf
    - user: root
    - group: root
    - mode: '0644'
    - require: 
      - cmd: httpd-install

/usr/lib/systemd/system/httpd.service:
  file.managed:
    - source: salt://modules/web/apache/file/httpd.service.j2 
    - user: root
    - group: root
    - mode: '0644'
    - template: jinja
  • salt://modules.web.apache.file
[root@master file]# pwd
/srv/salt/prod/modules/web/apache/file

[root@master file]# ls 
apr-1.7.0.tar.gz       httpd-2.4.48.tar.gz  httpd.service.j2
apr-util-1.6.1.tar.gz  httpd.conf           install.sh
  • salt://modules.database.mysql.install
[root@master mysql]# cat install.sls 
dep-mysql-install:
  pkg.installed:
    - pkgs:
      - ncurses-compat-libs

mysql:
  user.present:
    - system: true
    - createhome: false
    - shell: /sbin/nologin

{{ pillar['mysql_install_dir'] }}:
  archive.extracted:
    - source: salt://modules/database/mysql/files/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
  file.symlink:
    - name: {{ pillar['mysql_install_dir'] }}/mysql
    - target: {{ pillar['mysql_install_dir'] }}/mysql-5.7.34-linux-glibc2.12-x86_64 

{{ pillar['mysql_install_dir'] }}/mysql:
  file.directory:
    - user: mysql
    - group: mysql
    - mode: '0755'
    - recurse:
      - user
      - group

{{ pillar['data_dir'] }}:
  file.directory:
    - user: mysql
    - group: mysql
    - mode: '0755'
    - makedirs: true
    - recurse:
      - user
      - group 

/etc/profile.d/mysqld.sh:
  file.managed:
    - source: salt://modules/database/mysql/files/mysqld.sh.j2
    - template: jinja

{{ pillar['mysql_install_dir'] }}/mysql/support-files/mysql.server:
  file.managed:
    - source: salt://modules/database/mysql/files/mysql.server
    - user: mysql
    - group: mysql
    - mode: '0755'

/usr/lib/systemd/system/mysqld.service:
  file.managed:
    - source: salt://modules/database/mysql/files/mysqld.service.j2
    - user: root
    - group: root
    - mode: '0644'
    - template: jinja

mysql-initialize:
  cmd.run:
    - name: '{{ pillar['mysql_install_dir'] }}/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir={{ pillar['data_dir'] }}/' 
    - require:
      - archive: {{ pillar['mysql_install_dir'] }}
      - file: {{ pillar['data_dir'] }}
      - user: mysql
    - unless: test $(ls -l {{ pillar['data_dir'] }} |wc -l) -gt 1
  • salt://modules.database.mysql.files
[root@master files]# pwd
/srv/salt/prod/modules/database/mysql/files

[root@master files]# ls 
my.cnf.j2                                   mysqld.sh.j2
mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz  mysql.server
mysqld.service.j2
  • salt://modules.application.php.install
[root@master php]# cat install.sls 
/tmp/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 /tmp/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
    - unless: rpm -q oniguruma-devel 

php-dep-package:
  pkg.installed:
    - pkgs:
      - libxml2 
      - libxml2-devel 
      - libsqlite3x-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 
      - libzip
      - libzip-devel
      - mhash 
      - mhash-devel 
      - php-mysqlnd
      - make
      - gcc
      - gcc-c++ 

/usr/src:
  archive.extracted:
    - source: salt://modules/application/php/files/php-7.4.24.tar.xz

php-install:
  cmd.script:
    - name: salt://modules/application/php/files/install.sh
    - unless: test -d /usr/local/ph7

copy-file-php:
  file.managed:
    - names:
      - /usr/local/php7/etc/php-fpm.conf:
        - source: salt://modules/application/php/files/php-fpm.conf.default
      - /usr/local/php7/etc/php-fpm.d/www.conf:
        - source: salt://modules/application/php/files/www.conf.default
      - /etc/php.ini:
        - source: salt://modules/application/php/files/php.ini-production
      - /etc/init.d/php-fpm:
        - source: salt://modules/application/php/files/init.d.php-fpm
        - user: root
        - group: root
        - mode: '0755'
      - /usr/lib/systemd/system/php-fpm.service:
        - source: salt://modules/application/php/files/php-fpm.service
    - require:
      - cmd: php-install  

php-fpm.service:
  service.running:
    - enable: true
    - reload: true
    - require: 
      - cmd: php-install
      - file: copy-file-php
    - watch: 
      - file: copy-file-php
  • salt://modules.application.php.files
[root@master files]# pwd
/srv/salt/prod/modules/application/php/files

[root@master files]# ls 
init.d.php-fpm                          php-fpm.conf.default
install.sh                              php-fpm.service
oniguruma-devel-6.8.2-2.el8.x86_64.rpm  php.ini-production
php-7.4.24.tar.xz                       www.conf.default
php-8.0.11.tar.xz
  • salt://zabbix
[root@master zabbix]# pwd
/srv/salt/prod/zabbix

[root@master zabbix]# ls 
apache.sls  files    main.sls  mysql.sls
  • salt://zabbix.apache
[root@master zabbix]# cat apache.sls 
include:
  - modules.web.apache.install

/usr/include/httpd:
  file.symlink:
    - target: {{ pillar['install_dir'] }}/include

create-zabbix-dir:
  file.directory:
    - name: {{ pillar['install_dir'] }}/htdocs/zabbix
    - user: root
    - group: root
    - mode: '0755'
    - makedirs: true

{{ pillar['install_dir'] }}/conf/extra/vhosts.conf:
  file.managed:
    - source: salt://zabbix/files/vhosts.conf.j2
    - user: root
    - group: root
    - mode: '0644'
    - template: jinja
    - require:
      - cmd: httpd-install

{{ pillar['install_dir'] }}/htdocs/zabbix/index.php:
  file.managed:
    - source: salt://zabbix/files/index.php
    - user: root
    - group: root
    - mode: '0644'
  
httpd.service:
  service.running:
    - enable: true
    - reload: true
    - require: 
      - cmd: httpd-install
      - file: /usr/lib/systemd/system/httpd.service
    - watch:
      - file: {{ pillar['install_dir'] }}/conf/httpd.conf
      - file: {{ pillar['install_dir'] }}/conf/extra/vhosts.conf
  • salt://zabbix.mysql
[root@master zabbix]# cat mysql.sls 
include:
  - modules.database.mysql.install

extend:
  dep-mysql-install:
    pkg.installed:
      - pkgs:
        - ncurses-devel 
        - openssl-devel 
        - openssl 
        - cmake 
        - mariadb-devel

{{ pillar['mysql_install_dir'] }}/include/mysql:
  file.symlink:
    - target: {{ pillar['mysql_install_dir'] }}/mysql/include

/etc/ld.so.conf.d/mysql.conf:
  file.managed:
    - source: salt://zabbix/files/mysql.conf.j2
    - user: root
    - group: root
    - mode: '0644'
    - template: jinja

/etc/my.cnf:
  file.managed:
    - source: salt://zabbix/files/my.cnf.j2
    - user: root
    - group: root
    - mode: '0644'
    - template: jinja

mysqld.service:
  service.running:
    - enable: true
    - reload: true
    - require:
      - archive: {{ pillar['mysql_install_dir'] }}
      - file: /usr/lib/systemd/system/mysqld.service
      - file: /etc/my.cnf
    - watch:
      - file: /etc/my.cnf

set-password-mysql:
  cmd.run: 
    - name: {{ pillar['mysql_install_dir'] }}/mysql/bin/mysql -e "set password = password('123456');"
    - require: 
      - service: mysqld.service
    - unless: {{ pillar['mysql_install_dir'] }}/mysql/bin/mysql -uroot -p123456 -e 'exit'
  • salt://zabbix.main
[root@master zabbix]# cat main.sls 
include:
  - zabbix.apache
  - zabbix.mysql
  - modules.application.php.install

zabbix-dep-package:
  pkg.installed:
    - pkgs:
      - net-snmp-devel
      - libevent-devel

zabbix-extracted:
  archive.extracted:
    - name: {{ pillar['extracted_dir'] }}
    - source: salt://zabbix/files/zabbix-5.4.4.tar.gz
    
zabbix:
  user.present:
    - system: true
    - createhome: false
    - shell: /sbin/nologin

zabbix-install:
  cmd.script:
    - name: salt://zabbix/files/install.sh {{ pillar['extracted_dir'] }}
    - unless: test $(ls -l /usr/local/etc |wc -l) -gt 1
  
/usr/local/etc/zabbix_server.conf:
  file.managed:
    - source: salt://zabbix/files/zabbix_server.conf
    - user: root
    - group: root
    - mode: '0644'
    - require:
      - cmd: zabbix-install
 
/var/lib/mysql:
  file.directory:
    - user: root
    - group: root
    - mode: '0755'
    - makedirs: true

/var/lib/mysql/mysql.sock:
  file.symlink:
    - target: /tmp/mysql.sock

/usr/local/apache/htdocs/zabbix:
  file.recurse:
    - source: salt://zabbix/files/zabbix
    - include_empty: true
    - require:
      - cmd: httpd-install
   
/usr/local/apache/htdocs:
  file.directory:
    - user: apache
    - group: apache
    - mode: '0755'
    - recurse:
      - user
      - group
    - require: 
      - cmd: httpd-install
      - user: create-httpd-user

/etc/php.ini:
  file.managed:
    - source: salt://zabbix/files/php.ini
    - require: 
      - cmd: php-install
      - file: copy-file-php 

/usr/local/apache/htdocs/zabbix/conf:
  file.directory:
    - user: apache
    - group: apache
    - mode: '0777'
    - require:
      - cmd: httpd-install
  
php-fpm.service-watch:
  service.running:
    - name: php-fpm.service
    - enable: true
    - reload: true
    - watch:
      - file: copy-file-php

start-zabbix-server:
  cmd.run:
    - name: zabbix_server
    - unless: ss -antl |grep 10051
 
start-zabbix-agentd:
  cmd.run:
    - name: zabbix_agentd
    - unless: ss -antl |grep 10050

mysqld.service-watch:
  service.running:
    - name: mysqld.service
    - enable: true
    - reload: true
    - watch:
      - file: /etc/my.cnf

httpd.service-watch:
  service.running:
    - name: httpd.service
    - enable: true
    - reload: true
    - watch: 
      - file: {{ pillar['install_dir'] }}/conf/httpd.conf
      - file: {{ pillar['install_dir'] }}/conf/extra/vhosts.conf
  • 执行
[root@master zabbix]# salt '*' state.sls zabbix.main saltenv=prod 

在这里插入图片描述

  PHP知识库 最新文章
Laravel 下实现 Google 2fa 验证
UUCTF WP
DASCTF10月 web
XAMPP任意命令执行提升权限漏洞(CVE-2020-
[GYCTF2020]Easyphp
iwebsec靶场 代码执行关卡通关笔记
多个线程同步执行,多个线程依次执行,多个
php 没事记录下常用方法 (TP5.1)
php之jwt
2021-09-18
上一篇文章      下一篇文章      查看所有文章
加:2021-11-14 21:23:49  更:2021-11-14 21:24:36 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/14 14:50:21-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码