MySQL的社區版沒有審計功能,企業版才有審計功能。企業版中自帶 Audit Plugin ,名為audit_log.so。但是其它MySQL分支版本也開發了各自的審計功能插件。最常見的就是Percona Audit Log Plugin、MariaDB Audit Plugin、當然還有通用插件M... ...
MySQL的社區版沒有審計功能,企業版才有審計功能。企業版中自帶 Audit Plugin ,名為audit_log.so。但是其它MySQL分支版本也開發了各自的審計功能插件。最常見的就是Percona Audit Log Plugin、MariaDB Audit Plugin、當然還有通用插件McAfee MySQL Audit Plugin。 如果MySQL社區版想上審計功能的話,能否使用這三個插件呢?答案是社區版MySQL可以使用MariaDB Audit Plugin和McAfee MySQL Audit Plugin,Percona Audit Log Plugin是僅供Percona Server使用的免費插件,下麵我們來學習、總結一下,在MySQL社區版中如何使用MariaDB Audit Plugin插件來做資料庫的跟蹤、審計。
插件介紹
下麵是官方網址關於MariaDB Audit Plugin的介紹,更多資料請參考https://mariadb.com/kb/en/mariadb-audit-plugin/
MariaDB and MySQL are used in a broad range of environments, but if you needed to record user access to be in compliance with auditing regulations for your organization, you would previously have had to use other database solutions. To meet this need, though, MariaDB has developed the MariaDB Audit Plugin. Although the MariaDB Audit Plugin has some unique features available only for MariaDB, it can be used also with MySQL.
Basically, the purpose of the MariaDB Audit Plugin is to log the server's activity. For each client session, it records who connected to the server (i.e., user name and host), what queries were executed, and which tables were accessed and server variables that were changed. This information is stored in a rotating log file or it may be sent to the local syslogd.
The MariaDB Audit Plugin works with MariaDB, MySQL (as of, version 5.5.34 and 10.0.7) and Percona Server. MariaDB started including by default the Audit Plugin from versions 10.0.10 and 5.5.37, and it can be installed in any version from MariaDB 5.5.20.
插件下載
目前而言,官方並沒有提供單獨MariaDB Audit Plugin下載地址,所以你必須下載MariaDB的安裝包,然後從安裝包中找到插件的文件。
官方下載地址:
https://downloads.mariadb.org/mariadb/+releases/
這裡我們下載mariadb-5.5.64-linux-systemd-x86_64.tar.gz測試驗證一下。插件server_audit.so一般位於目錄./lib/plugin下麵。
插件安裝
MySQL的插件必須放在plugin_dir目錄下麵,所以首先查看當前社區版本MySQL的系統變數plugin_dir(插件路徑)
mysql> select version() from dual;
+------------+
| version() |
+------------+
| 5.7.21-log |
+------------+
1 row in set (0.00 sec)
mysql> show variables like 'plugin_dir';
+---------------+--------------------------+
| Variable_name | Value |
+---------------+--------------------------+
| plugin_dir | /usr/lib64/mysql/plugin/ |
+---------------+--------------------------+
1 row in set (0.01 sec)
mysql>
將server_audit.so文件拷貝到系統變數plugin_dir對應的目錄下麵。
# cd /tmp
# tar -xzvf mariadb-5.5.64-linux-systemd-x86_64.tar.gz
# cd mariadb-5.5.64-linux-systemd-x86_64
# find ./ -name "server_audit.so"
./lib/plugin/server_audit.so
# cp /tmp/mariadb-5.5.64-linux-systemd-x86_64/lib/plugin/server_audit.so /usr/lib64/mysql/plugin/
# chmod +x server_audit.so
在安裝MySQL插件MariaDB Audit Plugin前,先確認系統glibc版本是否匹配編譯server_audit.so的glibc版本。MariaDB一般多使用2.14版glibc進行編譯。如果沒有2.14版本的glibc,很有可能出現下麵錯誤,如下所示:
# strings /lib64/libc.so.6 |grep GLIBC_
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_PRIVATE
mysql> INSTALL PLUGIN server_audit SONAME 'server_audit.so';
ERROR 1126 (HY000): Can't open shared library '/usr/lib64/mysql/plugin/server_audit.so' (errno: 2 /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /usr/lib64/mysql/plugin/server_audit.so))
mysql>
安裝glibc2.14,簡單步驟如下,安裝glibc2.14可能會遇到一些問題,此篇不做展開講述。
# wget -c http://ftp.gnu.org/gnu/libc/glibc-2.14.tar.gz
# tar -zxvf glibc-2.14.tar.gz
# cd glibc-2.14
# mkdir build
# cd build
# ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
#make && make install
安裝完成後,驗證是否安裝成功。
# ll /lib64/libc.so.6
lrwxrwxrwx 1 root root 12 May 23 18:28 /lib64/libc.so.6 -> libc-2.14.so
# strings /lib64/libc.so.6 |grep GLIBC_
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_PRIVATE
註意,安裝完2.14版本的glibc後,必須重啟MySQL,否則在安裝補丁過程中,依然報上面錯誤
mysql> INSTALL PLUGIN server_audit SONAME 'server_audit.so';
ERROR 1126 (HY000): Can't open shared library '/usr/lib64/mysql/plugin/server_audit.so' (errno: 2 /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /usr/lib64/mysql/plugin/server_audit.so))
重啟MySQL實例後,安裝成功。如下所示: