使用saltstack部署zabbix agent

使用saltstack部署zabbix agent

使用saltstack部署zabbix agent

使用saltstack部署zabbix agent

环境:

master:121.40.28.126
client:121.41.118.184

客户端安装配置

1.安装saltstack 客户端以及修改配置文件  
[root@zy_mongo02 ~]# yum -y install salt-minion  

查看zabbix模块结构

[root@srv-zy-ops salt]# tree zabbix/
zabbix/
├── config.sls
├── file
│   ├── zabbix-2.4.zip   ###包需要自己去下载
│   ├── zabbix_agentd
│   └── zabbix_agentd.conf
├── init.sls
└── install.sls

1 directory, 6 files
[root@srv-zy-ops salt]#

查看top.sls配置文件

[root@srv-zy-ops salt]# cat top.sls
base:
'*':
    - zabbix.install
    - zabbix.config
[root@srv-zy-ops salt]#

查看zabbix install 模块配置文件

PS:我在这里为了做测试所以用的版本较新,可以根据自己的业务版本来。
[root@srv-zy-ops zabbix]# cat install.sls
### install source zabbix agent
zabbix_source:
file.managed:
    - name: /tmp/zabbix-2.4.zip
    - unless: test -e /tmp/zabbix-2.4.zip
    - source: salt://zabbix/file/zabbix-2.4.zip

### tar zabbix agent
extract_zabbix:
cmd.run:
    - cwd: /usr/local
    - name: 'unzip /tmp/zabbix-2.4.zip'
    - unless: test -d /usr/local/zabbix
- require:
    - file: zabbix_source


### adduser for zabbix agent
zabbix_user:
user.present:
- name: zabbix
- createhome: False
- gid_from_name: True
- shell: /sbin/nologin
[root@srv-zy-ops zabbix]#

查看zabbix config模块配置文件

[root@srv-zy-ops zabbix]# cat config.sls
include:
  - zabbix.install
### zabbix agent config
config:
file.managed:
  - name: /usr/local/zabbix/etc/zabbix_agentd.conf
  - source: salt://zabbix/file/zabbix_agentd.conf
  - template: jinja
  - defaults:
    Hostname: {{ grains['host'] }}

### zabbix init config
script:
file.managed:
  - name: /etc/init.d/zabbix_agentd
  - user: root
  - mode: 755
  - source: salt://zabbix/file/zabbix_agentd
cmd.run:
  - names:
  - /sbin/chkconfig --add zabbix_agentd
  - /sbin/chkconfig --level 35 zabbix_agentd on
  - unless: /sbin/chkconfig --list zabbix_agentd
service.running:
  - name: zabbix_agentd
  - enable: True
  - restart: True
  - watch:
    - file: /usr/local/zabbix/etc/zabbix_agentd.conf
[root@srv-zy-ops zabbix]#

查看zabbix主配置文件 这个文件根据自己的需求去定义

less zabbix/file/zabbix_agentd.conf
Server=121.40.28.126   zabbi服务器的IP地址

### Option: Hostname
# Unique, case sensitive hostname.
# Required for active checks and must match hostname 	as configured on the server.
# Value is acquired from HostnameItem if undefined.
#
# Mandatory: no
# Default:
# Hostname=

Hostname={{ grains['host'] }}   需要和grains模块的文件结	合使用

### Option: HostnameItem
# Item used for generating Hostname if it 
iundefined. Ignored if Hostname is defined.
# Does not support UserParameters or aliases.
#
# Mandatory: no
# Default:
# HostnameItem=system.hostname

测试

[root@srv-zy-ops salt]# salt zy_mongo02 state.highstate test=True 如果没有问题去掉"test=True"执行就好了
[root@srv-zy-ops salt]#

客户端查看

[root@srv-zy-ops salt]# salt zy_mongo02 cmd.run '/etc/rc.d/init.d/zabbix_agentd status'
zy_mongo02:
zabbix_agentd (pid 3439 3438 3437 3436 3435 3434) is running...
[root@srv-zy-ops salt]#

See also