作者:Chengda Zhang(张成达)
Oracle ACE Associate: Database
在平台的运行环境中,会根据等保测评要求,进行登录失败采取必要的措施,如:登录失败5次锁定帐户等,配置登录连接超时处理功能。本文将介绍如何安装连接控制插件以及设置相应的策略。
一、查询插件是否安装
show plugins;
二、安装插件
在mysql5.7后mysql/data/lib/plugin目录默认增加了connection_control.so插件,安装即可:
install plugin connection_control soname "connection_control.so";
#登录错误次数限制插件
install plugin connection_control_failed_login_attempts soname 'connection_control.so';
#为了把错误次数记录到表中
三、设置插件
查询一下安装状态
show variables like "%connection_control%";
解释:
connection_control_failed_connections_threshold :连续失败最大次数3次,0表示不开启
connection_control_max_connection_delay :超过最大失败次数之后阻塞登录最大时间(毫秒)
connection_control_min_connection_delay :超过最大失败次数之后阻塞登录最小时间(毫秒)
修改配置命令:
set global connection_control_max_connection_delay=2147483647;
set global connection_control_failed_connections_threshold=5;
set global connection_control_min_connection_delay=600000;
四、修改my.cnf配置文件
[mysqld]
plugin-load-add = connection_control.so
connection-control = FORCE
connection-control-failed-login-attempts = FORCE
connection_control_min_connection_delay = 600000
connection_control_max_connection_delay = 2147483647
connection_control_failed_connections_threshold = 5
五、查询插件状态
show status like "%connection_control%";
Connection_control_delay_generated:表示连接控制的使用次数(可用户判断是否存在暴力登录尝试)
重新配置connection_control_failed_connections_threshold变量,该表记录会被删除(重置)
六、查询各账号登录失败次数
use information_schema;
select * from connection_control_failed_login_attempts;
如果使用不存在的用户登录,则该表记录用户名为空,但会记录具体登录的IP。