小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程

zabbix监控nginx

a机器:zabbix服务端(192.168.234.128) b机器:zabbix客户端(192.168.234.125)

在b机器(zabbix客户端)操作:

编辑nginx虚拟主机配置文件:

?
1
[root@centos ~]# vi /etc/nginx/conf.d/default.conf

在server{}中添加以下内容:

?
1
2
3
4
5
6
7
location /nginx_status
{
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}

重载nginx配置:

?
1
[root@centos ~]# nginx -s reload

测试:

?
1
2
3
4
5
[root@centos ~]# curl http://127.0.0.1/nginx_status
active connections: 1
server accepts handled requests
3 3 3
reading: 0 writing: 1 waiting: 0

#nginx状态信息已显示

状态说明:

%小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程-猿站网-插图

添加监控脚本:

?
1
vi /usr/local/sbin/ngx_status.sh

添加以下内容:

?
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
#!/bin/bash
url=”http://127.0.0.1/nginx_status”
curl=/usr/bin/curl
# 检测nginx进程是否存在
function ping {
/sbin/pidof nginx | wc -l
}
# 检测nginx性能
function active {
$curl $url 2>/dev/null| grep active | awk {print $nf}
}
function reading {
$curl $url 2>/dev/null| grep reading | awk {print $2}
}
function writing {
$curl $url 2>/dev/null| grep writing | awk {print $4}
}
function waiting {
$curl $url 2>/dev/null| grep waiting | awk {print $6}
}
function accepts {
$curl $url 2>/dev/null| awk nr==3 | awk {print $1}
}
function handled {
$curl $url 2>/dev/null| awk nr==3 | awk {print $2}
}
function requests {
$curl $url 2>/dev/null| awk nr==3 | awk {print $3}
}
$1

添加权限:

?
1
[root@centos ~]# chmod 755 /usr/local/sbin/ngx_status.sh

编辑zabbix_agent配置文件:

?
1
[root@centos ~]# vi /etc/zabbix/zabbix_agentd.conf

在option:userparameter处添加:userparameter=nginx.status[*],/usr/local/sbin/ngx_status.sh $1

%小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程-1猿站网-插图

重启服务:

?
1
[root@centos ~]# systemctl restart zabbix-agent

在a机器(服务端)测试:

?
1
2
[root@zabbix ~]# zabbix_get -s 192.168.234.125 -k nginx.status[accepts]
6

在本机创建.xml文件并添加以下内容:(文件名称自定义)

?
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
<?xml version=”1.0″ encoding=”utf-8″?>
<zabbix_export>
<version>4.0</version>
<date>2019-02-11t07:29:29z</date>
<groups>
<group>
<name>templates</name>
</group>
</groups>
<templates>
<template>
<template>template app nginx</template>
<name>template app nginx</name>
<description/>
<groups>
<group>
<name>templates</name>
</group>
</groups>
<applications>
<application>
<name>nginx</name>
</application>
</applications>
<items>
<item>
<name>nginx status server accepts</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>nginx.status[accepts]</key>
<delay>60</delay>
<history>90d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description>accepts</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>nginx</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>10</type>
<params/>
</step>
</preprocessing>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<master_item/>
</item>
<item>
<name>nginx status connections active</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>nginx.status[active]</key>
<delay>60</delay>
<history>90d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description>active</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>nginx</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<master_item/>
</item>
<item>
<name>nginx status server handled</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>nginx.status[handled]</key>
<delay>60</delay>
<history>90d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description>handled</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>nginx</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>10</type>
<params/>
</step>
</preprocessing>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<master_item/>
</item>
<item>
<name>nginx status ping</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>nginx.status[ping]</key>
<delay>60</delay>
<history>30d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description>is live</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>nginx</name>
</application>
</applications>
<valuemap>
<name>service state</name>
</valuemap>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<master_item/>
</item>
<item>
<name>nginx status connections reading</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>nginx.status[reading]</key>
<delay>60</delay>
<history>90d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description>reading</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>nginx</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<master_item/>
</item>
<item>
<name>nginx status server requests</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>nginx.status[requests]</key>
<delay>60</delay>
<history>90d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description>requests</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>nginx</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing>
<step>
<type>10</type>
<params/>
</step>
</preprocessing>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<master_item/>
</item>
<item>
<name>nginx status connections waiting</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>nginx.status[waiting]</key>
<delay>60</delay>
<history>90d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description>waiting</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>nginx</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<master_item/>
</item>
<item>
<name>nginx status connections writing</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>nginx.status[writing]</key>
<delay>60</delay>
<history>90d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description>writing</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>nginx</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<timeout>3s</timeout>
<url/>
<query_fields/>
<posts/>
<status_codes>200</status_codes>
<follow_redirects>1</follow_redirects>
<post_type>0</post_type>
<http_proxy/>
<headers/>
<retrieve_mode>0</retrieve_mode>
<request_method>0</request_method>
<output_format>0</output_format>
<allow_traps>0</allow_traps>
<ssl_cert_file/>
<ssl_key_file/>
<ssl_key_password/>
<verify_peer>0</verify_peer>
<verify_host>0</verify_host>
<master_item/>
</item>
</items>
<discovery_rules/>
<httptests/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
<triggers>
<trigger>
<expression>{template app nginx:nginx.status[ping].last()}=0</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>nginx was down!</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>4</priority>
<description>nginx进程数:0,请注意</description>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger>
</triggers>
<graphs>
<graph>
<name>nginx status connections</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>1</show_work_period>
<show_triggers>1</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>0</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>0</drawtype>
<color>00c800</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>template app nginx</host>
<key>nginx.status[active]</key>
</item>
</graph_item>
<graph_item>
<sortorder>1</sortorder>
<drawtype>0</drawtype>
<color>c80000</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>template app nginx</host>
<key>nginx.status[reading]</key>
</item>
</graph_item>
<graph_item>
<sortorder>2</sortorder>
<drawtype>0</drawtype>
<color>0000c8</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>template app nginx</host>
<key>nginx.status[waiting]</key>
</item>
</graph_item>
<graph_item>
<sortorder>3</sortorder>
<drawtype>0</drawtype>
<color>c800c8</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>template app nginx</host>
<key>nginx.status[writing]</key>
</item>
</graph_item>
</graph_items>
</graph>
<graph>
<name>nginx status server</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>1</show_work_period>
<show_triggers>1</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>0</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>0</drawtype>
<color>00c800</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>template app nginx</host>
<key>nginx.status[accepts]</key>
</item>
</graph_item>
<graph_item>
<sortorder>1</sortorder>
<drawtype>0</drawtype>
<color>c80000</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>template app nginx</host>
<key>nginx.status[handled]</key>
</item>
</graph_item>
<graph_item>
<sortorder>2</sortorder>
<drawtype>0</drawtype>
<color>0000c8</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>template app nginx</host>
<key>nginx.status[requests]</key>
</item>
</graph_item>
</graph_items>
</graph>
</graphs>
<value_maps>
<value_map>
<name>service state</name>
<mappings>
<mapping>
<value>0</value>
<newvalue>down</newvalue>
</mapping>
<mapping>
<value>1</value>
<newvalue>up</newvalue>
</mapping>
</mappings>
</value_map>
</value_maps>
</zabbix_export>

在zabbix前端页面点击配置→模板→导入:

%小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程-2猿站网-插图

#导入刚才创建的xml文件即可

导入成功后在主机列表页面选择被监控的机器(b机器)链接该模板即可开始监控nginx

zabbix监控tomcat

a机器:zabbix服务端(192.168.234.128) b机器:zabbix客户端(192.168.234.125)

在a机器安装zabbix-java-gateway:

?
1
2
3
[root@zabbix ~]# wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-java-gateway-4.0.14-1.el7.x86_64.rpm
[root@zabbix ~]# yum -y localinstall zabbix-java-gateway-4.0.14-1.el7.x86_64.rpm

编辑gateway配置文件:

?
1
[root@zabbix ~]# vi /etc/zabbix/zabbix_java_gateway.conf

去掉listen_ip、listen_port(监听端口)、start_pollers(进程数)的注释符号#:

%小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程-3猿站网-插图

#listen_ip定义被监控机器的地址,不指定默认监听全部机器

编辑server配置文件:

?
1
[root@zabbix ~]# vi /etc/zabbix/zabbix_server.conf

定义以下3个配置参数:

%小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程-4猿站网-插图

启动zabbix-java-gateway服务:

?
1
[root@zabbix ~]# systemctl start zabbix-java-gateway

重启zabbix-server服务:

?
1
[root@zabbix ~]# systemctl restart zabbix-server

查看监听端口:

?
1
2
[root@zabbix ~]# netstat -lntp |grep java
tcp6  0  0 :::10052    :::*     listen  8706/java

开启jmx

在b机器编辑tomcat配置文件:

?
1
[root@centos ~]# vi /usr/local/tomcat/bin/catalina.sh

添加以下内容:

?
1
2
3
4
5
export catalina_opts=”$catalina_opts -dcom.sun.management.jmxremote
-djava.rmi.server.hostname=192.168.234.125
-dcom.sun.management.jmxremote.port=9999
-dcom.sun.management.jmxremote.ssl=false
-dcom.sun.management.jmxremote.authenticate=false”

#hostname定义b机器地址,端口9999(默认12345)

重启tomcat:

?
1
2
3
[root@centos ~]# /usr/local/tomcat/bin/shutdown.sh
[root@centos ~]# /usr/local/tomcat/bin/startup.sh

查看监听端口9999:

?
1
2
[root@centos ~]# netstat -lntp |grep 9999
tcp6  0  0 :::9999     :::*     listen  25861/java

进入zabbix前端页面添加主机:

%小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程-5猿站网-插图

#与普通情况添加监控主机不同,监控b机器的tomcat需要配置jmx接口

模板链接jmx相关的两个模板:

%小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程-6猿站网-插图

当jmx图标变绿即表示配置成功:

%小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程-7猿站网-插图

zabbix监控mysql

a机器:zabbix服务端(192.168.234.128) b机器:zabbix客户端(192.168.234.125)

zabbix_agent定义mysql监控的配置文件:/etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf

在b机器登录mysql创建用户:

?
1
mysql> grant usage,process,replication client on *.* to zamysql@localhost identified by zamysql;

创建配置文件指定的目录:

?
1
[root@centos ~]# mkdir /var/lib/zabbix

创建my.cnf文件:

?
1
[root@centos ~]# vi /var/lib/zabbix/.my.cnf

#需要注意该文件是隐藏文件

添加以下内容:

?
1
2
3
4
5
6
7
8
9
10
11
[mysql]
host=localhost
user=zamysql
password=zamysql
socket=/tmp/mysql.sock
[mysqladmin]
host=localhost
user=zamysql
password=zamysql
socket=/tmp/mysql.sock

在a机器测试:

?
1
2
3
4
5
6
[root@zabbix ~]# zabbix_get -s 192.168.234.125 -p 10050 -k mysql.ping
1
[root@zabbix ~]# zabbix_get -s 192.168.234.125 -p 10050 -k mysql.version
mysql ver 14.14 distrib 5.6.43, for linux-glibc2.12 (x86_64) using editline wrapper
[root@zabbix ~]# zabbix_get -s 192.168.234.125 -p 10050 -k mysql.size
10240

#已成功获取数据

在zabbix前端页面添加主机:

%小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程-8猿站网-插图

监控模板选择db mysql:

%小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程-9猿站网-插图

zbx标准变为绿色表示成功:

%小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程-10猿站网-插图

在监测→最新数据页面即可查看mysql监控数据:

%小知识:zabbix监控Nginx/Tomcat/MySQL的详细教程-11猿站网-插图

总结

以上所述是小编给大家介绍的zabbix监控nginx/tomcat/mysql的详细教程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:Zabbix3.4监控mongodb数据库状态的方法

2023-3-21 15:44:21

建站知识

小知识:zabbix redis自动发现端口的脚本返回json格式

2023-3-21 15:59:21

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索