环境:
server1 | 172.25.60.1 | salt-master + salt-minion + zabbix-server |
---|---|---|
server2 | 172.25.60.2 | salt-minion + zabbix-agent |
1.软件包安装过程存在许多依赖性,配置好yum源
[root@server2 zabbix]# cat /etc/yum.repos.d/rhel7.3.repo
[rhel7.3]
name=rhel7.3
baseurl=http://172.25.60.250/rhel-7.3
gpgcheck=0
[salt]
name=saltname
baseurl=http://172.25.60.250/saltstack
gpgcheck=0
[zabbix]
name=zabbix
baseurl=http://172.25.60.250/zabbix
gpgcheck=0
2.server1上首先安装配置mariadb-server
yum install mariadb-server
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation //安全初始化,设置密码westos
mysql -pwestos //设置数据库
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by 'westos';
cd /usr/share/doc/zabbix-server-mysql-4.0.5/
zcat create.sql.gz | mysql -p zabbix //输入数据库密码
3.master端编写文件
整体结果如下:
(1)vim apache/install
install-apache:
pkg.installed:
- pkgs:
- httpd
service.running:
- name: httpd
(2)vim pkgs/install.sls
zabbix:
pkg.installed:
- pkgs:
- gcc
- zlib-devel
- pcre-devel
(3)vim zabbix-agent/install.sls
include:
- pkgs.install
install-zabbix-agent:
file.managed:
- name: /mnt/zabbix-agent-4.0.5-1.el7.x86_64.rpm
- source: salt://zabbix-agent/files/zabbix-agent-4.0.5-1.el7.x86_64.rpm
cmd.run:
- name: cd /mnt && yum rinstall -y zabbix-agent-4.0.5-1.el7.x86_64.rpm
/etc/httpd/conf.d/zabbix_agentd.conf:
file.managed:
- source: salt://zabbix-agent/files/zabbix_agentd.conf
service-zabbix-agent:
file.managed:
- name: /usr/lib/systemd/system/zabbix-agent
- source: salt://zabbix-server/files/zabbix-agent.service
service.running:
- name: zabbix-agent
- reload: True
- watch:
- file: /etc/zabbix/zabbix_server.conf
(4)vim zabbix-server/install.sls
include:
- pkgs.install
install-zabbix-server:
file.managed:
- name: /mnt/zabbix-server-mysql-4.0.5-1.el7.x86_64.rpm
- source: salt://zabbix-server/files/zabbix-server-mysql-4.0.5-1.el7.x86_64.rpm
install-zabbix-web:
file.managed:
- name: /mnt/zabbix-web-4.0.5-1.el7.noarch.rpm
- source: salt://zabbix-server/files/zabbix-web-4.0.5-1.el7.noarch.rpm
install-zabbix-mysql:
file.managed:
- name: /mnt/zabbix-web-mysql-4.0.5-1.el7.noarch.rpm
- source: salt://zabbix-server/files/zabbix-web-mysql-4.0.5-1.el7.noarch.rpm
cmd.run:
- name: cd /mnt && yum reinstall -y zabbix-server-mysql-4.0.5-1.el7.x86_64.rpm zabbix-web-4.0.5-1.el7.noarch.rpm zabbix-web-mysql-4.0.5-1.el7.noarch.rpm
(5)vim zabbix-server/service.sls
include:
- zabbix-server.install
/etc/zabbix/zabbix_server.conf:
file.managed:
- source: salt://zabbix-server/files/zabbix_server.conf
/etc/httpd/conf.d/zabbix.conf:
file.managed:
- source: salt://zabbix-server/files/zabbix.conf
service-zabbix-server:
file.managed:
- name: /usr/lib/systemd/system/zabbix-server
- source: salt://zabbix-server/files/zabbix-server.service
service.running:
- name: zabbix-server
- reload: True
- watch:
- file: /etc/zabbix/zabbix_server.conf
(6)vim top.sls
base:
'server1':
- apache.install
- zabbix-server.service
'server2':
- zabbix-agent.install
4.运行
salt '*' state.highstate
5.浏览器访问: