MySQL之MariaDB启用审计插件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL之MariaDB启用审计插件相关的知识,希望对你有一定的参考价值。
对于mysql Percona MariaDB三家都有自己的审计插件,但是呢,MySQL的审计插件是只有企业版才有的,同时也有很多第三方的的MySQL的审计插件,而Percona和MariaDB都是GPL的审计插件
首先看一下mariaDB 的审计插件
[[email protected]_Aolens_01 /usr/local/mysql]# mysql -uroot -p2aa263a42dd248 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 42804 Server version: 10.0.14-MariaDB-log Source distribution Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. MariaDB [(none)]> show variables like ‘%audit%‘; Empty set (0.00 sec) MariaDB [(none)]> INSTALL PLUGIN server_audit SONAME ‘server_audit.so‘; #安装审计插件 Query OK, 0 rows affected (0.18 sec) MariaDB [(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_logging | OFF | | 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 | +-------------------------------+-----------------------+ 14 rows in set (0.00 sec) MariaDB [(none)]> SHOW VARIABLES LIKE ‘plugin_dir‘; #插件地址路径 +---------------+------------------------------+ | Variable_name | Value | +---------------+------------------------------+ | plugin_dir | /usr/local/mysql/lib/plugin/ | +---------------+----------------------------- + 1 row in set (0.00 sec)
如果想永久加载,只需在配置文件里指定如下行即可,此时卸载该插件时会报错,插件将无法卸载,直到配置文件变更
[mysqld] plugin-load=server_audit=server_audit.so server_audit=FORCE_PLUS_PERMANENT
命令行启用audit ,重启后失效
MariaDB [(none)]> set global server_audit_file_rotate_size=1024*1024*1024; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> set global server_audit_events=‘query,table‘; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> set global server_audit_file_rotate_now=on; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> set global server_audit_logging=‘ON‘; Query OK, 0 rows affected (0.00 sec)
为了使MySQL重启设置的变量仍然生效,需要在配置文件添加相应配置:
[mysqld]
server_audit_events=‘CONNECT,QUERY,TABLE‘
server_audit_logging=on
server_audit_file_rotate_size=2000000
server_audit_file_rotations=10
查看审计日志:
[[email protected]_Aolens_01 ~]# tail -n 20 /mydata/data/server_audit.log
参数说明:
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:标识版本,用于开发测试
MYSQL 添加审计功能:
wget https://dl.bintray.com/mcafee/mysql-audit-plugin/:audit-plugin-mariadb-10.0-1.1.0-625-linux-x86_64.zip unzip audit-plugin-mariadb-10.0-1.1.0-625-linux-x86_64.zip cd audit-plugin-mariadb-10.0-1.1.0-625/lib mysql -uroot -p -e "show global variables like ‘plugin_dir‘;" ‘plugin_dir‘, ‘/usr/local/mysql/lib/plugin/‘
#拷贝插件到mysql的插件目录
cp libaudit_plugin.so /usr/local/mysql/lib/plugin/‘
#安装审计插件
mysql -uroot -p -e "INSTALL PLUGIN AUDIT SONAME ‘libaudit_plugin.so‘;"
其他配置和MariaDB一样
MariaDB审计插件变量解释:https://mariadb.com/kb/en/mariadb/server_audit-system-variables/#server_audit_events
MariaDB审计插件介绍:https://mariadb.com/kb/en/mariadb/about-the-mariadb-audit-plugin/
Percona的审计插件:https://www.percona.com/blog/2014/05/07/mysql-audit-plugin-now-available-in-percona-server-5-5-and-5-6/
https://www.percona.com/doc/percona-server/5.6/management/audit_log_plugin.html
MySQL的审计插件:https://dev.mysql.com/doc/refman/5.5/en/audit-log-installation.html
第三方的MySQL审计插件:https://github.com/mcafee/mysql-audit
本文出自 “aolens·程超” 博客,请务必保留此出处http://aolens.blog.51cto.com/7021142/1868900
以上是关于MySQL之MariaDB启用审计插件的主要内容,如果未能解决你的问题,请参考以下文章