设为首页 收藏本站
查看: 1711|回复: 0

[经验分享] saltstack的深入-配置zabbix所需的server,web,agent

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-8-14 08:58:01 | 显示全部楼层 |阅读模式
saltstack的深入-配置zabbix所需的server,web,agent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
操作内容:
一、基础环境
1、使用tvm-cobbler安装一个tvm-zabbix虚拟机来做实验。在“配置zabbix所需的mysql-server”的基础上继续操作
2、网络:
eth0:host-only(用于虚拟内网,手动固定IP,这样从宿主机可以直接连接到这个vm)
eth1:NAT(用于上外网,动态IP)
[iyunv@tvm-zabbix ~]# cd /etc/sysconfig/network-scripts/
[iyunv@tvm-zabbix network-scripts]# cat ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.56.200
PREFIX=24
GATEWAY=192.168.56.1
DNS1=192.168.56.254

[iyunv@tvm-zabbix network-scripts]# cat ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
DNS1=192.168.56.254

[iyunv@tvm-zabbix ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        36G  1.8G   32G   6% /
tmpfs           499M   12K  499M   1% /dev/shm
/dev/sda1       194M   29M  155M  16% /boot
/dev/sdb1        99G  188M   94G   1% /data


使用域名:
[iyunv@tvm-yum ~]# cat /etc/dnsmasq.d/office.conf |grep zbx-m
address=/zbx-m.office.test/192.168.56.200

3、repo
我们在自己的office这个repo中已经增加了几个rpm包:
[iyunv@tvm-zabbix ~]# yum search --disablerepo='*' --enablerepo='office' zabbix                     
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
======================================================================================= N/S Matched: zabbix ========================================================================================
percona-zabbix-templates.noarch : Percona Monitoring Plugins for Zabbix
zabbix-agent.x86_64 : Zabbix Agent
zabbix-get.x86_64 : Zabbix Get
zabbix-java-gateway.x86_64 : Zabbix java gateway
zabbix-sender.x86_64 : Zabbix Sender
zabbix-server.x86_64 : Zabbix server common files
zabbix-server-mysql.x86_64 : Zabbix server compiled to use MySQL database
zabbix-web.noarch : Zabbix Web Frontend
zabbix-web-mysql.noarch : Zabbix web frontend for MySQL
zabbix.x86_64 : Enterprise-class open source distributed monitoring solution.

  Name and summary matches only, use "search all" for everything.


二、配置
1、文件结构
[iyunv@tvm-saltmaster base]# tree zabbix/
zabbix/
├── agent.sls
├── server.sls
└── web.sls

0 directories, 3 files

[iyunv@tvm-saltmaster base]# tree conf.d/zabbix/
conf.d/zabbix/
├── httpd_zabbix.conf
├── php_zabbix.ini
├── README.txt
├── scripts
│?? ├── check_conn.py
│?? └── nginx_status
├── tpl.zabbix_agentd.conf
├── tpl.zabbix_server.conf
├── zabbix_agentd.conf
├── zabbix_agentd.d
│?? ├── userparameter_default.conf
│?? ├── userparameter_dell.conf
│?? ├── userparameter_nginx.conf
└── zabbix_server.conf

2 directories, 13 files


2、sls配置
1)init
===================================================init
[iyunv@tvm-saltmaster base]# cat zabbix/init.sls
include:
  - agent
===================================================init end

2)server
===================================================server
[iyunv@tvm-saltmaster base]# cat zabbix/server.sls
## 安装mysql db for zabbix, zabbix-server
#
# via pc @ 2015/8/13

zabbix-server-mysql-create:
  cmd.run:
## for zabbix db
# mysql> create database zabbix character set utf8 collate utf8_bin;
# msyql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
    - onlyif: s_zbx_pwd='zabbix'; zbx_tables=$(mysql -uzabbix -p${s_zbx_pwd} -e 'use zabbix;show tables;' |wc -l); test $zbx_tables -eq 0;
    - name: cd /usr/share/doc/zabbix-server-mysql-2.4.6/create/;
        s_zbx_pwd='zabbix';
        mysql -uzabbix -p${s_zbx_pwd} zabbix <schema.sql;
        mysql -uzabbix -p${s_zbx_pwd} zabbix <images.sql;
        mysql -uzabbix -p${s_zbx_pwd} zabbix <data.sql;


zabbix-server-mysql:
  pkg.installed:
## for local-office.repo
#
    - fromrepo: office,epel,base
    - name: zabbix-server-mysql
    - skip_verify: True
    - refresh: True
    - require_in:
      - file: /etc/zabbix/zabbix_server.conf
  service.running:
    - name: zabbix-server
    - enable: True
    - restart: True
    - watch:
      - file: zabbix-server-conf
    - requires:
      - pkg: zabbix-server-mysql


zabbix-server-conf:
  file.managed:
    - name: /etc/zabbix/zabbix_server.conf
    - source: salt://conf.d/zabbix/zabbix_server.conf
    - template: jinja


## for iptables
zabbix-10051:
  cmd.run:
    - unless: grep 'zabbix-server added' /etc/sysconfig/iptables
    - name:
        sed -i
        '/-A INPUT -i lo -j ACCEPT/a\## zabbix-server added.
        \n-A INPUT -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPT
        \n-A INPUT -p udp -m state --state NEW -m udp --dport 10051 -j ACCEPT
        ' /etc/sysconfig/iptables

zabbix-10051-tcp:
  cmd.run:
    - unless: /sbin/iptables -nL |grep 'tcp dpt:10051'
    - name: /sbin/iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPT

zabbix-10051-udp:
  cmd.run:
    - unless: /sbin/iptables -nL |grep 'udp dpt:10051'
    - name: /sbin/iptables -I INPUT -p udp -m state --state NEW -m udp --dport 10051 -j ACCEPT

===================================================server end

3)web
===================================================web
[iyunv@tvm-saltmaster base]# cat zabbix/web.sls
## 安装zabbix-web-mysql
#
# via pc @ 2015/8/13

zabbix-web-mysql:
  pkg.installed:
## for local-office.repo
#
    - fromrepo: office,epel,base
    - name: zabbix-web-mysql
    - skip_verify: True
    - refresh: True
  service.running:
    - name: httpd
    - enable: True
    - reload: True
    - watch:
      - file: zabbix-web-conf
      - file: zabbix-web-php
    - requires:
      - pkg: zabbix-web-mysql

zabbix-web-conf:
  file.managed:
    - name: /etc/httpd/conf.d/zabbix.conf
    - source: salt://conf.d/zabbix/httpd_zabbix.conf
    - requires:
      - pkg: zabbix-web-mysql

zabbix-web-php:
  file.managed:
    - name: /etc/php.ini
    - source: salt://conf.d/zabbix/php_zabbix.ini
    - requires:
      - pkg: zabbix-web-mysql

## for iptables
zabbix-80:
  cmd.run:
    - unless: grep 'zabbix-web added' /etc/sysconfig/iptables
    - name:
        sed -i
        '/-A INPUT -i lo -j ACCEPT/a\## zabbix-web added.
        \n-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
        ' /etc/sysconfig/iptables
    - requires:
      - pkg: zabbix-web-mysql

zabbix-80-tcp:
  cmd.run:
    - unless: /sbin/iptables -nL |grep 'tcp dpt:80'
    - name: /sbin/iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
    - requires:
      - pkg: zabbix-web-mysql

===================================================web end

4)agent
===================================================agent
[iyunv@tvm-saltmaster base]# cat zabbix/agent.sls
## 安装zabbix-agent
#
# via pc @ 2015/8/13

zabbix-agent:
  pkg.installed:
## for local-office.repo
#
    - fromrepo: office
    - name: zabbix-agent
    - skip_verify: True
    - refresh: True
    - require_in:
      - file: zabbix-agent-conf
      - file: zabbix-agent-dir
      - file: zabbix-agent-scripts
      - file: zabbix-agent-conf-mysql
      - file: zabbix-agent-conf-monit
## remove origin file: userparameter_mysql.conf
  file.absent:
    - name: /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
  service.running:
    - name: zabbix-agent
    - enable: True
    - restart: True
    - watch:
      - file: /etc/zabbix/zabbix_agentd.conf
      - file: /etc/zabbix/zabbix_agentd.d
    - requires:
      - pkg: zabbix-agent

zabbix-agent-conf:
  file.managed:
    - name: /etc/zabbix/zabbix_agentd.conf
    - source: salt://conf.d/zabbix/zabbix_agentd.conf
    - template: jinja

zabbix-agent-dir:
  file.directory:
    - name: /etc/zabbix/zabbix_agentd.d
    - source: salt://conf.d/zabbix/zabbix_agentd.d/
    - mkdirs: True

zabbix-agent-scripts:
  file.directory:
    - name: /etc/zabbix/scripts
    - source: salt://conf.d/zabbix/scripts/
    - mkdirs: True

zabbix-agent-conf-mysql:
## make symlink to: userparameter_mysql.conf
  file.symlink:
    - onlyif: test -f /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf
    - name: /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
    - target: /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf

zabbix-agent-conf-monit:
  file.managed:
    - name: /etc/monit.d/zabbix-agent.conf
    - source: salt://conf.d/monit/zabbix-agent.conf



## for iptables
zabbix-10050:
  cmd.run:
    - unless: grep 'zabbix-agent added' /etc/sysconfig/iptables
    - name:
        sed -i
        '/-A INPUT -i lo -j ACCEPT/a\## zabbix-agent added.
        \n-A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
        \n-A INPUT -p udp -m state --state NEW -m udp --dport 10050 -j ACCEPT
        ' /etc/sysconfig/iptables

zabbix-10050-tcp:
  cmd.run:
    - unless: /sbin/iptables -nL |grep 'tcp dpt:10050'
    - name: /sbin/iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT

zabbix-10050-udp:
  cmd.run:
    - unless: /sbin/iptables -nL |grep 'udp dpt:10050'
    - name: /sbin/iptables -I INPUT -p udp -m state --state NEW -m udp --dport 10050 -j ACCEPT

===================================================agent end

3、conf配置
1)README.txt
===================================================README.txt
[iyunv@tvm-saltmaster base]# cat conf.d/zabbix/README.txt
# 简化配置文件:
grep ^[^#] tpl.zabbix_agentd.conf >zabbix_agentd.conf
grep ^[^#] tpl.zabbix_server.conf >zabbix_server.conf
===================================================README.txt end
2)httpd_zabbix.conf
对比默认文件,仅修改了timezone这行:
php_value date.timezone Asia/Shanghai
附上完整的配置:
===================================================httpd_zabbix.conf
[iyunv@tvm-saltmaster base]# cat conf.d/zabbix/httpd_zabbix.conf
#
# Zabbix monitoring system php web frontend
#

Alias /zabbix /usr/share/zabbix

<Directory "/usr/share/zabbix">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all

    php_value max_execution_time 300
    php_value memory_limit 128M
    php_value post_max_size 16M
    php_value upload_max_filesize 2M
    php_value max_input_time 300
    php_value date.timezone Asia/Shanghai
</Directory>

<Directory "/usr/share/zabbix/conf">
    Order deny,allow
    Deny from all
    <files *.php>
        Order deny,allow
        Deny from all
    </files>
</Directory>

<Directory "/usr/share/zabbix/api">
    Order deny,allow
    Deny from all
    <files *.php>
        Order deny,allow
        Deny from all
    </files>
</Directory>

<Directory "/usr/share/zabbix/include">
    Order deny,allow
    Deny from all
    <files *.php>
        Order deny,allow
        Deny from all
    </files>
</Directory>

<Directory "/usr/share/zabbix/include/classes">
    Order deny,allow
    Deny from all
    <files *.php>
        Order deny,allow
        Deny from all
    </files>
</Directory>
===================================================httpd_zabbix.conf end

3)php_zabbix.ini
和昨天配置mysql时用到的一致。
===================================================php_zabbix.ini end
[iyunv@tvm-saltmaster base]# cat conf.d/zabbix/php_zabbix.ini |grep -E 'timezone|mysql.sock' |grep -v ';'
date.timezone = Asia/Shanghai
mysql.default_socket = /data/mysql/mysql.sock
mysqli.default_socket = /data/mysql/mysql.sock
===================================================php_zabbix.ini end

4)zabbix_agentd.conf
===================================================zabbix_agentd.conf
[iyunv@tvm-saltmaster base]# cat conf.d/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=5
Server=zbx-m.office.test
ListenIP={{ grains['ip_interfaces']['eth0'][0] }}
ServerActive=zbx-m.office.test
Hostname={{ grains['id'] }}
Include=/etc/zabbix/zabbix_agentd.d/
UnsafeUserParameters=1
===================================================zabbix_agentd.conf end

5)zabbix_server.conf
===================================================zabbix_server.conf
[iyunv@tvm-saltmaster base]# cat conf.d/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=10
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/data/mysql/mysql.sock
DBPort=3306
SNMPTrapperFile=/var/log/snmptt/snmptt.log
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
===================================================zabbix_server.conf end



三、执行
[iyunv@tvm-saltmaster base]# salt 'tvm-zabbix' state.sls zabbix.server --output-file='/tmp/z1.log'
[iyunv@tvm-saltmaster base]# salt 'tvm-zabbix' state.sls zabbix.web --output-file='/tmp/z2.log'
[iyunv@tvm-saltmaster base]# salt 'tvm-zabbix' state.sls zabbix.agent --output-file='/tmp/z3.log'



四、配置zabbix-web
1、访问:
http://192.168.56.200/zabbix
根据引导一步步操作,然后登录web页面。

2、我们来使用下“Active agent auto-registration”的功能
1)configuration-action页面,找到右上方“Create action”下面有个下拉框“Event Source”,选择:“Auto registration”
2)点击“Create action”创建一个动作
3)在“Action”选项卡输入一个“Name”:test auto registration
4)在“Conditions”选项卡新增一个条件:Host name like tvm
5)在“Operations”选项卡新增操作:
Add to host groups: Linux servers
Link to templates: Template OS Linux

保存。


ZYXW、参考
1、老大提供的saltstack相关资料。
2、zabbix doc
https://www.zabbix.com/documenta ... rprise_linux_centos
https://www.zabbix.com/documenta ... y/auto_registration



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-98768-1-1.html 上篇帖子: saltstack初探 下篇帖子: saltstack的深入-管理python-pip server
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表