美文网首页
20210121--mysql开启数据库日志审计功能

20210121--mysql开启数据库日志审计功能

作者: 負笈在线 | 来源:发表于2021-03-23 23:18 被阅读0次

一、MYSQL审计方法分类

1.借助init-connect和binlog实现变相审计,不过不能对root用户(超级权限的用户)进行审计。

2.MYSQL 企业版增加MySQL Enterprise Audit Plugin

3.macfee公司基于percona开发的mysql audit插件:支持MYSQL、MariaDB、percona

4.MariaDB Audit Plugin(只支持MariaDB)

二、macfee的mysql audit插件安装

1.解压插件包

# unzip audit-plugin-mysql-5.5-1.0.9-585-linux-x86_64.zip

2.执行命令获取MySQL的plugin目录

mysql> SHOW GLOBAL VARIABLES LIKE 'plugin_dir';

+---------------+-------------------------------+

| Variable_name | Value                        |

+---------------+-------------------------------+

| plugin_dir    | /www/server/mysql/lib/plugin/ |

+---------------+-------------------------------+

1 row in set (0.01 sec)

3.将解压好的插件复制到 MySQL 的插件目录下

# cp /root/audit-plugin-mysql-5.5-1.0.9-585/lib/libaudit_plugin.so /www/server/mysql/lib/plugin/

# chmod a+x /www/server/mysql/lib/plugin/libaudit_plugin.so

4.安装插件

mysql> install plugin audit soname 'libaudit_plugin.so';

如果出现以下报错,使用offset-extract.sh工具解决。

ERROR 1123 (HY000): Can't initialize function 'audit'; Plugin initialization function failed.

5.查看插件功能是否开启

mysql> show variables like '%audit_json_file%';

+-------------------------+-------+

| Variable_name          | Value |

+-------------------------+-------+

| audit_json_file        | OFF  |

| audit_json_file_bufsize | 1    |

| audit_json_file_flush  | OFF  |

| audit_json_file_retry  | 60    |

| audit_json_file_sync    | 0    |

+-------------------------+-------+

6.查看mysql当前已经加载了哪些插件

mysql> show plugins;

+--------------------------+----------+--------------------+---------+---------+

| Name                    | Status  | Type              | Library | License |

+--------------------------+----------+--------------------+---------+---------+

| binlog                  | ACTIVE  | STORAGE ENGINE    | NULL    | GPL    |

| mysql_native_password    | ACTIVE  | AUTHENTICATION    | NULL    | GPL    |

| mysql_old_password      | ACTIVE  | AUTHENTICATION    | NULL    | GPL    |

| CSV                      | ACTIVE  | STORAGE ENGINE    | NULL    | GPL    |

| MEMORY                  | ACTIVE  | STORAGE ENGINE    | NULL    | GPL    |

| MyISAM                  | ACTIVE  | STORAGE ENGINE    | NULL    | GPL    |

| MRG_MYISAM              | ACTIVE  | STORAGE ENGINE    | NULL    | GPL    |

7.查看插件版本

mysql> show global status like '%audit%';

mysql> show global status like '%binlog%';

+----------------------------+--------+

| Variable_name              | Value  |

+----------------------------+--------+

| Binlog_cache_disk_use      | 3      |

| Binlog_cache_use          | 379    |

| Binlog_stmt_cache_disk_use | 2      |

| Binlog_stmt_cache_use      | 850687 |

| Com_binlog                | 0      |

| Com_show_binlog_events    | 0      |

| Com_show_binlogs          | 1      |

+----------------------------+--------+

7 rows in set (0.01 sec)

8.开启Audit功能

mysql> SET GLOBAL audit_json_file=ON;

Query OK, 0 rows affected (0.00 sec)

9.可以查看插件有哪些可配置的参数

mysql> SHOW GLOBAL VARIABLES LIKE '%audi%';

mysql> SHOW GLOBAL VARIABLES LIKE '%binlog%';

+-----------------------------------------+----------------------+

| Variable_name                          | Value                |

+-----------------------------------------+----------------------+

| binlog_cache_size                      | 32768                |

| binlog_direct_non_transactional_updates | OFF                  |

| binlog_format                          | MIXED                |

| binlog_stmt_cache_size                  | 32768                |

| innodb_locks_unsafe_for_binlog          | OFF                  |

| max_binlog_cache_size                  | 18446744073709547520 |

| max_binlog_size                        | 1073741824          |

| max_binlog_stmt_cache_size              | 18446744073709547520 |

| sync_binlog                            | 0                    |

+-----------------------------------------+----------------------+

9 rows in set (0.01 sec)

10.Audit需要关注的参数有:

audit_json_file是否开启audit功能。

audit_json_log_file记录文件的路径和名称信息(默认放在mysql数据目录下)。

audit_record_cmds audit记录的命令,默认为记录所有命令。可以设置为任意dml、dcl、ddl的组合。如:audit_record_cmds=select,insert,delete,update。还可以在线设置set global audit_record_cmds=NULL。(表示记录所有命令)

audit_record_objsaudit记录操作的对象,默认为记录所有对象,可以用SET GLOBAL audit_record_objs=NULL设置为默认。也可以指定为下面的格式:audit_record_objs=,test.*,mysql.*,information_schema.*。

audit_whitelist_users用户白名单。

11.为了保证重启数据库,配置不丢失,修改my.cnf配置文件,将下面的配置添加到 [mysqld] 中,所以在配置文件中my.cnf加入参数:

audit_json_file=on    #保证mysql重启后自动启动插件

plugin-load=AUDIT=libaudit_plugin.so    #防止删除了插件,重启后又会加载

audit_record_cmds='insert,delete,update,create,drop,alter,grant,truncate'  #要记录哪些命令语句,因为默认记录所有操作;

audit_offsets=7824, 7872, 3632, 4792, 456, 360, 0, 32, 64, 160, 536, 7988, 4360, 3648, 3656, 3660, 6072, 2072, 8, 7056, 7096, 7080, 13464, 148, 672

12.卸载插件的方法

mysql> uninstall plugin audit;

URL:

https://dl.bintray.com/mcafee/mysql-audit-plugin/

https://bintray.com/mcafee/mysql-audit-plugin/release

https://github.com/mcafee/mysql-audit/wiki

https://github.com/mcafee/mysql-audit/blob/master/offset-extract/offset-extract.sh

https://www.cnblogs.com/waynechou/p/mysql_audit.html

相关文章

  • 20210121--mysql开启数据库日志审计功能

    一、MYSQL审计方法分类 1.借助init-connect和binlog实现变相审计,不过不能对root用户(超...

  • 利用mysql注释实现审计功能

    目前mysql审计功能,大都是通过开启审计插件或者在中间件上吐出日志记录到相应的存储设备上,是可以实现审计功能的,...

  • MariaDB开启日志审计功能

    对于MySQL、Percona、MariaDB三家都有自己的审计插件,但是MySQL的审计插件是只有企业版才有的,...

  • MySQL审计插件介绍

    前言: 数据库审计功能主要将用户对数据库的各类操作行为记录审计日志,以便日后进行跟踪、查询、分析,以实现对用户操作...

  • MySQL开启日志及查看

    登录mysql数据库 检查日志功能是否开启 log_bin为OFF,表明binlog日志未开启 查找mysql的配...

  • 等保测评需要解决的问题

    等保测评问题汇总 1,终端开启安全审计策略 2.开启密码策略 3.终端未启用登录失败处理功能 4.终端未开启日志审...

  • 阿里云操作审计 - 日志安全分析(一)

    摘要:阿里云操作审计ActionTrail审计日志已经与日志服务打通,提供准实时的审计分析、开箱机用的报表功能。本...

  • Kubernetes审计日志功能

    1. 背景 从kubernetes 1.6版本开始支持审计功能,到1.12版本审计功能GA,而本文则是针对kube...

  • kubernetes 审计日志功能

    审计日志可以记录所有对 apiserver 接口的调用,让我们能够非常清晰的知道集群到底发生了什么事情,通过记录的...

  • hadoop日志审计

    1、配置 hadoop开启审计日志需要修改hadoop-env.sh export HADOOP_NAMENODE...

网友评论

      本文标题:20210121--mysql开启数据库日志审计功能

      本文链接:https://www.haomeiwen.com/subject/gdldzktx.html