文章目录
1.概述监控MariaDB服务主机
主机名称 | IP | 监控 | 概述Zabbix的服务 |
---|---|---|---|
server | 172.25.0.200 | Zabbix_server(监控端) | |
worker1 | 172.25.0.20 | MariaDB | Zabbix_agent(被监控端) |
2.安装MariaDB服务和配置MariaDB
#在worker1操作,安装MariaDB
yum install mariadb-server -y
#启动MariaDB服务和开启自动开机启动服务
systemctl start mariadb && systemctl enable mariadb && systemctl status mariadb
#在worker1操作,设置管理数据库密码
mysqladmin -u root password '123456'
#在worker1操作,创建数据库和设置字符集
mysql -u root -p123456 -e "create database zabbix default charset 'utf8';"
#在worker1操作,赋予权限
mysql -u root -p123456 -e "grant usage on *.* to zabbix@'localhost' identified by '123456';"
参数:
usage权限:usage权限只能用于数据库登录,不能执行任何操作
#在worker1操作,查看数据库里面是没有zabbix数据库的,所以没有任何的执行操作
mysql -u zabbix -p123456 -e "show databases;"
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
3.配置Zabbix的userparameter_mysql.conf 文件模板
#在worker1操作,复制文件模板
cp /usr/share/doc/zabbix-agent-5.0.0/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/
#配置client.cnf,MariaDB客户端的用户和密码,实现免密码登录
sed -i '/\[client\]/a\user=zabbix\npassword=123456' /etc/my.cnf.d/client.cnf
cat /etc/my.cnf.d/client.cnf
#
# These two groups are read by the client library
# Use it for options that affect all clients, but not the server
#
[client]
user=zabbix
password=123456
# This group is not read by mysql client library,
# If you use the same .cnf file for MySQL and MariaDB,
# use it for MariaDB-only client options
[client-mariadb]
#在worker1操作,测试数据库是否免密码登录
mysql
MariaDB [(none)]> select user();
+------------------+
| user() |
+------------------+
| zabbix@localhost |
+------------------+
1 row in set (0.00 sec)
#配置完后需要重启zabbix-agent服务
systemctl restart zabbix-agent
4.在Web配置模板
#配置–>主机–>点击worker1–>点击模板–>选择Template DB MySQL by Zabbix agent–>点击更新
#点击worker1
#点击模板
#搜索mysql–>点击Template DB MySQL by Zabbix agent
#点击更新
#监测–>主机
#点击最新数据
#搜索mysql
#点击所有数据图形
#点击显示堆叠数据图
#查看堆叠数据图的数据
5.在server进行压力测试mysql服务
#在worker1主机操作,授予root远程登录权限
mysql -u root -p123456 -e "grant all privileges on *.* to 'root'@'%' identified by '123456';"
#在server主机操作,进行压力测试
mysqlslap -h worker1 -uroot -p123456 --concurrency=1000 --number-of-queries=1000 --number-int-cols=5 --number-char-cols=20 --auto-generate-sql
Benchmark
Average number of seconds to run all queries: 2.189 seconds
Minimum number of seconds to run all queries: 2.189 seconds
Maximum number of seconds to run all queries: 2.189 seconds
Number of clients running queries: 1000
Average number of queries per client: 1
参数:
--concurrency=100 #指有100个客户端连接
--number-of-queries=1000 #指(并发客户端数×每一个客户端查询数)等于乘积是1000
--number-int-cols=5 #指定生成5个 int 类型的列
--number-char-cols=20 #指定生成20 个 char 类型的列
--auto-generate-sql #指自动生成测试 SQL
#查看最大连接数量为152和查看缓存大小