真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Zabbix使用自帶模板監(jiān)控MySQL

(一)簡介

zabbix在監(jiān)控MySQL數(shù)據(jù)庫時,會使用自帶的模板Template App MySQL,是不能直接使用的,因?yàn)闆]有key,而獲取不到數(shù)據(jù),前端會出現(xiàn)如下報錯“Warning: Using a password on the command line interface can be insecure.”報錯原因是mysql 5.6以后的版本增加了密碼安全策略,在命令行里加上密碼就會強(qiáng)制報錯,而5.6之前版本可以直接使用的。

為呈貢等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及呈貢網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站設(shè)計制作、成都網(wǎng)站建設(shè)、呈貢網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!

前邊有篇文章是通過mysql --login-path=local來進(jìn)行無密碼驗(yàn)證登錄,而本文是通過另一種方法通過修改/etc/my.cnf來進(jìn)行無密碼驗(yàn)證登錄。

錯誤探究:
 這個提示在mysql 5.5之后會出現(xiàn)。
而且,這個提示,會被zabbix-servre捕捉到,在zabbix-server.log日志中會出現(xiàn)

24123:20160826:101433.609 error reason for "110:mysql.status[Bytes_sent]" changed: Received value [mysqladmin: [Warning] Using a password on the command line interface can be insecure.8991074] is not suitable for value type [Numeric (float)]
提示參數(shù)不符合
在zabbix-server服務(wù)器上面,使用zabbix-get命令時

[root@localhost ~]# /usr/local/zabbix/bin/zabbix_get -s 172.21.100.12 -p10050 -k mysql.status[Uptime]

mysqladmin: [Warning] Using a password on the command line interface can be insecure.

522345
也就是說zabbix_key獲取的key值是“mysqladmin: [Warning] Using a password on the command line interface can be insecure.”而不是522345,造成服務(wù)端的數(shù)值類型不對,為解決這個問題必須使用無密碼登錄才可以,為了安全,只允許localhost進(jìn)行登錄。
 (二)背景簡介
IP主機(jī)名功能
172.20.66.110 zabbix_server zabbix 服務(wù)端
172. 21.100.12 zabbix_agent zabbix客戶端數(shù)據(jù)庫

(三)具體實(shí)施步驟

一,zabbix_agentd客戶端設(shè)置
1.在mysql數(shù)據(jù)上創(chuàng)建一個普通用戶lqb

[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 756
Server version: 5.5.58-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> grant all PRIVILEGES on *.* to lqb@'localhost' identified by '123456';  ###創(chuàng)建一個有權(quán)限的訪問用戶lqb密碼設(shè)置123456
Query OK, 0 rows affected (0.04 sec)

mysql> update mysql.user set authentication_string=password('123456') where user='lqb' and Host = 'localhost';     ###更新下改用戶的密碼
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

2.修改/etc/my.cnf文件創(chuàng)建無密碼登錄

[root@localhost ~]# vim /etc/my.cnf
[client]
user=lqb
password=123456

[mysqladmin]
host=localhost
user=lqb
password=123456

3.測試是否可以直接訪問,如果輸入命令mysql -ulqb直接進(jìn)去說明已OK。

[root@localhost ~]# mysql -ulqb
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 761
Server version: 5.5.58-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> select Host,User,authentication_string from mysql.user;
+-----------------------+--------+-------------------------------------------+
| Host                  | User   | authentication_string                     |
+-----------------------+--------+-------------------------------------------+
| localhost             | root   |                                           |
| localhost.localdomain | root   |                                           |
| 127.0.0.1             | root   |                                           |
| ::1                   | root   |                                           |
| %                     | root   | NULL                                      |
| %                     | zabbix | NULL                                      |
| localhost             | lqb    | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 172.21.100.12         | zabbix | NULL                                      |
+-----------------------+--------+-------------------------------------------+
8 rows in set (0.01 sec)

mysql> exit;
Bye

[root@localhost scripts]# mysqladmin extended-status |grep -w "Bytes_received" |cut -d"|" -f3   ###有數(shù)據(jù)返回說明正常
 10792596272  

4.創(chuàng)建mysql監(jiān)控腳本在目錄/usr/local/zabbix/scripts/chk_mysql.sh并賦予相關(guān)的權(quán)限。

[root@localhost scripts]# cat /usr/local/zabbix/scripts/chk_mysql.sh 
#!/bin/bash
# -------------------------------------------------------------------------------
# FileName:    check_mysql.sh
# Revision:    1.0
# Date:        2018/01/04
# Author:      lqb
# Email:       
# Website:     
# Description: 
# Notes:       ~
# -------------------------------------------------------------------------------
# Copyright:   2015 (c) DengYun
# License:     GPL
# 用戶MYSQL_USER='zabbix'
MYSQL_USER='lqb'
# 密碼
MYSQL_PWD='123456'
# 主機(jī)地址/IP
MYSQL_HOST='localhost'
# 端口
MYSQL_PORT='3306'
# 數(shù)據(jù)連接
#MYSQL_CONN="/usr/local/mysql/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
MYSQL_CONN="/usr/local/mysql/bin/mysqladmin "
# 參數(shù)是否正確
if [ $# -ne "1" ];then 
    echo "arg error!" 
fi 
# 獲取數(shù)據(jù)
case $1 in 
    Uptime) 
        result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"` 
        echo $result 
        ;; 
    Com_update) 
        result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3` 
        echo $result 
        ;; 
    Slow_queries) 
        result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"` 
        echo $result 
        ;; 
    Com_select) 
        result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3` 
        echo $result 
                ;; 
    Com_rollback) 
        result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3` 
                echo $result 
                ;; 
    Questions) 
        result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"` 
                echo $result 
                ;; 
    Com_insert) 
        result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3` 
                echo $result 
                ;; 
    Com_delete) 
        result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3` 
                echo $result 
                ;; 
    Com_commit) 
        result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3` 
                echo $result 
                ;; 
    Bytes_sent) 
        result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3` 
                echo $result 
                ;; 
    Bytes_received) 
        result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3` 
                echo $result 
                ;; 
    Com_begin) 
        result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3` 
                echo $result 
                ;; 

        *) 
        echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)" 
        ;; 
esac
[root@localhost zabbix]# chmod +x scripts/chk_mysql.sh 
[root@localhost zabbix]# chown -R zabbix.zabbix scripts/chk_mysql.sh 
[root@localhost zabbix]# ll scripts/
total 4
-rwxr-xr-x 1 zabbix zabbix 2675 Jan  4 04:01 chk_mysql.sh
null

5.修改zabbix_agentd.conf添加以下參數(shù):

UserParameter=mysql.version,mysql -V
UserParameter=mysql.status[*], /usr/local/zabbix/scripts/chk_mysql.sh $1
UserParameter=mysql.ping,/usr/local/mysql/bin/mysqladmin -ulqb ping | grep -c alive
[root@localhost scripts]# grep '^[a-Z]' /usr/local/zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=172.20.66.110
Hostname=172.21.100.12
RefreshActiveChecks=120
Timeout=20
UserParameter=mysql.version,mysql -V
UserParameter=mysql.status[*], /usr/local/zabbix/scripts/chk_mysql.sh $1
UserParameter=mysql.ping,/usr/local/mysql/bin/mysqladmin -ulqb ping | grep -c alive

6.重啟zabbix_agentd客戶端服務(wù),查看有沒有報錯。

[root@localhost scripts]# /etc/init.d/zabbix_agentd restart
Restarting zabbix_agentd (via systemctl):                  [  OK  ]
[root@localhost scripts]# tail -f /tmp/zabbix_agentd.log 
 24025:20180104:041135.331 **** Enabled features ****
 24025:20180104:041135.331 IPv6 support:           NO
 24025:20180104:041135.331 TLS support:            NO
 24025:20180104:041135.331 **************************
 24025:20180104:041135.331 using configuration file: /usr/local/zabbix/etc/zabbix_agentd.conf
 24025:20180104:041135.331 agent #0 started [main process]
 24030:20180104:041135.332 agent #4 started [listener #3]
 24028:20180104:041135.332 agent #2 started [listener #1]
 24027:20180104:041135.332 agent #1 started [collector]
 24029:20180104:041135.333 agent #3 started [listener #2]

二.在zabbix_server端的瀏覽器設(shè)置
1.收下在zabbix_server端查看下mysql腳本信息是否可以正常獲取

[root@localhost slow]# /usr/local/zabbix/bin/zabbix_get -s 172.21.100.12 -p10050 -k mysql.status[Uptime]
2165105

2.添加主機(jī)。配置--主機(jī)填寫相關(guān)信息。
Zabbix使用自帶模板監(jiān)控MySQL

3.鏈接相關(guān)模板。點(diǎn)擊模板選項(xiàng)卡--選擇--選中Templeate DB MySQL模板--添加--更新
Zabbix使用自帶模板監(jiān)控MySQL

4.查看監(jiān)控項(xiàng)有沒有紅色告警,沒有就算正常的。
Zabbix使用自帶模板監(jiān)控MySQL

5.等兩分鐘(數(shù)據(jù)默認(rèn)1分鐘來獲取數(shù)據(jù)),就可以獲取相關(guān)數(shù)據(jù)了
6.Zabbix使用自帶模板監(jiān)控MySQL

Zabbix使用自帶模板監(jiān)控MySQL

至此監(jiān)控mysql完成。


當(dāng)前文章:Zabbix使用自帶模板監(jiān)控MySQL
分享網(wǎng)址:http://weahome.cn/article/jjcosi.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部