MySQL8.0数据库审计
数据库审计属于数据库安全范畴。
序号 | 数据库安全 |
---|---|
1 | 数据库审计 |
2 | 数据库防火墙 |
3 | 数据库加密 |
4 | 数据脱敏 |
5 | 数据库漏洞扫描 |
6 | 数据库安全运维 |
背景
- 主动安全防护:缩短攻击从发生到发现的时间。
- 法律刚需:日志存储至少180天。
插件
- 官方企业版
- Percona MySQL
- MariaDB审计插件
- McAfee审计插件(支持 MySQL 8.0)
McAfee审计插件
使用 sysbench 压测,开启审计后约有25%的性能损耗
安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 解压
unzip audit-plugin-mysql-8.0-1.1.12-999-linux-x86_64.zip
# 將插件拷贝到 MySQL 的 plugin 下
cp /root/audit-plugin-mysql-8.0-1.1.12-999/lib/libaudit_plugin.so /usr/lib64/mysql/plugin/
chown -R mysql.mysql /usr/lib64/mysql/plugin/libaudit_plugin.so
chmod +x /usr/lib64/mysql/plugin/libaudit_plugin.so
# 连接 MySQL,加载插件
mysql> INSTALL PLUGIN AUDIT SONAME 'libaudit_plugin.so';
Query OK, 0 rows affected (5.97 sec)
mysql> show global status like 'AUDIT_version';
+---------------+------------+
| Variable_name | Value |
+---------------+------------+
| Audit_version | 1.1.12-999 |
+---------------+------------+
1 row in set (0.01 sec)
# 开启审计
mysql> set global audit_json_file=ON;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'audit_json_file';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| audit_json_file | ON |
+-----------------+-------+
1 row in set (0.01 sec)
# 为了重启能生效,写入到 /etc/my.cnf 中
[mysqld]
audit_json_file=on
plugin-load=AUDIT=libaudit_plugin.so
默认会在
data_dir(/var/lib/mysql)
路径下生成一个mysql-audit.json
文件
切换日志
1
2
mv mysql-audit.json mysql-audit.json.`date +%F`
mysql -e 'set global audit_json_file_flush=on;'
追踪日志
1
tail -f -n 20 mysql-audit.json | gerp "关键词"
本文由作者按照
CC BY 4.0
进行授权