saltstack批量安装zabbix agent
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了saltstack批量安装zabbix agent相关的知识,希望对你有一定的参考价值。
1、准备zabbix agent的配置文件
由于没有啥特别要求,这里我选择yum安装zabbix22-agent [[email protected] init]# yum -y install zabbix22-agent [[email protected] zabbix]# cp zabbix_agentd.conf /etc/salt/states/init/files/
2、创建zabbix_agent.sls
[[email protected] ~]# vim /etc/salt/states/init/zabbix_agent.sls zabbix_agent: pkg.installed: - name: zabbix22-agent file.managed: - name: /etc/zabbix_agentd.conf - source: salt://init/files/zabbix_agentd.conf - user: root - group: root - mode: ‘0644‘ service.running: - name: zabbix-agent - enable: True - restart: True 说明: pkg.installed:安装zabbix22-agent file.managed: 管理并下发文件 service.running: 管理服务的状态
3、编辑top.sls文件
[[email protected] ~]# cd /etc/salt/states/ [[email protected] states]# ls init prod top.sls [[email protected] states]# cat top.sls base: ‘*‘: - init.pkg - init.limit - init.ntp-crontab - init.hosts - init.zabbix_agent 查看文件的目录结构 [[email protected] states]# tree init/ init/ ├── files │ ├── hosts.conf │ ├── limits.conf │ ├── ntp-crontab.conf │ └── zabbix_agentd.conf ├── hosts.sls ├── limit.sls ├── ntp-crontab.sls ├── pkg.sls └── zabbix_agent.sls 1 directory, 9 files
4、推送测试
[[email protected] states]# salt ‘*‘ state.highstate 中间步骤略: ---------- ID: zabbix_agent Function: service.running Name: zabbix-agent Result: True Comment: Service zabbix-agent has been enabled, and is running Started: 14:04:45.625235 Duration: 410.618 ms Changes: ---------- zabbix-agent: True Summary ------------ Succeeded: 9 (changed=1) Failed: 0 ------------ Total states run: 9
5、在客户端进行测试:
[[email protected] ~]# salt ‘*‘ cmd.run ‘/etc/init.d/zabbix-agentd status‘ node01.saltstack.com: zabbix_agentd (pid 6084) is running... node02.saltstack.com: zabbix_agentd (pid 5782) is running... [[email protected] ~]# salt ‘*‘ cmd.run "egrep -v ‘^#|^$‘ /etc/zabbix_agentd.conf|grep -w Server" node01.saltstack.com: Server=10.10.10.140 node02.saltstack.com: Server=10.10.10.140
6、变更zabbix Server后,进行测试与验证
如果zabbix server变更了IP地址(由10.10.10.140改为10.10.10.148): [[email protected] ~]# egrep -v ‘^#|^$‘ /etc/salt/states/init/files/zabbix_agentd.conf | grep -w Server Server=10.10.10.148 推送下,更新服务器的agent ip状态: [[email protected] ~]# salt ‘*‘ state.highstate ---------- ID: zabbix_agent Function: file.managed Name: /etc/zabbix_agentd.conf Result: True Comment: File /etc/zabbix_agentd.conf updated Started: 14:22:29.306875 Duration: 16.102 ms Changes: ---------- diff: --- +++ @@ -79,7 +79,7 @@ # Server= #Server=127.0.0.1 -Server=10.10.10.140 +Server=10.10.10.148 ### Option: ListenPort #Agent will listen on this port for connections from the server. ---------- Summary ------------ Succeeded: 9 (changed=1) Failed: 0 ------------ Total states run: 9 检查下客户端,看agent的ip地址是否已经调整了: [[email protected] ~]# salt ‘*‘ cmd.run "egrep -v ‘^#|^$‘ /etc/zabbix_agentd.conf|grep -w Server" node01.saltstack.com: Server=10.10.10.148 node02.saltstack.com: Server=10.10.10.148
本文出自 “冰冻vs西瓜” 博客,请务必保留此出处http://molewan.blog.51cto.com/287340/1899827
以上是关于saltstack批量安装zabbix agent的主要内容,如果未能解决你的问题,请参考以下文章
Saltstack批量安装部署Zabbix代理(附zabbix自动注册详解)
Zabbix之十----批量安装zabbix-agent及web监控