赞
踩
一、安装审计模块--MySQL企业版
1、安装插件
mysql -f < path-to-basedir/share/audit_log_filter_linux_install.sql
2、检查插件是否安装成功
登录mysql客户端,mysql -u xx -pxx
检查插件列表是否有audit_log
mysql> show plugins;
| audit_log | ACTIVE | AUDIT | audit_log.so | PROPRIETARY |
3、查看插件设置
mysql>show global variables like 'audi%';
+--------------------------------------+--------------+
| Variable_name | Value |
+--------------------------------------+--------------+
...
| audit_log_buffer_size | 8388608 |
| audit_log_rotate_on_size | 67108864 |
| audit_log_strategy | ASYNCHRONOUS |
...
+--------------------------------------+--------------+
常见配置说明:
audit_log_buffer_size,在写入日志文件前,可以放在buffer里的日志大小。
audit_log_rotate_on_size,日志文件超过64MB后,会生成一个新的,更方便管理。
audit_log_strategy,日志写入策略,采用默认的ASYNCHRONOUS(异步)即可。
升级审计表结构,主要用于检验集
- ALTER TABLE mysql.audit_log_user DROP FOREIGN KEY audit_log_user_ibfk_1;
- ALTER TABLE mysql.audit_log_filter CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci;
- ALTER TABLE mysql.audit_log_user CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci;
- ALTER TABLE mysql.audit_log_user MODIFY COLUMN USER VARCHAR(32);
- ALTER TABLE mysql.audit_log_user ADD FOREIGN KEY (FILTERNAME) REFERENCES mysql.audit_log_filter(NAME);
4、配置日志输出格式
my.cnf 文件中配置参数
audit_log_format = JSON
重启mysql服务
二、审计规则配置
1、创建拦截规则
# QueryStatistics 为规则名称
- SELECT audit_log_filter_set_filter('QueryStatistics', '{
- "filter": {
- "class": {
- "name": "general",
- "event": {
- "name": "status",
- "print" : {
- "service": {
- "implementation": "mysql_server",
- "tag": "query_statistics",
- "element": [
- {"name": "query_time", "type": "double" },
- {"name": "bytes_sent", "type": "longlong" },
- {"name": "bytes_received", "type": "longlong" },
- {"name": "rows_sent", "type": "longlong" },
- {"name": "rows_examined", "type": "longlong" }
- ]
- }
- }
- }
- }
- }
- }');
2、给用户设置拦截规则
# QueryStatistics 为1步骤的规则名称
select audit_log_filter_set_user('huwj@%', 'QueryStatistics');
3、刷新规则生效
select audit_log_filter_flush();
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。