mariadbAction Trail

來源:互聯網
上載者:User

標籤:mairadb審計

mariadb可以啟用審計外掛程式來對資料庫的各種操作進行審計,以防營運背鍋!

啟用MariaDB的審計外掛程式,並調整相關參數

MariaDB [(none)]> show variables like ‘%audit%‘;Empty set (0.02 sec)

安裝MariaDB審計外掛程式

MariaDB [(none)]> INSTALL PLUGIN server_audit SONAME ‘server_audit‘;Query OK, 0 rows affected (0.41 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_loc_info         |                       || server_audit_logging          | OFF                   || 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              |

設定相關參數及說明:

1.設定記錄的事件

MariaDB [(none)]> set global server_audit_events=‘connect,query,table‘;Query OK, 0 rows affected (0.00 sec)

 註:connect,query,table可滿足我們所有審計需求

 相關事件說明可參考:https://mariadb.com/kb/en/mariadb/about-the-mariadb-audit-plugin/

2.指定不審計某些使用者的操作

MariaDB [(none)]> set global server_audit_excl_users=‘liuwei‘;Query OK, 0 rows affected (0.01 sec)

3.審計日誌存放的位置

server_audit_file_path        | server_audit.log

4.設定日誌輪轉

MariaDB [(none)]> set global server_audit_file_rotate_now=on;Query OK, 0 rows affected (0.00 sec)

5.設定審計日誌的大小

MariaDB [(none)]> set global server_audit_file_rotate_size=1024*1024*1024;Query OK, 0 rows affected (0.03 sec)

6.開啟審計日誌

MariaDB [(none)]> set global server_audit_logging=on;Query OK, 0 rows affected (0.00 sec)

7.設定日誌可以輪轉的個數

server_audit_file_rotations   | 9

查看設定之後的參數:

MariaDB [(none)]> show variables like ‘%audit%‘;+-------------------------------+-----------------------+| Variable_name                 | Value                 |+-------------------------------+-----------------------+| server_audit_events           | QUERY,TABLE           || server_audit_excl_users       | liuwei                || server_audit_file_path        | server_audit.log      || server_audit_file_rotate_now  | OFF                   || server_audit_file_rotate_size | 1073741824            || server_audit_file_rotations   | 9                     || server_audit_incl_users       |                       || server_audit_loc_info         |                       || 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              |+-------------------------------+-----------------------+

查看審計日誌是否進行記錄:可以記錄增刪改查所有操作

[[email protected] mysql]# cat server_audit.log 20160705 16:25:24,test2,root,localhost,9,2544,QUERY,,‘set global server_audit_logging=on‘,020160705 16:25:38,test2,root,localhost,9,2545,QUERY,,‘show variables like \‘%audit%\‘‘,020160705 16:28:06,test2,root,localhost,9,2546,QUERY,,‘SELECT DATABASE()‘,020160705 16:28:10,test2,root,localhost,9,2548,QUERY,,‘show databases‘,020160705 16:28:44,test2,root,localhost,9,2549,QUERY,,‘create database v1‘,0[[email protected] mysql]# tailf server_audit.log20160705 16:25:24,test2,root,localhost,9,2544,QUERY,,‘set global server_audit_logging=on‘,020160705 16:25:38,test2,root,localhost,9,2545,QUERY,,‘show variables like \‘%audit%\‘‘,020160705 16:28:06,test2,root,localhost,9,2546,QUERY,,‘SELECT DATABASE()‘,020160705 16:28:10,test2,root,localhost,9,2548,QUERY,,‘show databases‘,020160705 16:28:44,test2,root,localhost,9,2549,QUERY,,‘create database v1‘,020160705 16:31:20,test2,root,localhost,9,2552,QUERY,,‘set global server_audit_events=\‘connect,query,table\‘‘,020160705 16:31:30,test2,root,localhost,9,2553,QUERY,,‘show variables like \‘%audit%\‘‘,020160705 16:31:35,test2,root,localhost,9,0,DISCONNECT,,,020160705 16:31:51,test2,root,localhost,24,0,CONNECT,,,020160705 16:31:51,test2,root,localhost,24,2555,QUERY,,‘select @@version_comment limit 1‘,020160705 16:33:44,test2,root,192.168.10.215,25,0,FAILED_CONNECT,,,104520160705 16:33:44,test2,root,192.168.10.215,25,0,DISCONNECT,,,020160705 16:33:53,test2,liuwei,192.168.10.215,26,0,CONNECT,,,020160705 16:35:21,test2,root,localhost,24,2561,QUERY,,‘show variables like \‘%audit%\‘‘,020160705 16:40:22,test2,root,localhost,24,2563,WRITE,mysql,user,20160705 16:40:22,test2,root,localhost,24,2563,WRITE,mysql,db,20160705 16:40:22,test2,root,localhost,24,2563,QUERY,mysql,‘grant all on *.* to [email protected]\‘%\‘ identified by *****‘,0

在設定檔中配置審計參數,因為global重啟後就失效:

[mysqld]

server_audit_events=‘CONNECT,QUERY,TABLE‘

server_audit_logging=on

server_audit_file_rotate_size=200000

server_audit_file_rotations=10

server_audit_excl_users=‘liuwei‘

重啟生效

mariadbAction Trail

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.