zabbix 監控mysql實例

zabbix 監控mysql實例

環境:
CentOS 7.2
zabbix-3.0.5 LTS
nginx-1.10.1
php-7.0.11
mariadb-10.1.18


請參看


監控mysqlphp

zabbix自帶mysql模板監控mariadb,更全面的監控能夠自行編寫腳本或才經過第三方模板,如http://www.fromdual.com/mpm-installation-guidehtml


在要監控的mysql主機上mysql

1.安裝zabbix客戶端nginx

2.建立具備監控權限的數據庫用戶sql

GRANT USAGE ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY 'zabbix';數據庫

FLUSH PRIVILEGES;c#

3.建立數據庫鏈接配置文件session

root@jlive:~#cat >/usr/local/zabbix/etc/.my.cnf <<HEREsocket

[mysql]ide

host     = localhost

user     = zabbix

password = zabbix

socket   = /tmp/mysql.sock

[mysqladmin]

host     = localhost

user     = zabbix

password = zabbix

socket   = /tmp/mysql.sock

HERE

可根據環境不一樣做相應調整

4.使用zabbix mysql模板配置文件userparameter_mysql.conf

cp /usr/local/src/zabbix-3.0.2/conf/zabbix_agentd/userparameter_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d

sed -i 's#/var/lib/zabbix#/usr/local/zabbix/etc#g' /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf 

在agentd主配置文件中Include進來

 

sed -i '$ a Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d' /usr/local/zabbix/etc/zabbix_agentd.conf

5.重啓zabbix_agentd

/etc/init.d/zabbix_agentd restart

6.測試

root@jlive:~#zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf -t mysql.status[uptime]

mysql.status[uptime]                          [t|11914]

root@jlive:~#zabbix_get -s localhost -p 10050 -k 'mysql.status[Bytes_received]'

sh: mysql: command not found


日誌裏也一直提示mysql命令not found

 61652:20160430:223023.549 item "Zabbix server:mysql.status[Bytes_received]" became not supported: Received value [sh: mysql: command not found] is not suitable for value type [Numeric (float)]

 61650:20160430:223024.550 item "Zabbix server:mysql.status[Bytes_sent]" became not supported: Received value [sh: mysql: command not found] is not suitable for value type [Numeric (float)]

 61652:20160430:223025.552 item "Zabbix server:mysql.status[Com_begin]" became not supported: Received value [sh: mysql: command not found] is not suitable for value type [Numeric (float)]

 61653:20160430:223026.552 item "Zabbix server:mysql.status[Com_commit]" became not supported: Received value [sh: mysql: command not found] is not suitable for value type [Numeric (float)]

 61650:20160430:223027.554 item "Zabbix server:mysql.status[Com_delete]" became not supported: Received value [sh: mysql: command not found] is not suitable for value type [Numeric (float)]

 61653:20160430:223028.555 item "Zabbix server:mysql.status[Com_insert]" became not supported: Received value [sh: mysql: command not found] is not suitable for value type [Numeric (float)]

 61652:20160430:223029.557 item "Zabbix server:mysql.status[Com_rollback]" became not supported: Received value [sh: mysql: command not found] is not suitable for value type [Numeric (float)]

 61646:20160430:223501.719 executing housekeeper

 61646:20160430:223501.742 housekeeper [deleted 0 hist/trends, 1 items, 0 events, 0 sessions, 0 alarms, 0 audit items in 0.021534 sec, idle for 1 hour(s)]


但實際上mysql命令是存在的,只是非標準路徑,mariadb安裝在/opt/mariadb下,故mysql命令的絕對路徑是/opt/mariadb/bin/mysql,但我己經在/etc/profile中做了全局申明,export PATH=/opt/mariadb/bin:$PATH,但仍是報mysql  not found,因而百度了下,還真有朋友碰到相同的問題,試了下

解決方案

A./usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf中的全部mysql,mysqladmin替換爲絕對路徑

或者

B.將mysql,mysqladmin軟鏈到/usr/bin下

ln -s /opt/mariadb/bin/{mysql,mysqladmin} /usr/bin

注意:軟鏈到/usr/local/bin下無效,只能呵呵了


推薦B方案,軟鏈後立馬就生效了

root@jlive:~#zabbix_get -s localhost -p 10050 -k 'mysql.status[Bytes_received]'

17963712


 61653:20160430:223522.880 item "Zabbix server:mysql.ping" became supported

 61650:20160430:223523.882 item "Zabbix server:mysql.status[Bytes_received]" became supported

 61651:20160430:223524.883 item "Zabbix server:mysql.status[Bytes_sent]" became supported

 61652:20160430:223525.884 item "Zabbix server:mysql.status[Com_begin]" became supported

 61650:20160430:223526.887 item "Zabbix server:mysql.status[Com_commit]" became supported

 61651:20160430:223527.888 item "Zabbix server:mysql.status[Com_delete]" became supported

 61653:20160430:223528.889 item "Zabbix server:mysql.status[Com_insert]" became supported

 61652:20160430:223529.891 item "Zabbix server:mysql.status[Com_rollback]" became supported

 61653:20160430:223530.892 item "Zabbix server:mysql.status[Com_select]" became supported

 61650:20160430:223531.894 item "Zabbix server:mysql.status[Com_update]" became supported

 61651:20160430:223532.895 item "Zabbix server:mysql.status[Questions]" became supported

 61652:20160430:223533.895 item "Zabbix server:mysql.status[Slow_queries]" became supported

 61653:20160430:223534.896 item "Zabbix server:mysql.status[Uptime]" became supported


zabbix <wbr>監控mysql實例

相關文章
相關標籤/搜索