SaltStack自动化安装zabbix-server

  使用SaltStack自动化安装zabbix-server

  1,设置ntp时间同步

  2,安装zabbix-agent

  3,安装zabbix-server  

  4,安装及配置mariadb(mariadb与zabbix-server在同一台服务器)

  环境

  

  salt-master配置/etc/salt/master

  开启top

  目录结构

  ntp/install.sls

ntp-install:
  pkg.installed:
    - name: ntpdate

ntp-crontab:
  cmd.run:
    - name: echo '*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com' >>/var/spool/cron/root
    - unless: test `grep 'ntpdate' /var/spool/cron/root | wc -l` > 0

  安装ntpdate时间同步软件并且设置定时任务每隔5分钟同步时间

  这里设置一个unless假如已经在定时任务里面有设置时间同步则不执行设置以防重复

  zabbix-agent/install.sls

zabbix-agent-install:
  cmd.run:
    - name: rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
    - unless: test -f /etc/yum.repos.d/zabbix.repo
  pkg.installed:
    - name: zabbix-agent

zabbix-agent-service:
  service.running:
    - name: zabbix-agent
    - enable: True

  设置zabbix-agent源并且安装zabbix-agent设置自启动

  假如已经安装了源则不设置yum源

  

  zabbix-server/install.sls

zabbix-server-install:
  cmd.run:
    - name: rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
    - unless: test -f /etc/yum.repos.d/zabbix.repo
  pkg.installed:
    - pkgs:
      - zabbix-server-mysql
      - zabbix-web-mysql

zabbix-server-service:
  service.running:
    - name: zabbix-server
    - enable: True

zabbix-server-config:
  file.managed:
    - name: /etc/httpd/conf.d/zabbix.conf
    - source: salt://zabbix-server/files/zabbix.conf
    - mode: 644
    - user: root
    - group: root

httpd-config:
  file.managed:
    - name: /etc/httpd/conf/httpd.conf
    - sourec: salt://zabbix-server/files/httpd.conf
    - mode: 644

  安装zabbix-server并且设置配置文件

  配置文件zabbix.conf修改时区为Asia/Shanghai

  配置文件httpd.conf修改了 ServerName 127.0.0.1:80

  mariadb/install.sls

mariadb-install:
  pkg.installed:
    - name: mariadb-server

mariadb-service:
  service.running:
    - name: mariadb
    - enable: True

mariadb-config:
  cmd.run:
    - name: mysql -e "create database zabbix character set utf8 collate utf8_bin;grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';" && zcat `rpm -ql zabbix-server-mysql|grep create.sql.gz`|mysql -uzabbix -pzabbix zabbix && systemctl restart httpd
    - require:
      - service: mariadb-service

  安装mariadb并且初始化zabbix库

  这里刚刚安装mysql没有设置mysql密码,假如库zabbix已经存在会报错

  top.sls

base:
  'web1.example.com':
    - ntp.install
    - zabbix-agent.install
    - zabbix-server.install
    - mariadb.install

  给节点安装执行

salt '*' state.highstate

  如果是单独节点需要安装设置ntp和zabbix-agent则单独执行即可

  

  执行完毕验证在浏览器输入地址安装配置即可

http://192.168.0.209/zabbix/zabbix.php

  

原文地址:https://www.cnblogs.com/minseo/p/8779105.html