编写zabbix-agent安装文件
[root@linux-node1 base]# cd /srv/salt/base/init/
[root@linux-node1 init]# vim zabbix_agent.sls
zabbix-agent-install:
pkg.installed:
- name: zabbix-agent
file.managed:
- name: /etc/zabbix/zabbix_agentd.conf
- source: salt://init/files/zabbix_agentd.conf
- template: jinja
- defaults:
Server: {{ pillar['zabbix-agent']['Zabbix_Server'] }}
- require:
- pkg: zabbix-agent-install
service.running:
- name: zabbix-agent
- enable: True
- watch:
- pkg: zabbix-agent-install
- file: zabbix-agent-install
编写top文件
[root@linux-node1 base]# cd /srv/pillar/base/
[root@linux-node1 base]# vim top.sls
base:
'*':
- zabbix
编写zabbix.sls
[root@linux-node1 base]# vim zabbix.sls
zabbix-agent:
Zabbix_Server: 10.0.0.7
这里对应上面Server: {{ pillar['zabbix-agent']['Zabbix_Server'] }}
配置文件拷贝修改
[root@linux-node1 base]# cd /srv/salt/base/init/files
[root@linux-node1 init]# cp /etc/zabbix/zabbix_agentd.conf .
[root@linux-node1 init]# grep 'Server' zabbix_agentd.conf
Server=` Server ` # 对应上面zabbix_agent.sls中的server
编辑env_init文件
[root@linux-node1 init]# vim env_init.sls
include:
- init.dns
- init.history
- init.audit
- init.sysctl
- init.zabbix_agent
[root@linux-node1 init]# tree /srv/salt/base/init/
/srv/salt/base/init/
├── audit.sls
├── dns.sls
├── env_init.sls
├── files
│ ├── resolv.conf
│ └── zabbix_agentd.conf
├── history.sls
├── sysctl.sls
└── zabbix_agent.sls
另外epel的sls文件
[root@linux-node1 init]# vim epel.sls
yum_repo_release:
pkg.installed:
- sources:
- epel-release: http://mirrors.aliyun.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
- unless: rpm -qa | grep epel-release-6-8
安装libevent
[root@linux-node1 ~]# cd /srv/salt/prod/
[root@linux-node1 prod]# mkdir -pv libevent/files
[root@linux-node1 prod]# cd /srv/salt/prod/libevent
[root@linux-node1 libevent]# vim install.sls
libevent-source-install:
file.managed:
- name: /usr/local/src/libevent-2.0.22-stable.tar.gz
- source: salt://libevent/files/libevent-2.0.22-stable.tar.gz
- user: root
- group: root
- mode: 644
cmd.run:
- name: cd /usr/local/src && tar zxf libevent-2.0.22-stable.tar.gz && cd libevent-2.0.22-stable && ./configure --prefix=/usr/local/libevent && make && make install
- unless: test -d /usr/local/libevent
- require:
- file: libevent-source-install
[root@linux-node1 libevent]# pwd
/srv/salt/prod/libevent
[root@linux-node1 libevent]# tree
.
├── files
│ └── libevent-2.0.22-stable.tar.gz
└── install.sls
[root@linux-node1 files]# salt '*' state.sls libevent.install env=prod
[root@linux-node1 files]# salt '*' state.highstate
本文转自 liqius 51CTO博客,原文链接:http://blog.51cto.com/szgb17/1915232,如需转载请自行联系原作者