一、部署mcafee的mysql审计插件
1、下载插件https://bintray.com/mcafee/mysql-audit-plugin/release。
2、解压audit-plugin-mysql-5.5-1.0.5-479-linux-x86_64.zip压缩文件,复制lib目录下libaudit_plugin.so到/usr/local/mysql/lib/plugin。
3、登陆mysql 安装插件
mysql>show plugins;
mysql>INSTALL PLUGIN AUDIT SONAME 'libaudit_plugin.so';
mysql>show plugins;
mysql> set global audit_json_file = on;
mysql> set global audit_record_cmds=
'insert,delete,update,create,drop,alter,grant';
mysql> set global audit_record_objs =' DB1.*,DB2.*';
4、为了保证重启数据库,配置不丢失,修改my.cnf 配置文件,将下面的配置添加到[mysqld]中
plugin-load=AUDIT=libaudit_plugin.so
audit_json_file=ON
audit_record_cmds='insert,delete,update,create,drop,alter,grant'
audit_record_objs='DB1.*,DB2.*'
二、部署审计日志切割脚本和rsync脚本
1、用mysql用户解压audit_archive.zip 到/home/mysql/目录
$ unzip audit_archive.zip -d /home/mysql/
$ chmod u+x /home/mysql/audit_archive/bin/*
$ chmod 600 /home/mysql/audit_archive/config/rsyncd.pass
2、编写 /home/mysql/audit_archive/conf/mysql.cfg配置文件,根据mysql实例个数依次配置每个选项的值,每个选项都必须配置一个确定的值,user的值必须配置为root,且保证所配置的值是正确的,例如:
[3306]
ip=172.xx.xx.xx
user=root
pass=xxxx
port=3306
auditlog=/home/mysql/data3306/mysql-audit.json
socket=/tmp/mysql3306.sock
[3309]
ip=172.xx.xx.xx
user=root
pass=xxxxx
port=3309
auditlog=/home/mysql/data3309/mysql-audit.json
socket=/tmp/mysql3309.sock
2、用mysql用户制定计划任务,配置切换mysql审计日志的时间间隔,可根据mysql审计日志的记录的繁忙程度,配置crontab执行的时间间隔,例如:
a)每30分钟切换mysql审计日志,按30分钟切换
0,30 * * * * bash /home/mysql/audit_archive/bin/service.sh
b)每一小时切换mysql审计日志,按小时切换
0 * * * * bash /home/mysql/audit_archive/bin/service.sh
c)每12个小时切换mysql审计日志,按半天切换
0 12,0 * * * bash /home/mysql/audit_archive/bin/service.sh
d)每天的0点0分切换日志,按天切换
0 0 * * * bash /home/mysql/audit_archive/bin/service.sh