MariaDB Audit Plugin 将日志保存到 syslog

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
日志服务 SLS,月写入数据量 50GB 1个月
简介: Syslog 使用广泛,对日志进行独立存储。而且有很多的工具可对 syslog 数据进行聚合、监控、查询和分析。

Syslog 使用广泛,对日志进行独立存储。而且有很多的工具可对 syslog 数据进行聚合、监控、查询和分析。Syslog 数据可以当成是一个中央资料库。

你也可以在 MariaDB 中将日志写到 Syslog 中,步骤很简单:

首先下载 MariaDB 的 audit 插件

然后将 server_audit.so 文件拷贝到你的 MySQL/MariaDB 下的 lib/plugin 目录,并通过如下命令激活该插件:

view source

print?

1 MariaDB [(none)]> INSTALL PLUGIN server_audit SONAME'server_audit.so';

系统默认的日志是写到文件,我们需要改为 Syslog:

view source

print?

1 MariaDB [test]> SETGLOBAL server_audit_output_type=SYSLOG;
2 MariaDB [test]> SETGLOBAL server_audit_events='CONNECT,QUERY';
3 MariaDB [test]> SETGLOBAL server_audit_logging=on;

相关的配置项如下:

view source

print?

01 MariaDB [test]> show variables like '%audit%';
02 +-------------------------------------+-----------------------+
03 | Variable_name                       | Value                 |
04 +-------------------------------------+-----------------------+
05 | server_audit_events                 |CONNECT,QUERY         |
06 | server_audit_excl_users |           |                       |
07 | server_audit_file_path              | server_audit.log      |
08 | server_audit_file_rotate_now        |OFF                   |
09 | server_audit_file_rotate_size       | 1000000               |
10 | server_audit_file_rotations         | 9                     |
11 | server_audit_incl_users             |                       |
12 | server_audit_logging                |ON                    |
13 | server_audit_mode                   | 0                     |
14 | server_audit_output_type            | syslog                |
15 | server_audit_syslog_facility        | LOG_USER              |
16 | server_audit_syslog_ident           | mysql-server_auditing |
17 | server_audit_syslog_info            |                       |
18 | server_audit_syslog_priority        | LOG_INFO              |
19 +-------------------------------------+-----------------------+
20 14 rowsin set (0.00 sec)

运行状态信息:

view source

print?

01 MariaDB [test]> show status like'%audit%';
02 +------------------------------ +--------------+
03 | Variable_name                 | Value        |
04 +----------------------------- -+--------------+
05 | server_audit_active           | ON           |
06 | server_audit_current_log      | [SYSLOG]     |
07 | server_audit_last_error       |              |
08 | server_audit_writes_failed    | 0            |
09 +-------------------------------+--------------+
10 4 rowsin set (0.00 sec)

确保 rsyslog 在运行:

view source

print?

1 [root@centos1 log]# service rsyslog restart
2 Shutting down system logger: [ OK ]
3 Starting system logger: [ OK ]

现在所有连接和查询 MariaDB 的动作都会写到 syslog 日志里:

view source

print?

1 [root@centos1 log]# tail -f /var/log/messages
2 Sep 21 00:07:07 centos1 mysql-server_auditing: centos1.localdomain,root,localhost,1,10,QUERY,,'set global server_audit_logging=on',0
3 Sep 21 00:07:11 centos1 mysql-server_auditing: centos1.localdomain,root,localhost,1,11,QUERY,,'show status like \'%audit%\'',0
4 Sep 21 00:07:21 centos1 mysql-server_auditing: centos1.localdomain,root,localhost,1,12,QUERY,,'show variables like \'%audit%\'',0
5 Sep 21 00:10:06 centos1 mysql-server_auditing: centos1.localdomain,root,localhost,1,13,QUERY,,'set global server_audit_events=\'CONNECT,QUERY\'',0
6 Sep 21 00:13:09 centos1 mysql-server_auditing: centos1.localdomain,root,localhost,1,14,QUERY,,'SELECT DATABASE()',0
7 Sep 21 00:13:09 centos1 mysql-server_auditing: centos1.localdomain,root,localhost,1,16,QUERY,test,'show databases',0
8 Sep 21 00:13:09 centos1 mysql-server_auditing: centos1.localdomain,root,localhost,1,17,QUERY,test,'show tables',0
9 Sep 21 00:13:14 centos1 mysql-server_auditing: centos1.localdomain,root,localhost,1,18,QUERY,test,'show tables',0

日志写到 /var/log/messages 文件是由 /etc/rsyslog.conf 进行配置的:

view source

print?

1 *.info;mail.none;authpriv.none;cron.none /var/log/messages

如果你想要将日志写到不同的文件,可以:

view source

print?

1 if $programname == 'mysql-server_auditing' then /var/log/mariadbaudit1

使用 MariaDB Audit Plugin 对安全和系统管理来说是一个好的选择。

英文原文:http://serge.frezefond.com/2013/09/mariadb-audit-plugin-logging-to-syslog/

目录
相关文章
|
5月前
|
安全 Ubuntu Unix
/var/log/syslog日志说明
`/var/log/syslog`是Unix和Linux的日志文件,记录系统事件和消息,由`syslogd`或`rsyslogd`生成。日志条目含时间戳、主机名、PID、日志级别(如DEBUG、ERROR)和事件描述。内容涵盖系统启动/关闭、硬件错误、网络、用户登录、安全事件等。查看日志可使用`cat`、`tail`、`less`或`grep`命令。不过,不同Linux发行版可能有变,如Ubuntu使用`journald`和`journalctl`。
519 3
|
5月前
|
Kubernetes 容器
k8s学习-CKS真题-日志审计 log audit
k8s学习-CKS真题-日志审计 log audit
158 0
|
2月前
|
存储 网络协议 Linux
在Linux中,如何通过syslog进行远程日志转发?
在Linux中,如何通过syslog进行远程日志转发?
|
3月前
|
Unix Python
Python代码示例:使用`syslog`模块进行日志记录
Python代码示例:使用`syslog`模块进行日志记录
|
5月前
|
运维 安全 Ubuntu
`/var/log/syslog` 和 `/var/log/messages` 日志详解
`/var/log/syslog` 和 `/var/log/messages` 是Linux系统的日志文件,分别在Debian和Red Hat系发行版中记录系统事件和错误。它们包含时间戳、日志级别、PID及消息内容,由`rsyslog`等守护进程管理。常用命令如`tail`和`grep`用于查看和搜索日志。日志级别从低到高包括`debug`到`emerg`,表示不同严重程度的信息。注意保护日志文件的安全,防止未授权访问,并定期使用`logrotate`进行文件轮转以管理磁盘空间。
2078 1
|
数据采集 网络安全
syslog日志接口调试方法
日志数据采集,比较方便常用的就是通过syslog来进行数据采集,syslog可以通过udp协议来进行高效的数据传输。一般来说在工程实施的过程中需要对接对端系统的数据采集源可以通过以下步骤来进行syslog日志接口的调试。主要是验证syslog日志是否能正常送到指定的日志服务器的指定端口,日志服务器的指定端口是否能正常收到对端发过来的日志。
252 0
syslog日志接口调试方法
|
5月前
|
数据采集 监控 网络协议
使用函数计算(FC)通过Syslog协议投递日志
本文主要介绍一种使用函数计算(FC)通过Syslog协议投递日志的方法。
145 0
使用函数计算(FC)通过Syslog协议投递日志
|
运维 网络协议 Ubuntu
flume 通过syslog协议读取系统日志
flume 通过syslog协议读取系统日志
|
Oracle 关系型数据库 MySQL
迁移MariaDB审计插件(Audit Plugin)到MySQL 5.7---发表到爱可生开源社区
Oracle的MySQL社区版本不带审计插件(Audit Plugin),要想使用审计功能,你可以用Enterprise的版本,不过这需要银子。业界还有一些GPL协议的审计插件,这里我们选择MariaDB的审计插件。
224 0
|
5月前
|
弹性计算 监控 网络协议
使用ECS通过Syslog协议投递日志到SIEM
Syslog是一个常见的日志通道,几乎所有的SIEM(例如IBM Qradar, HP Arcsight)都支持通过Syslog渠道接收日志。本文主要介绍如何通过Syslog将日志服务中的日志投递到SIEM。
139 0
使用ECS通过Syslog协议投递日志到SIEM

推荐镜像

更多