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

1
2
3
4
5
6
7
8
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

1
2
3
4
5
6
7
8
9
10
11
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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

1
2
3
4
5
6
base:
  'web1.example.com':
    - ntp.install
    - zabbix-agent.install
    - zabbix-server.install
    - mariadb.install

  给节点安装执行

1
salt '*' state.highstate

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

  

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

1
http://192.168.0.209/zabbix/zabbix.php

  

 

posted @   minseo  阅读(239)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示