欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

zabbix 監(jiān)控mysql的方法

 更新時(shí)間:2020年10月12日 11:07:32   作者:名鳴明~  
這篇文章主要介紹了zabbix 監(jiān)控mysql的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作或?qū)W習(xí)具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

zabbix部署文檔

zabbix部署完之后

zabbix-agent操作

 1.監(jiān)控mysql,首先要先安裝mysql

[root@localhost ~]# yum -y install mariadb mariadb-server

2.編寫mysql監(jiān)控項(xiàng)的腳本

在zabbix-agent先授權(quán)個(gè)用戶 不然測(cè)試時(shí)沒有權(quán)限

[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 33
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> grant all on *.* to 'check'@'localhost' identified by '123';
Query OK, 0 rows affected (0.00 sec)

mysql監(jiān)控的內(nèi)容主要有

  • 主從的狀態(tài) (得先配置主從 在下面)
  • 流量檢測(cè) 發(fā)送,接受常規(guī)操作 增刪改查
  • 某個(gè)庫、某個(gè)表的大小
  • tps(每秒查詢處理的事務(wù)數(shù))qps(每秒能處理多少次請(qǐng)求數(shù))
[root@localhost ~]# mkdir /etc/zabbix/scipts
[root@localhost ~]# cd /etc/zabbix/scipts/
[root@localhost scipts]# vim mysql.sh 
#!/bin/bash
mysql="mysql -ucheck -p123"
case $1 in 
 # mysql主從狀態(tài)
 slave_status)
  $mysql -e "show slave status\G" |grep "Yes" |wc -l
 ;; 
 # mysql流量 接受
 Bytes_received)
  mysqladmin extended-status |grep "Bytes_received" |awk '{print $4}'
 ;;
 # mysql流量 發(fā)送
 Bytes_sent)
  mysqladmin extended-status |grep "Bytes_sent" |awk '{print $4}'
 ;;
 # mysql常規(guī)操作 增
 Com_insert)
  mysqladmin extended-status |grep -w "Com_insert" |awk '{print $4}'
 ;;
 # mysql常規(guī)操作 刪
 Com_delete)
  mysqladmin extended-status |grep -w "Com_delete" |awk '{print $4}'
 ;;
 # mysql常規(guī)操作 改
 Com_update)
  mysqladmin extended-status |grep -w "Com_update" |awk '{print $4}'
		;;
 # mysql常規(guī)操作 查
 Com_select)
  mysqladmin extended-status |grep -w "Com_select" |awk '{print $4}'
 ;;
 # mysql tps
 tps)
  mysqladmin status |awk '{print $6/$2}'
 ;;
 # mysql qps=(rollback+commit)/uptime
 qps)
  rollback=$(mysqladmin extended-status |grep -w "Com_rollback" |awk '{print $4}')
  commit=$(mysqladmin extended-status |grep -w "Com_commit" |awk '{print $4}')
  uptime=$(mysqladmin status |awk '{print $2}')
  count=$[$rollback+$commit]
  echo "$count $uptime" > /tmp/a.txt
  cat /tmp/a.txt |awk '{print $1/$2}'
 ;;
 # 庫大小 我們這里拿mysql庫舉例
 db)
  $mysql -e "select sum(data_length) from information_schema.tables where table_schema='mysql'" |sed -n '2p'
 ;;
 # 表大小 我們這里拿mysql下面的user表舉例
 tb)
  $mysql -e "select sum(data_length) from information_schema.tables where table_schema='mysql' and table_name='user'" |sed -n '2p'
 ;;
esac

3.自定義鍵值key 重啟zabbix-agent

[root@localhost scipts]# cd /etc/zabbix/zabbix_agentd.d/
[root@localhost zabbix_agentd.d]# vim mysql.conf
UserParameter=mysql[*],/etc/zabbix/scipts/mysql.sh $1
[root@localhost zabbix_agentd.d]# systemctl restart zabbix-agent

4.在zabbix-server測(cè)試 先安裝zabbix-get

[root@localhost ~]# yum -y install zabbix-get

[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[slave_status]
2
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[Bytes_received]
850970
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[Bytes_sent]
224906
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[Com_insert]
3001
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[Com_delete]
135
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[Com_update]
128
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[Com_select]
19
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[qps]
0.864842
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[tps]
1.92936
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[db]
555118
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[tb]
420

報(bào)錯(cuò)處理

[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[slave_status]
sh: /etc/zabbix/scipts/mysql.sh: 權(quán)限不夠

腳本執(zhí)行權(quán)限不夠 去zabbix-agent 加權(quán)限
[root@localhost zabbix_agentd.d]# chmod +x /etc/zabbix/scipts/mysql.sh 

[root@localhost ~]# zabbix_get -s 192.168.27.137 -k mysql[slave_status]
ERROR 1227 (42000) at line 1: Access denied; you need (at least one of) the SUPER,REPLICATION CLIENT privilege(s) for this operation

是因?yàn)橛脩魶]有權(quán)限查看 去zabbix-agent 授權(quán)個(gè)用戶在腳本里面加上
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 33
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> grant all on *.* to 'check'@'localhost' identified by '123';
Query OK, 0 rows affected (0.00 sec)

[root@localhost scipts]# vim mysql.sh 
#!/bin/bash
mysql="mysql -ucheck -p123"
case $1 in 
 # mysql主從狀態(tài)
 slave_status)
  $mysql -e "show slave status\G" |grep "Yes" |wc -l
 ;; 

zabbix頁面上添加監(jiān)控項(xiàng)和圖形

在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

查看mysql流量數(shù)據(jù)

在這里插入圖片描述
在這里插入圖片描述

查看mysql qps tps

在這里插入圖片描述

查看mysql主從狀態(tài)

在這里插入圖片描述

查看mysql常規(guī)操作

在這里插入圖片描述

查看mysql庫表大小

在這里插入圖片描述

mysql主從配置

一.zabbix-server端

[root@localhost ~]# vim /etc/my.cnf

在這里插入圖片描述

[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File  | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 175170 |  |   |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> grant all on *.* to 'tom'@'%' identified by '123';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

二.zabbix-agent端

[root@localhost ~]# vim /etc/my.cnf

在這里插入圖片描述

[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> change master to
 -> master_host='192.168.27.136',
 -> master_user='tom',
 -> master_password='123',
 -> master_log_file='mysql-bin.000001',
 -> master_log_pos=175170;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show slave status \G;
*************************** 1. row ***************************
  Slave_IO_State: Waiting for master to send event
   Master_Host: 192.168.27.136
   Master_User: tom
   Master_Port: 3306
  Connect_Retry: 60
  Master_Log_File: mysql-bin.000001
  Read_Master_Log_Pos: 175170
  Relay_Log_File: mysql-relay.000004
  Relay_Log_Pos: 529
 Relay_Master_Log_File: mysql-bin.000001
  Slave_IO_Running: Yes
  Slave_SQL_Running: No
  Replicate_Do_DB: 
  Replicate_Ignore_DB: 
  Replicate_Do_Table: 
 Replicate_Ignore_Table: 
 Replicate_Wild_Do_Table: 
 Replicate_Wild_Ignore_Table: 
   Last_Errno: 1146
   Last_Error: Error 'Table 'zabbix.history_uint' doesn't exist' on query. Default database: 'zabbix'. Query: 'insert into history_uint (itemid,clock,ns,value) values (23287,1602301747,810415730,1)'
   Skip_Counter: 0
  Exec_Master_Log_Pos: 173424
  Relay_Log_Space: 2565
  Until_Condition: None
  Until_Log_File: 
  Until_Log_Pos: 0
  Master_SSL_Allowed: No
  Master_SSL_CA_File: 
  Master_SSL_CA_Path: 
  Master_SSL_Cert: 
  Master_SSL_Cipher: 
  Master_SSL_Key: 
 Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
  Last_IO_Errno: 0
  Last_IO_Error: 
  Last_SQL_Errno: 1146
  Last_SQL_Error: Error 'Table 'zabbix.history_uint' doesn't exist' on query. Default database: 'zabbix'. Query: 'insert into history_uint (itemid,clock,ns,value) values (23287,1602301747,810415730,1)'
 Replicate_Ignore_Server_Ids: 
  Master_Server_Id: 1
1 row in set (0.00 sec)

ERROR: No query specified

報(bào)錯(cuò)處理

[root@localhost ~]# vim /etc/my.cnf

在這里插入圖片描述

[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show slave status \G;
*************************** 1. row ***************************
  Slave_IO_State: Waiting for master to send event
   Master_Host: 192.168.27.136
   Master_User: tom
   Master_Port: 3306
  Connect_Retry: 60
  Master_Log_File: mysql-bin.000001
  Read_Master_Log_Pos: 199126
  Relay_Log_File: mysql-relay.000006
  Relay_Log_Pos: 3950
 Relay_Master_Log_File: mysql-bin.000001
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
  Replicate_Do_DB: 
  Replicate_Ignore_DB: 
  Replicate_Do_Table: 
 Replicate_Ignore_Table: 
 Replicate_Wild_Do_Table: 
 Replicate_Wild_Ignore_Table: 
   Last_Errno: 0
   Last_Error: 
   Skip_Counter: 0
  Exec_Master_Log_Pos: 199126
  Relay_Log_Space: 4240
  Until_Condition: None
  Until_Log_File: 
  Until_Log_Pos: 0
  Master_SSL_Allowed: No
  Master_SSL_CA_File: 
  Master_SSL_CA_Path: 
  Master_SSL_Cert: 
  Master_SSL_Cipher: 
  Master_SSL_Key: 
 Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
  Last_IO_Errno: 0
  Last_IO_Error: 
  Last_SQL_Errno: 0
  Last_SQL_Error: 
 Replicate_Ignore_Server_Ids: 
  Master_Server_Id: 1
1 row in set (0.00 sec)

到此這篇關(guān)于zabbix 監(jiān)控mysql的方法的文章就介紹到這了,更多相關(guān)zabbix 監(jiān)控mysql內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 分布式監(jiān)控系統(tǒng)之Zabbix主動(dòng)、被動(dòng)及web監(jiān)控的過程詳解

    分布式監(jiān)控系統(tǒng)之Zabbix主動(dòng)、被動(dòng)及web監(jiān)控的過程詳解

    這篇文章主要介紹了分布式監(jiān)控系統(tǒng)之Zabbix主動(dòng)、被動(dòng)及web監(jiān)控的過程詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • 使用zabbix監(jiān)控oracle表空間的操作流程

    使用zabbix監(jiān)控oracle表空間的操作流程

    zabbix是一款極其強(qiáng)大的開源監(jiān)控工具,下面我分享下zabbix如何監(jiān)控表空間,跟著這個(gè)思路,監(jiān)控其他項(xiàng)都是類似操作,對(duì)zabbix監(jiān)控oracle表空間相關(guān)知識(shí)感興趣的朋友一起看看吧
    2021-06-06
  • Zabbix 動(dòng)態(tài)執(zhí)行監(jiān)控采集腳本的實(shí)現(xiàn)原理

    Zabbix 動(dòng)態(tài)執(zhí)行監(jiān)控采集腳本的實(shí)現(xiàn)原理

    這篇文章主要介紹了Zabbix 動(dòng)態(tài)執(zhí)行監(jiān)控采集腳本的實(shí)現(xiàn)原理,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • 關(guān)于YUM安裝部署Zabbix4.4.7使用mysql數(shù)據(jù)庫的問題

    關(guān)于YUM安裝部署Zabbix4.4.7使用mysql數(shù)據(jù)庫的問題

    這篇文章主要介紹了YUM安裝部署Zabbix4.4.7使用mysql數(shù)據(jù)庫的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-03-03
  • zabbix6.0LTS 配置proxy分布式監(jiān)控的過程詳解

    zabbix6.0LTS 配置proxy分布式監(jiān)控的過程詳解

    zabbix_proxy必須要安裝一個(gè)數(shù)據(jù)庫.zabbix官網(wǎng)推薦使用mariadb數(shù)據(jù)庫,本人嘗試過使用mysql8.0,這篇文章主要介紹了zabbix6.0LTS 配置proxy分布式監(jiān)控,需要的朋友可以參考下
    2023-07-07
  • Zabbix3.0郵件報(bào)警配置

    Zabbix3.0郵件報(bào)警配置

    這篇文章主要介紹了Zabbix3.0配置郵件報(bào)警安裝方法,需要的朋友可以參考下
    2018-02-02
  • 在centos7安裝zabbix3.0的超詳細(xì)步驟記錄

    在centos7安裝zabbix3.0的超詳細(xì)步驟記錄

    這篇文章主要給大家介紹了關(guān)于在centos7安裝zabbix3.0的超詳細(xì)步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-10-10
  • zabbix redis自動(dòng)發(fā)現(xiàn)端口的腳本返回json格式

    zabbix redis自動(dòng)發(fā)現(xiàn)端口的腳本返回json格式

    zabbix([`zæbiks])是一個(gè)基于WEB界面的提供分布式系統(tǒng)監(jiān)視以及網(wǎng)絡(luò)監(jiān)視功能的企業(yè)級(jí)的開源解決方案。這篇文章主要介紹了zabbix redis自動(dòng)發(fā)現(xiàn)端口的腳本,返回json格式,需要的朋友可以參考下
    2019-11-11
  • 獲取zabbix上所有主機(jī)的IP和主機(jī)名的實(shí)例代碼

    獲取zabbix上所有主機(jī)的IP和主機(jī)名的實(shí)例代碼

    zabbix([`zæbiks])是一個(gè)基于WEB界面的提供分布式系統(tǒng)監(jiān)視以及網(wǎng)絡(luò)監(jiān)視功能的企業(yè)級(jí)的開源解決方案。這篇文章主要介紹了獲取zabbix上所有主機(jī)的IP和主機(jī)名,需要的朋友可以參考下
    2019-10-10
  • ubuntu系統(tǒng)下部署zabbix服務(wù)器監(jiān)控的方法教程

    ubuntu系統(tǒng)下部署zabbix服務(wù)器監(jiān)控的方法教程

    這篇文章主要給大家介紹了在ubuntu系統(tǒng)下部署zabbix服務(wù)器監(jiān)控的方法教程,文中將步驟介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編來一起看看吧。
    2017-06-06

最新評(píng)論