mysql 5.6 社区版上审计功能,不扯皮
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 5.6 社区版上审计功能,不扯皮相关的知识,希望对你有一定的参考价值。
官网
https://mariadb.com/kb/en/mariadb/about-the-mariadb-audit-plugin/
一、环境说明
mysql 5.6.25 社区版
Mariadb 10.0.25 社区版
mysql 企业版有审计功能需要收费,社区版被阉割的不行不行了,和古时候的太监
没啥区别了,比较重要的功能特性都没有,不过也能凑合着用。可能说的有点过,
话糙理不糙,建议用不起企业版的可以考虑percona 和 mariadb,个人建议,仅供参考。
二、安装
1.下载mariadb 10.0.25_x64 安装包,解压缩上传server_audit.so 文件到/tmp 目录下
2. 查看插件路径
([email protected]) [(none)]> show variables like ‘plugin_dir‘; +---------------+--------------------------+ | Variable_name | Value | +---------------+--------------------------+ | plugin_dir | /usr/lib64/mysql/plugin/ | +---------------+--------------------------+ 1 row in set (0.00 sec)
3.cp 插件,授予执行权限
# cp /tmp/server_audit.so /usr/lib64/mysql/plugin/ # chmod +x /usr/lib64/mysql/plugin/server_audit.so #
4.安装插件
([email protected]) [(none)]> install plugin server_audit SONAME ‘server_audit.so‘; Query OK, 0 rows affected (0.00 sec)
5.查看参数
([email protected]) [(none)]> show variables like ‘%audit%‘; +-------------------------------+-----------------------+ | Variable_name | Value | +-------------------------------+-----------------------+ | server_audit_events | | | server_audit_excl_users | | | server_audit_file_path | server_audit.log | | server_audit_file_rotate_now | OFF | | server_audit_file_rotate_size | 1000000 | | server_audit_file_rotations | 9 | | server_audit_incl_users | | | server_audit_loc_info | | | server_audit_logging | OFF | | server_audit_mode | 1 | | server_audit_output_type | file | | server_audit_query_log_limit | 1024 | | server_audit_syslog_facility | LOG_USER | | server_audit_syslog_ident | mysql-server_auditing | | server_audit_syslog_info | | | server_audit_syslog_priority | LOG_INFO | +-------------------------------+-----------------------+ 16 rows in set (0.00 sec)
6.修改参数
([email protected]) [(none)]> set global server_audit_logging=on; Query OK, 0 rows affected (0.00 sec) ([email protected]) [(none)]> set global server_audit_file_rotate_now=ON; Query OK, 0 rows affected (0.00 sec)
7.查看审计日志路径
# find / -name server_audit.log /data/mysqldata/server_audit.log --默认在数据路径下
# tail -f /data/mysqldata/server_audit.log 20161226 22:46:38,mysql91,root,localhost,1,3,QUERY,,‘set global server_audit_logging=on‘,0 20161226 22:46:58,mysql91,root,localhost,1,4,QUERY,,‘show variables like \‘%audit%\‘‘,0 20161226 22:48:36,mysql91,root,localhost,1,5,QUERY,,‘show databases‘,0 20161226 22:49:27,mysql91,root,localhost,1,6,QUERY,,‘GRANT ALL PRIVILEGES ON *.* TO \‘roidba\‘@\‘%\‘ IDENTIFIED BY PASSWORD *****‘,0
三、正式环境需要解决两个问题
1.日志路径要规范
([email protected]) [(none)]> set global server_audit_file_path=‘/data/mysqllogs/‘; Query OK, 0 rows affected (0.00 sec)
2.通常查询不需要审计(mysql 测试过滤不掉,mariadb 可以)
([email protected]) [(none)]> set global server_audit_events=‘query_ddl,query_dml‘; Query OK, 0 rows affected (0.00 sec)
3.固化参数
vi /etc/my.cnf ########mariadb 10.0.25 audit plugin####### server_audit_logging=on server_audit_events=‘query_dml,query_ddl‘ server_audit_file_path =/data/mysqllogs/ server_audit_file_rotate_size=200000000 server_audit_file_rotations=200
4.建议重启
service mysql restart
本文出自 “roidba” 博客,请务必保留此出处http://roidba.blog.51cto.com/12318731/1886301
以上是关于mysql 5.6 社区版上审计功能,不扯皮的主要内容,如果未能解决你的问题,请参考以下文章