saltstack部署zabbix

目录结构

├── prod
│   ├── module
│   │   ├── application
│   │   │   ├── php8
│   │   │   │   ├── files
│   │   │   │   │   ├── init.d.php-fpm
│   │   │   │   │   ├── oniguruma-devel-6.8.2-2.el8.x86_64.rpm
│   │   │   │   │   ├── php-7.4.24.tar.gz
│   │   │   │   │   ├── php-8.0.12.tar.gz
│   │   │   │   │   ├── php-fpm.conf.default
│   │   │   │   │   ├── php-fpm.service
│   │   │   │   │   ├── php.ini-production
│   │   │   │   │   ├── php.sh
│   │   │   │   │   └── www.conf.default
│   │   │   │   └── install.sls
│   │   │   └── php7
│   │   │       ├── 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
│   │   │       │   └── www.conf
│   │   │       └── install.sls
│   │   ├── database
│   │   │   └── mysql
│   │   │       ├── files
│   │   │       │   ├── mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
│   │   │       │   ├── mysql.conf
│   │   │       │   ├── mysql.server
│   │   │       │   ├── mysql.service
│   │   │       │   └── mysql.sh
│   │   │       └── install.sls
│   │   ├── lamp
│   │   │   ├── files
│   │   │   │   ├── httpd.conf
│   │   │   │   └── index.php
│   │   │   └── install.sls
│   │   └── web
│   │       └── apache
│   │           ├── files
│   │           │   ├── httpd.conf
│   │           │   ├── httpd.service
│   │           │   └── httpd.sh
│   │           ├── install.sls
│   │           └── packages
│   │               ├── apr-1.7.0.tar.gz
│   │               ├── apr-util-1.6.1.tar.gz
│   │               └── httpd-2.4.51.tar.gz
│   └── zabbix
│       ├── apache.sls
│       ├── files
│       │   ├── index.php
│       │   ├── my.cnf
│       │   ├── vhosts.conf
│       │   ├── zabbix-5.4.4.tar.gz
│       │   └── zabbix.sh
│       ├── install.sls
│       ├── main.sls
│       └── mysql.sls
└── test  

pillar结构

[root@master zabbix]# cat top.sls 
prod:
  'node1':
    - apache
    - mysql
    - zabbix

[root@master pillar]# cat pillar.items 
node1:
    ----------
    data_dir:
        /opt/data
    extracted_dir:
        /usr/src
    install_dir:
        /usr/local/apache
    mysql_install_dir:
        /usr/local

module的配置文件

[root@master web]# cat apache/install.sls 
"Development Tools":
  pkg.group_installed

mypkgs:
  pkg.installed:
    - pkgs:
      - make
      - openssl-devel
      - pcre-devel
      - zlib-devel
      - expat-devel
      - gcc-c++

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

copy-packages:
  file.managed:
    - names:
      - /usr/src/apr-1.7.0.tar.gz:
        - source: salt://module/web/apache/packages/apr-1.7.0.tar.gz
      - /usr/src/apr-util-1.6.1.tar.gz:
        - source: salt:///module/web/apache/packages/apr-util-1.6.1.tar.gz
      - /usr/src/httpd-2.4.51.tar.gz:
        - source: salt://module/web/apache/packages/httpd-2.4.51.tar.gz

apache-install:
  cmd.script:
    - name: salt://module/web/apache/files/httpd.sh
    - unless: test -d /usr/local/apache

  
    - 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:
    - name: /usr/local/apache/conf/httpd.conf
    - source: salt://module/web/apache/files/httpd.conf
    - user: root
    - group: root
    - mode: '644'
    - require: 
      - cmd: httpd-install

/usr/lib/systemd/system/httpd.service:
  file.managed:
    - source: salt://module/web/apache/files/httpd.service
    - user: root
    - group: root
    - mode: '644'
    - template: jinja

module的MySQL

[root@master module]# cat database/mysql/install.sls 
mysql-install:
  pkg.installed:
    - pkgs:
      - ncurses-compat-libs
      - ncurses-devel
      - cmake
      - mariadb-devel
      - openssl
      - opnessl-devel

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

unzip-mysql:
  archive.extracted:
    - name: /usr/local
    - source: salt://module/database/mysql/files/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

mysql-link:
  file.symlink:
    - name: /usr/local/mysql
    - target: /usr/local/mysql-5.7.34-linux-glibc2.12-x86_64

/usr/local/mysql:
  file.directory:
    - user: mysql
    - group: mysql
    - mode: '755'
    - recurse:
      - user
      - group

/etc/profile.d/mysql.sh:
  file.managed:
    - source: salt://module/database/mysql/files/mysql.sh
    - user: root
    - group: root
    - mode: '644'

/opt/data:
  file.directory:
    - user: mysql
    - group: mysql
    - mode: '755'
    - makedirs: true
    - recurse:
      - user
      - group

/usr/include/mysql:
  file.symlink:
    - target: /usr/local/mysql/include/

/etc/ld.so.conf.d/mysql.conf:
  file.managed:
    - source: salt://module/database/mysql/files/mysql.conf


/usr/local/mysql/support-files/mysql.server:
  file.managed:
    - user: root
    - group: root
    - mode: '755'
    - source: salt://module/database/mysql/files/mysql.server

/usr/lib/systemd/system/mysql.service:
  file.managed:
    - user: root
    - group: root
    - mode: '644'
    - source: salt://module/database/mysql/files/mysql.service

initialize-mysql:
  cmd.run:
    - name: '/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir /opt/data/'

module的php

[root@master module]# cat application/php7/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 
      - libsqlite3x-devel 
      - php-mysqlnd 
      - libzip-devel
      - gcc
      - gcc-c++
      - make

/usr/src/oniguruma-devel-6.8.2-2.el8.x86_64.rpm:
  file.managed:
    - source: salt://php7/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

/usr/src:
  archive.extracted:
    - source: salt://php7/files/php-7.4.24.tar.gz

salt://php7/files/install.sh:
  cmd.script
    - unless: test -d /usr/local/php7
copysoft:
  file.managed:
    - names:
      - /etc/init.d/php-fpm:
        - source: salt://php7/files/php-fpm
        - user: root
        - group: root
        - mode: '0755'
      - /usr/local/php7/etc/php-fpm.conf:
        - source: salt://php7/files/php-fpm.conf
      - /usr/local/php7/etc/php-fpm.d/www.conf:
        - source: salt://php7/files/www.conf
      - /usr/lib/systemd/system/php-fpm.service:
        - source: salt://php7/files/php-fpm.service

php-fpm.service:
  service.running:
    - enable: true

zabbix项目

[root@master zabbix]# ls
apache.sls  files  install.sls  main.sls  mysql.sls

apache

[root@master zabbix]# cat apache.sls 
include:
  - module.web.apache.install

/usr/include/httpd:
  file.symlink:
    - target: /usr/local/apache/include

start-apache:
  service.running:
    - name: httpd
    - enable: true

/usr/local/apache/htdocs/test:
  file.directory:
    - user: root
    - group: root
    - mode: '755'

/usr/local/apache/conf/extra/vhosts.conf:
  file.managed:
    - source: salt://zabbix/files/vhosts.conf
    - user: root
    - group: root
    - mode: '644'

/usr/local/apache/htdocs/test/index.php:
  file.managed:
    - source: salt://zabbix/files/index.php
    - user: root
    - group: root
    - mode: '644'

/usr/local/apache/htdocs/:
  file.directory:
    - user: apache
    - group: apache
    - recurse:
      - user
      - group

httpd.service:
  service.running:
    - enable: true

MySQL

[root@master zabbix]# cat mysql.sls 
include:
  - module.database.mysql.install

/etc/my.cnf:
  file.managed:
    - source: salt://zabbix/files/my.cnf

start-mysql:
  service.running:
    - name: mysql
    - enable: true

  cmd.run:
    - name: /usr/local/mysql/bin/mysql -e "set password=password('1');"

zabbix安装部署

[root@master zabbix]# cat install.sls 
install-zabbix:
  pkg.installed:
    - pkgs:
      - net-snmp-devel
      - libevent-devel

/usr/local:
  archive.extracted:
    - source: salt://zabbix/files/zabbix-5.4.4.tar.gz

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

salt://zabbix/files/zabbix.sh:
  cmd.script
    -unless: test -f /usr/local/etc/zabbix_server.conf

/usr/local/etc/zabbix_server.conf:
  file.managed:
    - source: salt://zabbix/files/zabbix_server.conf

/var/lib/mysql:
  file.directory:
    - user: root
    - group: root      
    - mode: 755
    - require
      - cmd: salt://zabbix/files/zabbix.sh

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

zabbix-link:
  file.symlink:
    - name: /usr/lib64
    - target: /usr/local/mysql/lib/libmysqlclient.so.20

 
  cmd.run:
    - names:
      - zabbix_server 
      - zabbix_agentd

/etc/php.ini:
  file.managed:
    - source: salt://zabbix/files/php.ini

/usr/local/apache/htdocs/zabbix:
  file.directory:
    - user: apache
    - group: apache
    - mode: '644'
    - recurse:
      - user
      - group


/usr/local/apache/htdocs/zabbix/:
  file.recurse:
    - source: salt://zabbix/files/ui
    - include_empty: true

/usr/local/apache/conf/httpd.conf:
  file.managed:
    - source: salt://zabbix/files/httpd.conf


[root@master zabbix]# cd files/
[root@master files]# ls
httpd.conf  ld.so.conf  php.ini  vhosts.conf          zabbix_server.conf
index.php   my.cnf      ui       zabbix-5.4.4.tar.gz  zabbix.sh

[root@master files]# cat zabbix.sh 
#!/bin/bash

/usr/local/mysql/bin/mysql -uroot -p1 -e "create database zabbix character set utf8 collate utf8_bin;"
/usr/local/mysql/bin/mysql -uroot -p1 -e "grant all privileges on zabbix.* to zabbix@localhost identified by '1';"
/usr/local/mysql/bin/mysql -uroot -p1 -e "flush privileges;"

cd /usr/local/zabbix-5.4.4/database/mysql/
/usr/local/mysql/bin/mysql -uroot -p1 zabbix < schema.sql
/usr/local/mysql/bin/mysql -uroot -p1 zabbix < images.sql
/usr/local/mysql/bin/mysql -uroot -p1 zabbix < data.sql

cd /usr/local/zabbix-5.4.4
./configure --enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2

make install


[root@master zabbix]# cat main.sls 
include:
  - zabbix.apache
  - zabbix.mysql
  - module.application.php7.install
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容