MariaDB [(none)]> INSTALL PLUGIN server_audit SONAME 'server_audit'; MariaDB [(none)]> show plugins; +-----------------------------+----------+--------------------+-----------------+---------+ | Name | Status | Type | Library | License | +-----------------------------+----------+--------------------+-----------------+---------+ | SERVER_AUDIT | ACTIVE | AUDIT | server_audit.so | GPL | +-----------------------------+----------+--------------------+-----------------+---------+
- 手动安装通过MariaDB官网下载最新的audit审计插件:
https://mariadb.com/kb/en/mariadb-audit-plugin/
- 登陆MariaDB查看audit插件存放路径:
MariaDB [(none)]> SHOW VARIABLES LIKE 'plugin_dir'; +---------------+-------------------------------+ | Variable_name | Value | +---------------+-------------------------------+ | plugin_dir | /www/server/mysql/lib/plugin/ | +---------------+-------------------------------+ 1 row in set (0.00 sec)
- 将audit插件拷贝到plugindir目录下“ /www/server/mysql/lib/plugin/ ”,执行命令安装并启用:
MariaDB [(none)]> install plugin server_audit SONAME 'server_audit.so'; MariaDB [(none)]> SET GLOBAL server_audit_logging=ON; MariaDB [(none)]> SET GLOBAL server_audit_file_rotate_now=ON; MariaDB [(none)]> SHOW GLOBAL STATUS LIKE 'server_audit%'; +----------------------------+------------------+ | Variable_name | Value | +----------------------------+------------------+ | Server_audit_active | ON | | Server_audit_current_log | server_audit.log | | Server_audit_last_error | | | Server_audit_writes_failed | 0 | +----------------------------+------------------+
- 卸载命令如下:
UNINSTALL PLUGIN 'server_audit';
- 通过以上命令启用audit后,重启MariaDB后会失效,通过添加以下参数到my.cnf可以永久生效:
[mysqld] plugin-load=server_audit=server_audit.so server_audit=FORCE_PLUS_PERMANENT
- audit审计插件其他参数设置
MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE "server_audit%"; +-------------------------------+-----------------------+ | Variable_name | Value | +-------------------------------+-----------------------+ | server_audit_events | 'CONNECT,QUERY,TABLE' | | 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_logging | ON | | server_audit_mode | 0 | | server_audit_output_type | file | | server_audit_syslog_facility | LOG_USER | | server_audit_syslog_ident | mysql-server_auditing | | server_audit_syslog_info | | | server_audit_syslog_priority | LOG_INFO | +-------------------------------+-----------------------+
参数说明:
server_audit_output_type:指定日志输出类型,可为SYSLOG或FILE
server_audit_logging:启动或关闭审计
server_audit_events:指定记录事件的类型,可以用逗号分隔的多个值(connect,query,table),如果开启了查询缓存(query cache),查询直接从查询缓存返回数据,将没有table记录
server_audit_file_path:如server_audit_output_type为FILE,使用该变量设置存储日志的文件,可以指定目录,默认存放在数据目录的server_audit.log文件中
server_audit_file_rotate_size:限制日志文件的大小
server_audit_file_rotations:指定日志文件的数量,如果为0日志将从不轮转
server_audit_file_rotate_now:强制日志文件轮转
server_audit_incl_users:指定哪些用户的活动将记录,connect将不受此变量影响,该变量比server_audit_excl_users优先级高
server_audit_syslog_facility:默认为LOG_USER,指定facility
server_audit_syslog_ident:设置ident,作为每个syslog记录的一部分
server_audit_syslog_info:指定的info字符串将添加到syslog记录
server_audit_syslog_priority:定义记录日志的syslogd priority
server_audit_excl_users:该列表的用户行为将不记录,connect将不受该设置影响
server_audit_mode:标识版本,用于开发测试