溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

發(fā)布時(shí)間:2022-06-02 11:43:24 來源:億速云 閱讀:147 作者:iii 欄目:大數(shù)據(jù)

這篇文章主要介紹“zabbix監(jiān)控Nginx/Tomcat/MySQL的方法”的相關(guān)知識(shí),小編通過實(shí)際案例向大家展示操作過程,操作方法簡(jiǎn)單快捷,實(shí)用性強(qiáng),希望這篇“zabbix監(jiān)控Nginx/Tomcat/MySQL的方法”文章能幫助大家解決問題。

zabbix監(jiān)控nginx

a機(jī)器:zabbix服務(wù)端(192.168.234.128) b機(jī)器:zabbix客戶端(192.168.234.125)

在b機(jī)器(zabbix客戶端)操作:

編輯nginx虛擬主機(jī)配置文件:

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

在server{}中添加以下內(nèi)容:

 location /nginx_status
 {
  stub_status on;
  access_log off;
  allow 127.0.0.1;
  deny all;
 }

重載nginx配置:

[root@centos ~]# nginx -s reload

測(cè)試:

[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狀態(tài)信息已顯示

狀態(tài)說明:

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

添加監(jiān)控腳本:

vi /usr/local/sbin/ngx_status.sh

添加以下內(nèi)容:

#!/bin/bash
url="http://127.0.0.1/nginx_status"
curl=/usr/bin/curl

# 檢測(cè)nginx進(jìn)程是否存在
function ping {
 /sbin/pidof nginx | wc -l 
}
# 檢測(cè)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

添加權(quán)限:

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

編輯zabbix_agent配置文件:

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

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

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

重啟服務(wù):

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

在a機(jī)器(服務(wù)端)測(cè)試:

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

在本機(jī)創(chuàng)建.xml文件并添加以下內(nèi)容:(文件名稱自定義)

<?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進(jìn)程數(shù):0,請(qǐng)注意</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前端頁面點(diǎn)擊配置→模板→導(dǎo)入:

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

#導(dǎo)入剛才創(chuàng)建的xml文件即可

導(dǎo)入成功后在主機(jī)列表頁面選擇被監(jiān)控的機(jī)器(b機(jī)器)鏈接該模板即可開始監(jiān)控nginx

zabbix監(jiān)控tomcat

a機(jī)器:zabbix服務(wù)端(192.168.234.128) b機(jī)器:zabbix客戶端(192.168.234.125)

在a機(jī)器安裝zabbix-java-gateway:

[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配置文件:

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

去掉listen_ip、listen_port(監(jiān)聽端口)、start_pollers(進(jìn)程數(shù))的注釋符號(hào)#:

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

#listen_ip定義被監(jiān)控機(jī)器的地址,不指定默認(rèn)監(jiān)聽全部機(jī)器

編輯server配置文件:

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

定義以下3個(gè)配置參數(shù):

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

啟動(dòng)zabbix-java-gateway服務(wù):

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

重啟zabbix-server服務(wù):

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

查看監(jiān)聽端口:

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

開啟jmx

在b機(jī)器編輯tomcat配置文件:

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

添加以下內(nèi)容:

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機(jī)器地址,端口9999(默認(rèn)12345)

重啟tomcat:

[root@centos ~]# /usr/local/tomcat/bin/shutdown.sh 

[root@centos ~]# /usr/local/tomcat/bin/startup.sh

查看監(jiān)聽端口9999:

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

進(jìn)入zabbix前端頁面添加主機(jī):

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

#與普通情況添加監(jiān)控主機(jī)不同,監(jiān)控b機(jī)器的tomcat需要配置jmx接口

模板鏈接jmx相關(guān)的兩個(gè)模板:

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

當(dāng)jmx圖標(biāo)變綠即表示配置成功:

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

zabbix監(jiān)控mysql

a機(jī)器:zabbix服務(wù)端(192.168.234.128) b機(jī)器:zabbix客戶端(192.168.234.125)

zabbix_agent定義mysql監(jiān)控的配置文件:/etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf

在b機(jī)器登錄mysql創(chuàng)建用戶:

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

創(chuàng)建配置文件指定的目錄:

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

創(chuàng)建my.cnf文件:

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

#需要注意該文件是隱藏文件

添加以下內(nèi)容:

[mysql]
host=localhost
user=zamysql
password='zamysql'
socket=/tmp/mysql.sock

[mysqladmin]
host=localhost
user=zamysql
password='zamysql'
socket=/tmp/mysql.sock

在a機(jī)器測(cè)試:

[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

#已成功獲取數(shù)據(jù)

在zabbix前端頁面添加主機(jī):

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

監(jiān)控模板選擇db mysql:

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

zbx標(biāo)準(zhǔn)變?yōu)榫G色表示成功:

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

在監(jiān)測(cè)→最新數(shù)據(jù)頁面即可查看mysql監(jiān)控?cái)?shù)據(jù):

zabbix監(jiān)控Nginx/Tomcat/MySQL的方法

關(guān)于“zabbix監(jiān)控Nginx/Tomcat/MySQL的方法”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI