背景
最近项目要验收了,数据库的一个验收标准就是要有数据库审计,所以参照资料安装了Mysql的审计插件。
正文
一、下载插件
下载地址:https://bintray.com/mcafee/mysql-audit-plugin/release/1.1.4-725#files
可选择对应MySQL5.7数据库的最新审计插件,这里以audit-plugin-mysql-5.7-1.1.7-805-linux-x86_64.zip为例。
二、解压插件
[root@mysql]#unzip audit-plugin-mysql-5.7-1.1.7-805-linux-x86_64.zip
[root@mysql]#cp audit-plugin-mariadb-10.2-1.1.4-725/lib/libaudit_plugin.so [root@mysql]#/usr/local/mysql/plugin/
[root@mysql]#chmod +x libaudit_plugin.so
[root@mysql]#chown mysql:mysql libaudit_plugin.so
三、登录数据库进行安装
mysql> install plugin audit soname 'libaudit_plugin.so';
如果报错信息如下:
ERROR 1123 (HY000): Can't initialize function 'audit'; Plugin initialization function failed.
解决办法:
1)授权,加载
[root@mysql]#cd audit-plugin-mysql-5.7-1.1.4-725/utils [root@mysql]#chmod +x offset-extract.sh [root@mysql]#./offset-extract.sh /usr/local/mysql/bin/mysqld
2)编辑/etc/my.cnf
plugin-load=audit=libaudit_plugin.so audit_offsets = 7824, 7872, 3632, 4792, 456, 360, 0, 32, 64, 160, 536, 7988, 4360, 3648, 3656, 3660, 6072, 2072, 8, 7056, 7096, 7080 audit_json_file = on audit_record_cmds = 'insert,delete,update,create,drop,alter,grant,truncate'
其中audit_offsets的内容,可以根据执行offset-extract.sh脚本的结果来配置,每个版本有一些差异
3)重启mysql
[root@mysql]#/etc/init.d/mysql.service restart
mysql> install plugin audit soname 'libaudit_plugin.so';
四、查看日志
[root@mysql]# find / -name mysql-audit.json
[root@mysql]# tail -f /usr/local/mysql/mysql-audit.json