自动化运维工具Saltstack3(saltstack-zabbix-mysql)

配置zabbix与saltstack的软件仓库,主机是安装zabbix所需的软件以备文件传输

一、目录文件梳理

自动化运维工具Saltstack3(saltstack-zabbix-mysql)_第1张图片

二、mariadb模块

vim init.sls
///
db-install:
  pkg.installed:
    - pkgs:
      - mariadb-server
      - mariadb
      - MySQL-python


  service.running:
    - name: mariadb
 
  cmd.run:
    - name: mysql -pwestos -e "DELETE FROM mysql.user WHERE User='';" && mysql -pwestos -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');" && mysql -pwestos -e "DROP DATABASE IF EXISTS test;" && mysql -pwestos -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" && mysql -pwestos -e "FLUSH PRIVILEGES;"
    - onlyif: mysql -e "show databases;"

  #mysql_user.present:
    #- name: root
    #- password: westos
db-configure:
  file.managed:
    - name: /mnt/create.sql.gz
    - source: salt://mariadb/create.sql.gz

  mysql_database.present:
    - name: zabbix
    - character_set: utf8
    - collate: utf8_bin
    - connection_user: root
    - connection_pass: westos

  mysql_user.present:
    - name: zabbix
    - host: localhost
    - password: westos
    - connection_user: root
    - connection_pass: westos

  mysql_grants.present:
    - grant: all privileges
    - database: zabbix.*
    - user: zabbix
    - connection_user: root
    - connection_pass: westos

  cmd.wait:
    - name: zcat /mnt/create.sql.gz | mysql -uzabbix -pwestos zabbix
    - watch:
      - mysql_database: db-configure
\\\

三、zabbix-server模块

vim init.sls
\\\
server-install:
  pkg.installed:
    - pkgs:
      - zabbix-server-mysql
      - zabbix-agent

  file.managed:
    - name: /etc/zabbix/zabbix_server.conf
    - source: salt://zabbix-server/zabbix_server.conf
    - template: jinja
    - context:
      DBPasswd: {{ pillar['DBPasswd'] }}

  service.running:
    - name: zabbix-server
    - watch:
      - file: server-install

zabbix-agent:
  service.running
///
vim /srv/salt/zabbix-server/zabbix_server.conf
\\\
DBPassword={{ DBPasswd }}
///

四、zabbix-agent模块

vim init.sls
\\\
agent-install:
  pkg.installed:
    - name: zabbix-agent

  file.managed:
    - name: /etc/zabbix/zabbix_agentd.conf
    - source: salt://zabbix-agent/zabbix_agentd.conf
    - template: jinja
    - context:
      zabbixserver: {{ pillar['Zabbix-server'] }}
      hostname: {{ grains['fqdn'] }}

  service.running:
    - name: zabbix-agent
    - watch:
      - file: agent-install
///
vim /srv/salt/zabbix-agent/zabbix_agentd.conf
\\\
ServerActive={{ zabbixserver }}
Hostname={{ hostname }}
Server={{ zabbixserver }}
///

五、zabbix-web模块

vim init.sls
///
web-install:
  pkg.installed:
    - pkgs:
      - zabbix-web-mysql
      - zabbix-web
      - httpd
      - php
      - php-mysql

  file.managed:
    - name: /etc/httpd/conf.d/zabbix.conf
    - source: salt://zabbix-web/zabbix.conf

  service.running:
    - name: httpd
    - watch:
      - file: web-install
\\\
vim /srv/salt/zabbix-web/zabbix.conf
\\\
php_value date.timezone Asia/Shanghai
///

六、top模块

vim /srv/salt/top.sls
\\\
base:
  'server2':
    - mariadb
    - zabbix-server
    - zabbix-agent
    - zabbix-web
///

七、Pillar模块

vim /srv/pillar/top.sls
\\\
base:
  '*':
    - zabbix
///
vim /srv/pillar/zabbix.sls
\\\
{% if grains['fqdn'] == 'server2' %}
DBPasswd: westos
Zabbix-server: 172.25.51.2
{% endif %}
///

八、测试\高级推送

salt server2 state.highstate

自动化运维工具Saltstack3(saltstack-zabbix-mysql)_第2张图片

你可能感兴趣的:(企业实战系列,linux,运维)