赞
踩
1.数据库审计工具介绍及选择
1.1. 数据库审计工具介绍
1.2. 数据库审计工具选择
2. Percona Audit Log
2.1. Percona Audit Log 下载
2.2. Percona Audit Log 安装
1 2 3 4 5 | cp Percona-Server-5.7.28-31-Linux.x86_64.ssl1:111/lib/mysql/plugin/audit_log.so /usr/local/mysql/lib/plugin/ INSTALL PLUGIN audit_log SONAME 'audit_log.so'; ERROR 1126 (HY000): Can't open shared library '/usr/local/mysql/lib/plugin/percona_audit_log.so' (errno: 11 /usr/local/mysql/lib/plugin/percona_audit_log.so: undefined symbol: plugin_thdvar_safe_update) |
另一篇文章给出了判断当前数据库是否可用的方法(Trying to install Audit_log Plugin on MySQL)
2.3. Percona Audit 插件在 Oracle MySQL 分支不可用,所以选择 MariaDB 分支审计插件。
3. MariaDB Audit Plugin
3.1. MariaDB Audit Plugin 的简介
3.2. MariaDB Audit Plugin 的安装
3.2.1. 插件下载
3.2.2. 插件安装
SHOW GLOBAL VARIABLES LIKE 'plugin_dir'; +---------------+--------------------------+ | Variable_name | Value | +---------------+--------------------------+ | plugin_dir | /usr/lib64/mysql/plugin/ | +---------------+--------------------------+ |
cp server_audit.so /usr/lib64/mysql/plugin/ |
INSTALL PLUGIN server_audit SONAME 'server_audit.so'; show plugins; +----------------------------+----------+--------------------+-----------------+---------+ | Name | Status | Type | Library | License | +----------------------------+----------+--------------------+-----------------+---------+ |... | | | | | | SERVER_AUDIT | ACTIVE | AUDIT | server_audit.so | GPL | +----------------------------+----------+--------------------+-----------------+---------+ |
3.2.3. 插件配置
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_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 | +-------------------------------+-----------------------+ |
SET GLOBAL server_audit_logging=ON; |
# 在 mysql datadir 中创建 auditlog 目录 mkdir -p auditlog chown -R mysql:mysql auditlog chmod 750 auditlog |
set global server_audit_file_path='/home/mysql/mysql57_3306/auditlog/server_audit.log'; |
1 2 3 4 5 6 7 8 | set global server_audit_events='CONNECT,QUERY,TABLE,QUERY_DDL,QUERY_DML,QUERY_DCL'; set global server_audit_output_type= file; set global server_audit_logging = 1; set global server_audit_file_rotate_size = 500000000; set global server_audit_file_rotations = 3; set global server_audit_incl_users = ''; set global server_audit_excl_users = ''; set global server_audit_query_log_limit = 4096; |
3.2.4. 卸载
UNINSTALL PLUGIN server_audit; |
[mysqld] server_audit=FORCE_PLUS_PERMANENT |
3.2.4. 配置文件参数
1 2 3 4 5 6 7 8 9 | loose-server_audit_file_path='/data/mysql/mysql57_3306/auditlog/server_audit.log' loose-server_audit_events='CONNECT,QUERY,TABLE,QUERY_DDL,QUERY_DML,QUERY_DCL' loose-server_audit_output_type= file loose-server_audit_logging = 1 loose-server_audit_file_rotate_size = 500000000 loose-server_audit_file_rotations = 3 loose-server_audit_incl_users = '' loose-server_audit_excl_users = '' loose-server_audit_query_log_limit = 4096 |
3.3. MariaDB Audit Plugin 的日志格式
[timestamp],[serverhost],[username],[host],[connectionid],[queryid],[operation],[database],[object],[retcode] |
日志项 | 描述 | ||
[timestamp][syslog_host][syslog_ident]:[syslog_info][serverhost],[username],[host],[connectionid],[queryid],[operation],[database],[object],[retcode] | |||
timestamp | 事件发生的时间。如果使用syslog,则格式由 syslogd 定义 | ||
syslog_host | 接收系统日志条目的主机 | ||
syslog_ident | 用于标识系统日志条目,包括MariaDB服务器 | ||
syslog_info | 用于提供标识系统日志条目的信息 | ||
serverhost | MariaDB服务器主机名 | ||
username | 连接的用户 | ||
host | 用户连接的主机 | ||
connectionid | 相关操作的连接标识号 | ||
queryid | 查询ID号,可用于查找关系表事件和相关查询。对于TABLE事件,将添加多行 | ||
operation | 记录的动作类型:CONNECT,QUERY,READ,WRITE,CREATE,ALTER,RENAME,DROP | ||
database | 活动数据库(由 USE 设置) | ||
object | 对QUERY事件或TABLE事件的表名执行查询 | ||
retcode | 返回已记录操作的代码 | ||
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。