环境
node1 192.168.56.11 角色 salt-master
node2 192.168.56.12 角色 salt-minon
实现内容
使用salt远程安装zabbix-agent
步骤
环境是基于前几篇博客基础上Master和minion已经配置完成
一,创建zabbix项目文件夹,用于存放状态文件
[root@linux-node1 base]# mkdir /srv/salt/base/zabbix -p [root@linux-node1 base]# mkdir /srv/salt/base/init/files -p #用于存放系统相关初始化的信息
二,配置salt的epel源文件
[root@linux-node1 files]# pwd /srv/salt/base/init/files [root@linux-node1 files]# wget http://mirrors.aliyun.com/repo/epel-7.repo --2017-10-22 19:50:35-- http://mirrors.aliyun.com/repo/epel-7.repo
......
三,拷贝zabbix配置文件作为salt的zabbix源文件
[root@linux-node1 zabbix]# yum list |grep zabbix22-agent zabbix22-agent.x86_64 2.2.20-1.el7 epel [root@linux-node1 zabbix]# ll /etc/zabbix/zabbix_agentd.conf lrwxrwxrwx 1 root root 22 Oct 22 20:03 /etc/zabbix/zabbix_agent.conf -> /etc/zabbix_agent.conf [root@linux-node1 zabbix]# mkdir /srv/salt/base/zabbix/files [root@linux-node1 zabbix]# cp /etc/zabbix_agentd.conf /srv/salt/base/zabbix/files
四,添加jiaja模板变量到salt的zabbix源文件
[root@linux-node1 files]# grep ^[a-Z] zabbix_agentd.conf PidFile=/run/zabbix/zabbix_agentd.pid LogFile=/var/log/zabbix/zabbix_agentd.log LogFileSize=0 Server={{ ZABBIX_SERVER }} Hostname={{ AGENT_HOSTNAME }} Include=/etc/zabbix_agentd.conf.d/
五,配置epel状态文件管理
[root@linux-node1 init]# pwd /srv/salt/base/init [root@linux-node1 init]# vim yum-repo.sls [root@linux-node1 init]# cat yum-repo.sls /etc/yum.repos.d/epel-7.repo: file.managed: - source: salt://init/files/epel-7.repo - user: root - group: root - mode: 644
六,写zabbix-agent的状态文件
[root@linux-node1 zabbix]# pwd /srv/salt/base/zabbix [root@linux-node1 zabbix]# cat zabbix-agent.sls include: #支持include功能 - init.yum-repo zabbix-agent: pkg.installed: - name: zabbix22-agent - require: - file: /etc/yum.repos.d/epel-7.repo file.managed: - name: /etc/zabbix_agentd.conf - source: salt://zabbix/files/zabbix_agentd.conf - user: root - group: root - mode: 644 - template: jinja - defaults: ZABBIX_SERVER: 192.168.56.12 AGENT_HOSTNAME: {{ grains['fqdn'] }} - require: - pkg: zabbix-agent service.running: - name: zabbix-agent - enable: True - watch: - file: zabbix-agent - pkg: zabbix-agent zabbix_agentd.conf.d: file.directory: - name: /etc/zabbix_agentd.conf.d - watch_in: - service: zabbix-agent - require: - pkg: zabbix-agent - file: zabbix-agent
七,测试
[root@linux-node1 files]# salt 'linux-node2*' state.sls zabbix.zabbix-agent test=True linux-node2.example.com: ---------- ID: /etc/yum.repos.d/epel-7.repo Function: file.managed Result: None Comment: The file /etc/yum.repos.d/epel-7.repo is set to be changed Started: 20:26:12.939665 Duration: 10.114 ms Changes: ---------- newfile: /etc/yum.repos.d/epel-7.repo ---------- ID: zabbix-agent Function: pkg.installed Name: zabbix22-agent Result: None Comment: The following packages are set to be installed/updated: zabbix22-agent Started: 20:26:13.254634 Duration: 2867.494 ms Changes: ---------- ID: zabbix-agent Function: file.managed Name: /etc/zabbix_agentd.conf Result: None Comment: The file /etc/zabbix_agentd.conf is set to be changed Started: 20:26:16.122685 Duration: 15.872 ms Changes: ---------- newfile: /etc/zabbix_agentd.conf ---------- ID: zabbix_agentd.conf.d Function: file.directory Name: /etc/zabbix_agentd.conf.d Result: None Comment: The following files will be changed: /etc/zabbix_agentd.conf.d: directory - new Started: 20:26:16.139640 Duration: 0.401 ms Changes: ---------- ID: zabbix-agent Function: service.running Result: None Comment: Service is set to be started Started: 20:26:16.206765 Duration: 79.412 ms Changes: Summary ------------ Succeeded: 5 (unchanged=5, changed=2) Failed: 0 ------------ Total states run: 5