[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] Giám sát port TCP

“Port” là một thuật ngữ chuyên ngành được sử dụng phổ thông trong network, system nói riêng và...
30/12/2020

[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

[Checkmk] Nâng cấp phiên bản checkmk trên CentOS 7

Checkmk ra đời vào năm 2015 trải qua quá trình phát triển được rất nhiều các cá nhân, tổ chức...
30/12/2020
Bài Viết

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

Reliable IPv4 and IPv6 Subnet Rental Services: The Perfect Solution for Global Businesses
23/12/2024

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024