uuidmin

binlog及审计配置

实现方案

[ binlog + init-connect ],binlog可以审计到所有数据记录及表结构变更相关的记录,但,不记录连接的信息,要通过额外的手段来记录,比如show full processlist; 是可得出连接信息中的process id,与binlog中的thread id进行关联分析,得到连接的信息{用户名、登录时间、源ip},为了永久记录process id,采用init-connect 方式记录到数据库表中。

1、binlog(非正式环境关闭)

1.1 查看服务器binlog状态

登入root账号后通过以下命令查看

show variables like '%log_bin%';

查看到binlog日志为ON开启状态;(默认为开启状态)

 

 

1.2关闭binlog

vim /etc/mysql/mysql.conf.d/mysqld.cnf

在文件最后添加 disable-log-bin

重启mysql 服务

systemctl restart mysql

2、配置 init-connect 

2.1. 创建init-connect用于记录的库和表

mysql> create database mysql_access_log;
mysql> create table mysql_access_log.access_log ( conn_id int(11) default null, `time` timestamp, `localname` varchar(30), `matchname` varchar(30));

2.2. 授权用户于该库的表mysql_access_log.accesslog有insert权限

如用户user_web

mysql> CREATE USER 'user_web'@'%' IDENTIFIED BY 'Azalea888888#';

mysql> grant all privileges on mysql_access_log.access_log to 'user_web'@'%';

2.3. 配置用户登录日志插入表,/etc/mysql/mysql.conf.d/mysqld.cnf 中 [mysqld] 下添加,并重启mysql生效

vim /etc/mysql/mysql.conf.d/mysqld.cnf

init-connect='insert into mysql_access_log.access_log values(connection_id(),now(),user(),current_user());'

2.4. 特别注意:

①init-connect只记录非super权限用户,所以需要好好管理用户,按情况回收super权限;

②非super权限用户登录都受init-connect影响,未授权对mysql_access_log.access_log有insert权限的用户即无法登录成功!

③当重启mysql后connection_id会存在不按历史续增长而重复出现,所以查记录时注意多个重复的id记录。

posted on 2022-12-15 18:00  uuidmin  阅读(76)  评论(0编辑  收藏  举报

导航