MONITOR MYSQL/MARIADB SỬ DỤNG ZABBIX SERVER

3
3509

Setup a MySql/MariaDB Monitoring User:

root@web01:~# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2016, 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> create user 'zabbix_admin'@'localhost' IDENTIFIED BY 'Password';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT USAGE ON *.* TO 'zabbix_admin'@'localhost' IDENTIFIED BY 'Password';
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

mysql> exit
Bye

Configure Zabbix Agent

– To monitor MySql / MariaDB we have to create a file called userparameter_mysql.conf in /etc/zabbix/zabbix_agentd.conf.d, will it be used to collect data:

root@web01:~# vi /etc/zabbix/zabbix_agentd.conf.d/userparameter_mysql.conf

– Add this lines

 # For all the following commands HOME should be set to the directory that has .my.cnf file with password information.
#
# Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert].
# Key syntax is mysql.status[variable].
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/etc/zabbix mysql -N | awk '{print $$2}' # My line
#
# Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data].
# Key syntax is mysql.size[<database>,<table>,<type>].
# Database may be a database name or "all". Default is "all".
# Table may be a table name or "all". Default is "all".
# Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both".
# Database is mandatory if a table is specified. Type may be specified always.
# Returns value in bytes.
# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table
UserParameter=mysql.size[*],echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[$
#
#Default below
UserParameter=mysql.ping,HOME=/etc/zabbix mysqladmin ping | grep -c alive 
#
#My line
UserParameter=mysql.uptime,HOME=/etc/zabbix mysqladmin status | cut -f2 -d ":" | cut -f1 -d "T" | tr -d " "
UserParameter=mysql.threads,HOME=/etc/zabbix mysqladmin status | cut -f3 -d ":" | cut -f1 -d "Q" | tr -d " "
UserParameter=mysql.questions,HOME=/etc/zabbix mysqladmin status | cut -f4 -d ":"|cut -f1 -d "S" | tr -d " "
UserParameter=mysql.slowqueries,HOME=/etc/zabbix mysqladmin status | cut -f5 -d ":" | cut -f1 -d "O" | tr -d " "
UserParameter=mysql.qps,HOME=/etc/zabbix mysqladmin status | cut -f9 -d ":" | tr -d " "
UserParameter=mysql.version,mysql -V

Next, we need to give Zabbix the login information for our new user. Create a file called .my.cnf in /etc/zabbix and fill it with these lines:

root@web01:~# vi /etc/zabbix/.my.cnf
#
[mysql]
user=zabbix_admin
password=Password
[mysqladmin]
user=zabbix_admin
password=Password

ADD line to /etc/zabbix/zabbix_agentd.conf
Include=/etc/zabbix/zabbix_agentd.conf.d/*.conf

Open : /root/zabbix-3.0.0/conf/zabbix_agentd/userparameter_mysql.conf

Correct line : UserParameter=mysql.ping,HOME=/var/lib//zabbix mysqladmin ping | grep -c alive

to UserParameter=mysql.ping,HOME=/etc/zabbix mysqladmin ping | grep -c alive

– Restart the zabbix agent service using the following command:

root@web01:~# systemctl restart zabbix-agent

3
Leave a Reply

avatar
3 Comment threads
0 Thread replies
19 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
unknownVu hieu Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Vu hieu
Guest
Vu hieu

Đúng cái đang cần
Cảm ơn bác nhé

james
Guest
james

thanks man!

unknown
Guest
unknown

good jobs