[Zabbix] Giám sát MySQL

30/12/2020

Bạn đang sử dụng Zabbix để giám sát hệ thống của mình. Bạn muốn theo dõi MySQL trên hệ thống giám sát của mình. Trong bài viết này tôi sẽ hướng dẫn bạn cách giám sát MySQL trên Zabbix.

1. Mô hình

2. Cài đặt

2.1 Thực hiện trên MySQL

2.1.1 Cài đặt zabbix agent

Trước tiên ta cần cài đặt Zabbix agent trên máy đang chạy MySQL

rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm yum install zabbix-agent -y

Khai báo thông tin của zabbix server trong file /etc/zabbix/zabbix_agentd.conf

ListenPort=10050 Server=10.10.10.167

Bật zabbix agent

systemctl start zabbix-agent systemctl enable zabbix-agent

Mở port

firewall-cmd --zone=public --add-port=10050/tcp firewall-cmd --zone=public --permanent --add-port=10050/tcp

Tắt selinux

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0

2.1.2 Cấu hình MySQL

Tạo user

mysql -u root -p grant usage on *.* TO 'zabbix'@'%' indentified by 'zabbix'; exit;

Khai báo user/password vừa tạo

mkdir /var/lib/zabbix vi /var/lib/zabbix/.my.cnf

Ghi vào file này nội dung như sau

[client] user = zabbix password = zabbix

Kiểm tra trong file /etc/zabbix/zabbix_agentd.conf đã có dòng sau

Include=/etc/zabbix/zabbix_agentd.d/*.conf

Kiểm tra trong thư mục /etc/zabbix/zabbix_agentd.d

ls /etc/zabbix/zabbix_agentd.d

Xem trong thư mục này đã có file userparameter_mysql.conf chưa. Nếu chưa có thì tạo file có tên như vậy và thêm vào đó nội dung như sau

# 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}' # 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 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

Restart zabbix-agent

systemctl restart zabbix-agent

2.2 Thực hiện trên zabbix server

Tạo host trên server

Chọn template Template DB MySQL

Như vậy ta đã có thể giám sát MySQL trên Zabbix

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

[Checkmk 1.6] Cấu hình cảnh báo qua email

Bài viết này hướng dẫn các bạn các bạn thiết lập cảnh báo qua email. Khi có bất thường với...
30/12/2020

[Zabbix] Giám sát Cisco Switch – SNMP

Khi nhắc tới các thiết bị network hẳn ai cũng biết tới Cisco. Thiết bị network trong hệ thống...
30/12/2020

[Zabbix] Giám sát MySQL

Bạn đang sử dụng Zabbix để giám sát hệ thống của mình. Bạn muốn theo dõi MySQL trên hệ thống...
30/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

SỰ KHÁC BIỆT GIỮA RESIDENTIAL PROXY VÀ PROXY DATACENTER
17/02/2024

Mua Proxy v6 US Private chạy PRE, Face, Insta, Gmail
07/01/2024

Mua shadowsocks và hướng dẫn sữ dụng trên window
05/01/2024

Tại sao Proxy Socks lại được ưa chuộng hơn Proxy HTTP?
04/01/2024

Mua thuê proxy v4 nuôi zalo chất lượng cao, kinh nghiệm tránh quét tài khoản zalo
02/01/2024