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 -VNext, 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=root password=Password– Restart the zabbix agent service using the following command:
root@web01:~# systemctl restart zabbix-agent– Finally, you can setup the host in your Zabbix server by selecting the MySQL Server template and you’ll start getting a data flow and triggers about the status of your database server:
After that go to /etc/my.cnf
At the end of the file add below Lines
[client]
user=zabbix_admin
password=password
port=3306
check the data by typing belo command.
zabbix_get -s 127.0.0.1 -k mysql.status[Com_begin]
1
Comments
Post a Comment