系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > server > anz > 详细页面

zabbix监控Nginx/Tomcat/MySQL的详细教程

时间:2019-12-10来源:系统城作者:电脑系统城

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. location /nginx_status
  2. {
  3. stub_status on;
  4. access_log off;
  5. allow 127.0.0.1;
  6. deny all;
  7. }

 

重载nginx配置:


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

测试:


 
  1. [root@centos ~]# curl http://127.0.0.1/nginx_status
  2. Active connections: 1
  3. server accepts handled requests
  4. 3 3 3
  5. Reading: 0 Writing: 1 Waiting: 0

#nginx状态信息已显示

状态说明:

添加监控脚本:


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

添加以下内容:


 
  1. #!/bin/bash
  2. url="http://127.0.0.1/nginx_status"
  3. curl=/usr/bin/curl
  4.  
  5. # 检测nginx进程是否存在
  6. function ping {
  7. /sbin/pidof nginx | wc -l
  8. }
  9. # 检测nginx性能
  10. function active {
  11. $curl $url 2>/dev/null| grep 'Active' | awk '{print $NF}'
  12. }
  13. function reading {
  14. $curl $url 2>/dev/null| grep 'Reading' | awk '{print $2}'
  15. }
  16. function writing {
  17. $curl $url 2>/dev/null| grep 'Writing' | awk '{print $4}'
  18. }
  19. function waiting {
  20. $curl $url 2>/dev/null| grep 'Waiting' | awk '{print $6}'
  21. }
  22. function accepts {
  23. $curl $url 2>/dev/null| awk NR==3 | awk '{print $1}'
  24. }
  25. function handled {
  26. $curl $url 2>/dev/null| awk NR==3 | awk '{print $2}'
  27. }
  28. function requests {
  29. $curl $url 2>/dev/null| awk NR==3 | awk '{print $3}'
  30. }
  31. $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

在这里插入图片描述

重启服务:


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

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


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

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


 
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <zabbix_export>
  3. <version>4.0</version>
  4. <date>2019-02-11T07:29:29Z</date>
  5. <groups>
  6. <group>
  7. <name>Templates</name>
  8. </group>
  9. </groups>
  10. <templates>
  11. <template>
  12. <template>Template App NGINX</template>
  13. <name>Template App NGINX</name>
  14. <description/>
  15. <groups>
  16. <group>
  17. <name>Templates</name>
  18. </group>
  19. </groups>
  20. <applications>
  21. <application>
  22. <name>nginx</name>
  23. </application>
  24. </applications>
  25. <items>
  26. <item>
  27. <name>nginx status server accepts</name>
  28. <type>0</type>
  29. <snmp_community/>
  30. <snmp_oid/>
  31. <key>nginx.status[accepts]</key>
  32. <delay>60</delay>
  33. <history>90d</history>
  34. <trends>365d</trends>
  35. <status>0</status>
  36. <value_type>3</value_type>
  37. <allowed_hosts/>
  38. <units/>
  39. <snmpv3_contextname/>
  40. <snmpv3_securityname/>
  41. <snmpv3_securitylevel>0</snmpv3_securitylevel>
  42. <snmpv3_authprotocol>0</snmpv3_authprotocol>
  43. <snmpv3_authpassphrase/>
  44. <snmpv3_privprotocol>0</snmpv3_privprotocol>
  45. <snmpv3_privpassphrase/>
  46. <params/>
  47. <ipmi_sensor/>
  48. <authtype>0</authtype>
  49. <username/>
  50. <password/>
  51. <publickey/>
  52. <privatekey/>
  53. <port/>
  54. <description>accepts</description>
  55. <inventory_link>0</inventory_link>
  56. <applications>
  57. <application>
  58. <name>nginx</name>
  59. </application>
  60. </applications>
  61. <valuemap/>
  62. <logtimefmt/>
  63. <preprocessing>
  64. <step>
  65. <type>10</type>
  66. <params/>
  67. </step>
  68. </preprocessing>
  69. <jmx_endpoint/>
  70. <timeout>3s</timeout>
  71. <url/>
  72. <query_fields/>
  73. <posts/>
  74. <status_codes>200</status_codes>
  75. <follow_redirects>1</follow_redirects>
  76. <post_type>0</post_type>
  77. <http_proxy/>
  78. <headers/>
  79. <retrieve_mode>0</retrieve_mode>
  80. <request_method>0</request_method>
  81. <output_format>0</output_format>
  82. <allow_traps>0</allow_traps>
  83. <ssl_cert_file/>
  84. <ssl_key_file/>
  85. <ssl_key_password/>
  86. <verify_peer>0</verify_peer>
  87. <verify_host>0</verify_host>
  88. <master_item/>
  89. </item>
  90. <item>
  91. <name>nginx status connections active</name>
  92. <type>0</type>
  93. <snmp_community/>
  94. <snmp_oid/>
  95. <key>nginx.status[active]</key>
  96. <delay>60</delay>
  97. <history>90d</history>
  98. <trends>365d</trends>
  99. <status>0</status>
  100. <value_type>3</value_type>
  101. <allowed_hosts/>
  102. <units/>
  103. <snmpv3_contextname/>
  104. <snmpv3_securityname/>
  105. <snmpv3_securitylevel>0</snmpv3_securitylevel>
  106. <snmpv3_authprotocol>0</snmpv3_authprotocol>
  107. <snmpv3_authpassphrase/>
  108. <snmpv3_privprotocol>0</snmpv3_privprotocol>
  109. <snmpv3_privpassphrase/>
  110. <params/>
  111. <ipmi_sensor/>
  112. <authtype>0</authtype>
  113. <username/>
  114. <password/>
  115. <publickey/>
  116. <privatekey/>
  117. <port/>
  118. <description>active</description>
  119. <inventory_link>0</inventory_link>
  120. <applications>
  121. <application>
  122. <name>nginx</name>
  123. </application>
  124. </applications>
  125. <valuemap/>
  126. <logtimefmt/>
  127. <preprocessing/>
  128. <jmx_endpoint/>
  129. <timeout>3s</timeout>
  130. <url/>
  131. <query_fields/>
  132. <posts/>
  133. <status_codes>200</status_codes>
  134. <follow_redirects>1</follow_redirects>
  135. <post_type>0</post_type>
  136. <http_proxy/>
  137. <headers/>
  138. <retrieve_mode>0</retrieve_mode>
  139. <request_method>0</request_method>
  140. <output_format>0</output_format>
  141. <allow_traps>0</allow_traps>
  142. <ssl_cert_file/>
  143. <ssl_key_file/>
  144. <ssl_key_password/>
  145. <verify_peer>0</verify_peer>
  146. <verify_host>0</verify_host>
  147. <master_item/>
  148. </item>
  149. <item>
  150. <name>nginx status server handled</name>
  151. <type>0</type>
  152. <snmp_community/>
  153. <snmp_oid/>
  154. <key>nginx.status[handled]</key>
  155. <delay>60</delay>
  156. <history>90d</history>
  157. <trends>365d</trends>
  158. <status>0</status>
  159. <value_type>3</value_type>
  160. <allowed_hosts/>
  161. <units/>
  162. <snmpv3_contextname/>
  163. <snmpv3_securityname/>
  164. <snmpv3_securitylevel>0</snmpv3_securitylevel>
  165. <snmpv3_authprotocol>0</snmpv3_authprotocol>
  166. <snmpv3_authpassphrase/>
  167. <snmpv3_privprotocol>0</snmpv3_privprotocol>
  168. <snmpv3_privpassphrase/>
  169. <params/>
  170. <ipmi_sensor/>
  171. <authtype>0</authtype>
  172. <username/>
  173. <password/>
  174. <publickey/>
  175. <privatekey/>
  176. <port/>
  177. <description>handled</description>
  178. <inventory_link>0</inventory_link>
  179. <applications>
  180. <application>
  181. <name>nginx</name>
  182. </application>
  183. </applications>
  184. <valuemap/>
  185. <logtimefmt/>
  186. <preprocessing>
  187. <step>
  188. <type>10</type>
  189. <params/>
  190. </step>
  191. </preprocessing>
  192. <jmx_endpoint/>
  193. <timeout>3s</timeout>
  194. <url/>
  195. <query_fields/>
  196. <posts/>
  197. <status_codes>200</status_codes>
  198. <follow_redirects>1</follow_redirects>
  199. <post_type>0</post_type>
  200. <http_proxy/>
  201. <headers/>
  202. <retrieve_mode>0</retrieve_mode>
  203. <request_method>0</request_method>
  204. <output_format>0</output_format>
  205. <allow_traps>0</allow_traps>
  206. <ssl_cert_file/>
  207. <ssl_key_file/>
  208. <ssl_key_password/>
  209. <verify_peer>0</verify_peer>
  210. <verify_host>0</verify_host>
  211. <master_item/>
  212. </item>
  213. <item>
  214. <name>nginx status PING</name>
  215. <type>0</type>
  216. <snmp_community/>
  217. <snmp_oid/>
  218. <key>nginx.status[ping]</key>
  219. <delay>60</delay>
  220. <history>30d</history>
  221. <trends>365d</trends>
  222. <status>0</status>
  223. <value_type>3</value_type>
  224. <allowed_hosts/>
  225. <units/>
  226. <snmpv3_contextname/>
  227. <snmpv3_securityname/>
  228. <snmpv3_securitylevel>0</snmpv3_securitylevel>
  229. <snmpv3_authprotocol>0</snmpv3_authprotocol>
  230. <snmpv3_authpassphrase/>
  231. <snmpv3_privprotocol>0</snmpv3_privprotocol>
  232. <snmpv3_privpassphrase/>
  233. <params/>
  234. <ipmi_sensor/>
  235. <authtype>0</authtype>
  236. <username/>
  237. <password/>
  238. <publickey/>
  239. <privatekey/>
  240. <port/>
  241. <description>is live</description>
  242. <inventory_link>0</inventory_link>
  243. <applications>
  244. <application>
  245. <name>nginx</name>
  246. </application>
  247. </applications>
  248. <valuemap>
  249. <name>Service state</name>
  250. </valuemap>
  251. <logtimefmt/>
  252. <preprocessing/>
  253. <jmx_endpoint/>
  254. <timeout>3s</timeout>
  255. <url/>
  256. <query_fields/>
  257. <posts/>
  258. <status_codes>200</status_codes>
  259. <follow_redirects>1</follow_redirects>
  260. <post_type>0</post_type>
  261. <http_proxy/>
  262. <headers/>
  263. <retrieve_mode>0</retrieve_mode>
  264. <request_method>0</request_method>
  265. <output_format>0</output_format>
  266. <allow_traps>0</allow_traps>
  267. <ssl_cert_file/>
  268. <ssl_key_file/>
  269. <ssl_key_password/>
  270. <verify_peer>0</verify_peer>
  271. <verify_host>0</verify_host>
  272. <master_item/>
  273. </item>
  274. <item>
  275. <name>nginx status connections reading</name>
  276. <type>0</type>
  277. <snmp_community/>
  278. <snmp_oid/>
  279. <key>nginx.status[reading]</key>
  280. <delay>60</delay>
  281. <history>90d</history>
  282. <trends>365d</trends>
  283. <status>0</status>
  284. <value_type>3</value_type>
  285. <allowed_hosts/>
  286. <units/>
  287. <snmpv3_contextname/>
  288. <snmpv3_securityname/>
  289. <snmpv3_securitylevel>0</snmpv3_securitylevel>
  290. <snmpv3_authprotocol>0</snmpv3_authprotocol>
  291. <snmpv3_authpassphrase/>
  292. <snmpv3_privprotocol>0</snmpv3_privprotocol>
  293. <snmpv3_privpassphrase/>
  294. <params/>
  295. <ipmi_sensor/>
  296. <authtype>0</authtype>
  297. <username/>
  298. <password/>
  299. <publickey/>
  300. <privatekey/>
  301. <port/>
  302. <description>reading</description>
  303. <inventory_link>0</inventory_link>
  304. <applications>
  305. <application>
  306. <name>nginx</name>
  307. </application>
  308. </applications>
  309. <valuemap/>
  310. <logtimefmt/>
  311. <preprocessing/>
  312. <jmx_endpoint/>
  313. <timeout>3s</timeout>
  314. <url/>
  315. <query_fields/>
  316. <posts/>
  317. <status_codes>200</status_codes>
  318. <follow_redirects>1</follow_redirects>
  319. <post_type>0</post_type>
  320. <http_proxy/>
  321. <headers/>
  322. <retrieve_mode>0</retrieve_mode>
  323. <request_method>0</request_method>
  324. <output_format>0</output_format>
  325. <allow_traps>0</allow_traps>
  326. <ssl_cert_file/>
  327. <ssl_key_file/>
  328. <ssl_key_password/>
  329. <verify_peer>0</verify_peer>
  330. <verify_host>0</verify_host>
  331. <master_item/>
  332. </item>
  333. <item>
  334. <name>nginx status server requests</name>
  335. <type>0</type>
  336. <snmp_community/>
  337. <snmp_oid/>
  338. <key>nginx.status[requests]</key>
  339. <delay>60</delay>
  340. <history>90d</history>
  341. <trends>365d</trends>
  342. <status>0</status>
  343. <value_type>3</value_type>
  344. <allowed_hosts/>
  345. <units/>
  346. <snmpv3_contextname/>
  347. <snmpv3_securityname/>
  348. <snmpv3_securitylevel>0</snmpv3_securitylevel>
  349. <snmpv3_authprotocol>0</snmpv3_authprotocol>
  350. <snmpv3_authpassphrase/>
  351. <snmpv3_privprotocol>0</snmpv3_privprotocol>
  352. <snmpv3_privpassphrase/>
  353. <params/>
  354. <ipmi_sensor/>
  355. <authtype>0</authtype>
  356. <username/>
  357. <password/>
  358. <publickey/>
  359. <privatekey/>
  360. <port/>
  361. <description>requests</description>
  362. <inventory_link>0</inventory_link>
  363. <applications>
  364. <application>
  365. <name>nginx</name>
  366. </application>
  367. </applications>
  368. <valuemap/>
  369. <logtimefmt/>
  370. <preprocessing>
  371. <step>
  372. <type>10</type>
  373. <params/>
  374. </step>
  375. </preprocessing>
  376. <jmx_endpoint/>
  377. <timeout>3s</timeout>
  378. <url/>
  379. <query_fields/>
  380. <posts/>
  381. <status_codes>200</status_codes>
  382. <follow_redirects>1</follow_redirects>
  383. <post_type>0</post_type>
  384. <http_proxy/>
  385. <headers/>
  386. <retrieve_mode>0</retrieve_mode>
  387. <request_method>0</request_method>
  388. <output_format>0</output_format>
  389. <allow_traps>0</allow_traps>
  390. <ssl_cert_file/>
  391. <ssl_key_file/>
  392. <ssl_key_password/>
  393. <verify_peer>0</verify_peer>
  394. <verify_host>0</verify_host>
  395. <master_item/>
  396. </item>
  397. <item>
  398. <name>nginx status connections waiting</name>
  399. <type>0</type>
  400. <snmp_community/>
  401. <snmp_oid/>
  402. <key>nginx.status[waiting]</key>
  403. <delay>60</delay>
  404. <history>90d</history>
  405. <trends>365d</trends>
  406. <status>0</status>
  407. <value_type>3</value_type>
  408. <allowed_hosts/>
  409. <units/>
  410. <snmpv3_contextname/>
  411. <snmpv3_securityname/>
  412. <snmpv3_securitylevel>0</snmpv3_securitylevel>
  413. <snmpv3_authprotocol>0</snmpv3_authprotocol>
  414. <snmpv3_authpassphrase/>
  415. <snmpv3_privprotocol>0</snmpv3_privprotocol>
  416. <snmpv3_privpassphrase/>
  417. <params/>
  418. <ipmi_sensor/>
  419. <authtype>0</authtype>
  420. <username/>
  421. <password/>
  422. <publickey/>
  423. <privatekey/>
  424. <port/>
  425. <description>waiting</description>
  426. <inventory_link>0</inventory_link>
  427. <applications>
  428. <application>
  429. <name>nginx</name>
  430. </application>
  431. </applications>
  432. <valuemap/>
  433. <logtimefmt/>
  434. <preprocessing/>
  435. <jmx_endpoint/>
  436. <timeout>3s</timeout>
  437. <url/>
  438. <query_fields/>
  439. <posts/>
  440. <status_codes>200</status_codes>
  441. <follow_redirects>1</follow_redirects>
  442. <post_type>0</post_type>
  443. <http_proxy/>
  444. <headers/>
  445. <retrieve_mode>0</retrieve_mode>
  446. <request_method>0</request_method>
  447. <output_format>0</output_format>
  448. <allow_traps>0</allow_traps>
  449. <ssl_cert_file/>
  450. <ssl_key_file/>
  451. <ssl_key_password/>
  452. <verify_peer>0</verify_peer>
  453. <verify_host>0</verify_host>
  454. <master_item/>
  455. </item>
  456. <item>
  457. <name>nginx status connections writing</name>
  458. <type>0</type>
  459. <snmp_community/>
  460. <snmp_oid/>
  461. <key>nginx.status[writing]</key>
  462. <delay>60</delay>
  463. <history>90d</history>
  464. <trends>365d</trends>
  465. <status>0</status>
  466. <value_type>3</value_type>
  467. <allowed_hosts/>
  468. <units/>
  469. <snmpv3_contextname/>
  470. <snmpv3_securityname/>
  471. <snmpv3_securitylevel>0</snmpv3_securitylevel>
  472. <snmpv3_authprotocol>0</snmpv3_authprotocol>
  473. <snmpv3_authpassphrase/>
  474. <snmpv3_privprotocol>0</snmpv3_privprotocol>
  475. <snmpv3_privpassphrase/>
  476. <params/>
  477. <ipmi_sensor/>
  478. <authtype>0</authtype>
  479. <username/>
  480. <password/>
  481. <publickey/>
  482. <privatekey/>
  483. <port/>
  484. <description>writing</description>
  485. <inventory_link>0</inventory_link>
  486. <applications>
  487. <application>
  488. <name>nginx</name>
  489. </application>
  490. </applications>
  491. <valuemap/>
  492. <logtimefmt/>
  493. <preprocessing/>
  494. <jmx_endpoint/>
  495. <timeout>3s</timeout>
  496. <url/>
  497. <query_fields/>
  498. <posts/>
  499. <status_codes>200</status_codes>
  500. <follow_redirects>1</follow_redirects>
  501. <post_type>0</post_type>
  502. <http_proxy/>
  503. <headers/>
  504. <retrieve_mode>0</retrieve_mode>
  505. <request_method>0</request_method>
  506. <output_format>0</output_format>
  507. <allow_traps>0</allow_traps>
  508. <ssl_cert_file/>
  509. <ssl_key_file/>
  510. <ssl_key_password/>
  511. <verify_peer>0</verify_peer>
  512. <verify_host>0</verify_host>
  513. <master_item/>
  514. </item>
  515. </items>
  516. <discovery_rules/>
  517. <httptests/>
  518. <macros/>
  519. <templates/>
  520. <screens/>
  521. </template>
  522. </templates>
  523. <triggers>
  524. <trigger>
  525. <expression>{Template App NGINX:nginx.status[ping].last()}=0</expression>
  526. <recovery_mode>0</recovery_mode>
  527. <recovery_expression/>
  528. <name>nginx was down!</name>
  529. <correlation_mode>0</correlation_mode>
  530. <correlation_tag/>
  531. <url/>
  532. <status>0</status>
  533. <priority>4</priority>
  534. <description>NGINX进程数:0,请注意</description>
  535. <type>0</type>
  536. <manual_close>0</manual_close>
  537. <dependencies/>
  538. <tags/>
  539. </trigger>
  540. </triggers>
  541. <graphs>
  542. <graph>
  543. <name>nginx status connections</name>
  544. <width>900</width>
  545. <height>200</height>
  546. <yaxismin>0.0000</yaxismin>
  547. <yaxismax>100.0000</yaxismax>
  548. <show_work_period>1</show_work_period>
  549. <show_triggers>1</show_triggers>
  550. <type>0</type>
  551. <show_legend>1</show_legend>
  552. <show_3d>0</show_3d>
  553. <percent_left>0.0000</percent_left>
  554. <percent_right>0.0000</percent_right>
  555. <ymin_type_1>0</ymin_type_1>
  556. <ymax_type_1>0</ymax_type_1>
  557. <ymin_item_1>0</ymin_item_1>
  558. <ymax_item_1>0</ymax_item_1>
  559. <graph_items>
  560. <graph_item>
  561. <sortorder>0</sortorder>
  562. <drawtype>0</drawtype>
  563. <color>00C800</color>
  564. <yaxisside>0</yaxisside>
  565. <calc_fnc>2</calc_fnc>
  566. <type>0</type>
  567. <item>
  568. <host>Template App NGINX</host>
  569. <key>nginx.status[active]</key>
  570. </item>
  571. </graph_item>
  572. <graph_item>
  573. <sortorder>1</sortorder>
  574. <drawtype>0</drawtype>
  575. <color>C80000</color>
  576. <yaxisside>0</yaxisside>
  577. <calc_fnc>2</calc_fnc>
  578. <type>0</type>
  579. <item>
  580. <host>Template App NGINX</host>
  581. <key>nginx.status[reading]</key>
  582. </item>
  583. </graph_item>
  584. <graph_item>
  585. <sortorder>2</sortorder>
  586. <drawtype>0</drawtype>
  587. <color>0000C8</color>
  588. <yaxisside>0</yaxisside>
  589. <calc_fnc>2</calc_fnc>
  590. <type>0</type>
  591. <item>
  592. <host>Template App NGINX</host>
  593. <key>nginx.status[waiting]</key>
  594. </item>
  595. </graph_item>
  596. <graph_item>
  597. <sortorder>3</sortorder>
  598. <drawtype>0</drawtype>
  599. <color>C800C8</color>
  600. <yaxisside>0</yaxisside>
  601. <calc_fnc>2</calc_fnc>
  602. <type>0</type>
  603. <item>
  604. <host>Template App NGINX</host>
  605. <key>nginx.status[writing]</key>
  606. </item>
  607. </graph_item>
  608. </graph_items>
  609. </graph>
  610. <graph>
  611. <name>nginx status server</name>
  612. <width>900</width>
  613. <height>200</height>
  614. <yaxismin>0.0000</yaxismin>
  615. <yaxismax>100.0000</yaxismax>
  616. <show_work_period>1</show_work_period>
  617. <show_triggers>1</show_triggers>
  618. <type>0</type>
  619. <show_legend>1</show_legend>
  620. <show_3d>0</show_3d>
  621. <percent_left>0.0000</percent_left>
  622. <percent_right>0.0000</percent_right>
  623. <ymin_type_1>0</ymin_type_1>
  624. <ymax_type_1>0</ymax_type_1>
  625. <ymin_item_1>0</ymin_item_1>
  626. <ymax_item_1>0</ymax_item_1>
  627. <graph_items>
  628. <graph_item>
  629. <sortorder>0</sortorder>
  630. <drawtype>0</drawtype>
  631. <color>00C800</color>
  632. <yaxisside>0</yaxisside>
  633. <calc_fnc>2</calc_fnc>
  634. <type>0</type>
  635. <item>
  636. <host>Template App NGINX</host>
  637. <key>nginx.status[accepts]</key>
  638. </item>
  639. </graph_item>
  640. <graph_item>
  641. <sortorder>1</sortorder>
  642. <drawtype>0</drawtype>
  643. <color>C80000</color>
  644. <yaxisside>0</yaxisside>
  645. <calc_fnc>2</calc_fnc>
  646. <type>0</type>
  647. <item>
  648. <host>Template App NGINX</host>
  649. <key>nginx.status[handled]</key>
  650. </item>
  651. </graph_item>
  652. <graph_item>
  653. <sortorder>2</sortorder>
  654. <drawtype>0</drawtype>
  655. <color>0000C8</color>
  656. <yaxisside>0</yaxisside>
  657. <calc_fnc>2</calc_fnc>
  658. <type>0</type>
  659. <item>
  660. <host>Template App NGINX</host>
  661. <key>nginx.status[requests]</key>
  662. </item>
  663. </graph_item>
  664. </graph_items>
  665. </graph>
  666. </graphs>
  667. <value_maps>
  668. <value_map>
  669. <name>Service state</name>
  670. <mappings>
  671. <mapping>
  672. <value>0</value>
  673. <newvalue>Down</newvalue>
  674. </mapping>
  675. <mapping>
  676. <value>1</value>
  677. <newvalue>Up</newvalue>
  678. </mapping>
  679. </mappings>
  680. </value_map>
  681. </value_maps>
  682. </zabbix_export>

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

在这里插入图片描述

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

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

zabbix监控Tomcat

A机器:zabbix服务端(192.168.234.128) B机器:zabbix客户端(192.168.234.125)

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


 
  1. [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
  2.  
  3. [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(进程数)的注释符号#:

在这里插入图片描述

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

编辑server配置文件:


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

定义以下3个配置参数:

在这里插入图片描述

启动zabbix-java-gateway服务:


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

重启zabbix-server服务:


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

查看监听端口:


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

开启JMX

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


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

添加以下内容:


 
  1. export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote
  2. -Djava.rmi.server.hostname=192.168.234.125
  3. -Dcom.sun.management.jmxremote.port=9999
  4. -Dcom.sun.management.jmxremote.ssl=false
  5. -Dcom.sun.management.jmxremote.authenticate=false"

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

重启tomcat:


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

查看监听端口9999:


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

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

在这里插入图片描述

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

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

在这里插入图片描述

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

在这里插入图片描述

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. [mysql]
  2. host=localhost
  3. user=zamysql
  4. password='zamysql'
  5. socket=/tmp/mysql.sock
  6.  
  7. [mysqladmin]
  8. host=localhost
  9. user=zamysql
  10. password='zamysql'
  11. socket=/tmp/mysql.sock

在A机器测试:


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

#已成功获取数据

在zabbix前端页面添加主机:

在这里插入图片描述

监控模板选择DB mysql:

在这里插入图片描述

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

在这里插入图片描述

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

在这里插入图片描述

总结

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

分享到:

相关信息

  • Nginx主机域名配置实现

    一、配置多个端口访问不同文件 二、配置不同域名访问不同文件 三、配置不同域名访问同个文件...

    2023-03-17

  • Nginx配置-日志格式配置方式

    上线了一个小的预约程序,配置通过Nginx进行访问入口,默认的日志是没有请求时间的,因此需要配置一下,将每一次的请求的访问响应时间记录出来,备查与优化使用....

    2023-03-17

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载