搜索
首页运维Nginxzabbix监控Nginx/Tomcat/MySQL的方法

zabbix监控nginx

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

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

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

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

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

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

重载nginx配置:

[root@centos ~]# nginx -s reload

测试:

[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的方法

添加监控脚本:

vi /usr/local/sbin/ngx_status.sh

添加以下内容:

#!/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

添加权限:

[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监控Nginx/Tomcat/MySQL的方法

重启服务:

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

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

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

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

<?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的方法

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

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

zabbix监控tomcat

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

在a机器安装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(监听端口)、start_pollers(进程数)的注释符号#:

zabbix监控Nginx/Tomcat/MySQL的方法

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

编辑server配置文件:

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

定义以下3个配置参数:

zabbix监控Nginx/Tomcat/MySQL的方法

启动zabbix-java-gateway服务:

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

重启zabbix-server服务:

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

查看监听端口:

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

开启jmx

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

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

添加以下内容:

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:

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

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

查看监听端口9999:

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

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

zabbix监控Nginx/Tomcat/MySQL的方法

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

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

zabbix监控Nginx/Tomcat/MySQL的方法

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

zabbix监控Nginx/Tomcat/MySQL的方法

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创建用户:

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

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

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

创建my.cnf文件:

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

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

添加以下内容:

[mysql]
host=localhost
user=zamysql
password=&#39;zamysql&#39;
socket=/tmp/mysql.sock

[mysqladmin]
host=localhost
user=zamysql
password=&#39;zamysql&#39;
socket=/tmp/mysql.sock

在a机器测试:

[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的方法

监控模板选择db mysql:

zabbix监控Nginx/Tomcat/MySQL的方法

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

zabbix监控Nginx/Tomcat/MySQL的方法

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

zabbix监控Nginx/Tomcat/MySQL的方法

以上是zabbix监控Nginx/Tomcat/MySQL的方法的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文转载于:亿速云。如有侵权,请联系admin@php.cn删除
NGINX与Apache:性能,可伸缩性和效率NGINX与Apache:性能,可伸缩性和效率Apr 19, 2025 am 12:05 AM

NGINX和Apache都是强大的Web服务器,各自在性能、可扩展性和效率上有独特的优势和不足。1)NGINX在处理静态内容和反向代理时表现出色,适合高并发场景。2)Apache在处理动态内容时表现更好,适合需要丰富模块支持的项目。选择服务器应根据项目需求和场景来决定。

终极摊牌:nginx vs. apache终极摊牌:nginx vs. apacheApr 18, 2025 am 12:02 AM

NGINX适合处理高并发请求,Apache适合需要复杂配置和功能扩展的场景。1.NGINX采用事件驱动、非阻塞架构,适用于高并发环境。2.Apache采用进程或线程模型,提供丰富的模块生态系统,适合复杂配置需求。

nginx行动:示例和现实应用程序nginx行动:示例和现实应用程序Apr 17, 2025 am 12:18 AM

NGINX可用于提升网站性能、安全性和可扩展性。1)作为反向代理和负载均衡器,NGINX可优化后端服务和分担流量。2)通过事件驱动和异步架构,NGINX高效处理高并发连接。3)配置文件允许灵活定义规则,如静态文件服务和负载均衡。4)优化建议包括启用Gzip压缩、使用缓存和调整worker进程。

NGINX单元:支持不同的编程语言NGINX单元:支持不同的编程语言Apr 16, 2025 am 12:15 AM

NGINXUnit支持多种编程语言,通过模块化设计实现。1.加载语言模块:根据配置文件加载相应模块。2.应用启动:调用语言运行时执行应用代码。3.请求处理:将请求转发给应用实例。4.响应返回:将处理后的响应返回给客户端。

在Nginx和Apache之间进行选择:适合您的需求在Nginx和Apache之间进行选择:适合您的需求Apr 15, 2025 am 12:04 AM

NGINX和Apache各有优劣,适合不同场景。1.NGINX适合高并发和低资源消耗场景。2.Apache适合需要复杂配置和丰富模块的场景。通过比较它们的核心特性、性能差异和最佳实践,可以帮助你选择最适合需求的服务器软件。

nginx怎么启动nginx怎么启动Apr 14, 2025 pm 01:06 PM

问题:如何启动 Nginx?答案:安装 Nginx启动 Nginx验证 Nginx 是否已启动探索其他启动选项自动启动 Nginx

怎么查看nginx是否启动怎么查看nginx是否启动Apr 14, 2025 pm 01:03 PM

确认 Nginx 是否启动的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 检查端口 80 是否开放;3. 查看系统日志中 Nginx 启动消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

nginx怎么关闭nginx怎么关闭Apr 14, 2025 pm 01:00 PM

要关闭 Nginx 服务,请按以下步骤操作:确定安装类型:Red Hat/CentOS(systemctl status nginx)或 Debian/Ubuntu(service nginx status)停止服务:Red Hat/CentOS(systemctl stop nginx)或 Debian/Ubuntu(service nginx stop)禁用自动启动(可选):Red Hat/CentOS(systemctl disable nginx)或 Debian/Ubuntu(syst

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热工具

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。