天天看點

zabbix之 zabbix模闆監控mysql

zabbix中預設有mysql的監控模闆。預設已經在zabbix2.2及以上的版本中。模闆名稱:Template App MySQL。

如果沒有則要去zabbix官方下載下傳 url:https://zabbix.org/mw/images/d/d4/Template_App_MySQL-2.2.0.xml,然後在Zabbix伺服器的前端Web界面的組态->模闆頁面中選擇彙入,在新的頁面中導入下載下傳的模闆檔案。

#模拟環境

10.100.25.41 #zabbix server

10.100.25.40 #zabbix agent

一、

#zabbix配置-在zabbix agent上操作

1.1、

[bmonitor@mysql1 etc]$ pwd

/home/bmonitor/bmonitor_agent/etc

[bmonitor@mysql1 etc]$ cat zabbix_agentd.conf

PidFile=/home/bmonitor/bmonitor_agent/run/zabbix_agented.pid

LogFile=/home/bmonitor/bmonitor_agent/logs/zabbix_agented.log

Server=10.100.25.41 #指向zabbix伺服器

ServerActive=10.100.25.41:10051 #指向zabbix伺服器

Hostname=10.100.25.40

AllowRoot=1

User=bmonitor

UnsafeUserParameters=1

Include=/home/bmonitor/bmonitor_agent/zabbix-3.2.11/conf/zabbix_agentd/*.conf #這一行是指向模闆檔案的

1.2、

##添加帳戶密碼

mysql> GRANT USAGE ON *.* TO 'mysqlcheck'@'localhost' IDENTIFIED BY 'mysqlcheck';

mysql> FLUSH PRIVILEGES;

1.3、

##添加用來關聯mysql的配置檔案.my.cnf,

執行mysql mysqladmin腳本指令時不需要帳戶密碼,也不再提示警告

[bmonitor@mysql1 etc]$ cat /etc/my.cnf

[client]

host = localhost

user = mysqlcheck

password = mysqlcheck

socket = /tmp/mysql.sock1

[bmonitor@mysql1 bmonitor_agent]$ cat /home/bmonitor/bmonitor_agent/etc/.my.cnf

[mysql]

port = 3307

[mysqladmin]

password = mysqlchechk

1.4、

##修改zabbix模闆配置檔案中的mysql路徑

這個檔案用于制定Zabbix Agent如何擷取MySQL資料

[bmonitor@mysql1 zabbix_agentd]$ pwd

/home/bmonitor/bmonitor_agent/zabbix-3.2.11/conf/zabbix_agentd

[bmonitor@mysql1 zabbix_agentd]$

[bmonitor@mysql1 zabbix_agentd]$ ll

total 8

-rw-r--r-- 1 bmonitor bmonitor 1359 Dec 27 2017 userparameter_examples.conf

-rw-r--r-- 1 bmonitor bmonitor 1531 Dec 27 2017 userparameter_mysql.conf

sed -i 's@/var/lib/zabbix@/home/bmonitor/bmonitor_agent/etc/@g' /home/bmonitor/bmonitor_agent/zabbix-3.2.11/conf/zabbix_agentd/userparameter_mysql.conf

##測試不用帳戶密碼就可以執行mysqladmin指令

$ mysqladmin ping | grep -c alive

1

二、

#zabbix頁面配置-在zabbix server上操作

##建立主機

Configuration—Hosts—建立主機

主機名稱,群組選擇,agent的IP位址和端口,然後點更新

##使用模闆

Configuration—Hosts—主機名稱—Tempaltes,搜尋MySQL,添加彈出的模闆Template App MySQL,然後點更新

注意:選完模闆後,要點下添加按鈕才行。

##檢視監控效果

Monitoring—Graphs,選擇組,然後選擇host及展示的圖形

這時候圖形裡會多出mysql bandwidth和mysql operations,而且有輸出資訊

#總結說明