环境介绍:CentOS 6.*
数据库版本:MariaDB 10.0.15/18/21
参考链接:https://mariadb.com/kb/en/mariadb/about-the-mariadb-audit-plugin/
The purpose of the MariaDB Audit Plugin is to log the server's activity. Records about who connected to the server, what queries ran and what tables were touched can be stored to the rotating log file or sent to the local syslogd.
1、如何安装审计插件?
安装方法1:(不停机安装)
MariaDB [(none)]> install plugin server_audit SONAME 'server_audit.so';
MariaDB [(none)]> SHOW GLOBAL VARIABLES like '%audit%';
打开审计功能:
MariaDB [(none)]> set global server_audit_logging=on;
方法2:编辑配置参数,需重启数据库
[mysqld]
plugin-load=server_audit=server_audit.so
server_audit_logging=on;
2、如何卸载与防止审计被卸载?
server_audit=FORCE_PLUS_PERMANENT;
如何卸载审计插件:
MariaDB [(none)]> uninstall plugin server_audit;
3、单独制定审计日志位置?
# touch /var/log/server_audit.log
# chown mysql.mysql /var/log/server_audit.log
4、重要参数解释?
server_audit_events ##审计事件,包括6种(connect,query,table,query_ddl,query_dml,query_dcl)
server_audit_excl_users ##不审计用户server_audit_file_path ##审计日志位置
server_audit_file_rotate_now ##审计日志循环
server_audit_file_rotate_size ##审计日志大小(默认为1G)
server_audit_file_rotations ##审计日志最大循环次数
server_audit_incl_users ##审计那些用户
server_audit_logging ##打开或者关闭审计日志
server_audit_output_type ##审计日志输入格式(file or syslog,默认为file)
参考链接:https://mariadb.com/kb/en/mariadb/server_audit-system-variables/#server_audit_output_type
5、最终参数如下:
##aduit
plugin-load=server_audit=server_audit.so
server_audit_logging=ON
server_audit=FORCE_PLUS_PERMANENT
server_audit_file_path=/var/log/server_audit.log
6、配置日志滚动
#cat /var/log/server_audit.log
/var/log/server_audit.log {
daily
rotate 14
copytruncate
size 1G
compress
missingok
notifempty
sharedscripts
}