暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

xtrabackup 备份报错"too many open files" 突然消失

原创 进击的CJR 2024-07-07
311

问题描述

xtrabackup备份时候,一个有趣的问题,同样的环境同样的库,采用xtrabackup备份一直失败,而因为某次原因数据库重启过后,备份成功了。

模拟故障场景

准备环境

mysql 8.0.25
percona-xtrabackup-8.0.25
sysbench-1.0.20

使用sysbench 创建5000张表

sysbench  oltp_read_write --mysql-host=*.*.*.* --mysql-port=*** --mysql-user=** --mysql-password=** --mysql-db=test123 --tables=5000 --table-size=100  --threads=5 prepare

参数预置

/etc/security/limits.conf参数值

* soft nofile 100001
* hard nofile 100002
root soft nofile 100001
root hard nofile 100002
mysql soft nofile 1000
mysql hard nofile 1000

ulimit -n 
1000

my.cnf参数设置


table_open_cache=3000
open_files_limit=65535
innodb_open_files=65535

备份失败的情景

(1)使用mysql用户重启数据库

/bin/sh /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my8.cnf --user=mysql &

(2)使用xtrabackup备份

xtrabackup --defaults-file=/etc/my8.cnf --user=** --password=** --host=*****  --port=***  --backup --parallel=10 --target-dir=/data/backup/full1 

报错


xtrabackup: open files limit requested 65535, set to 1000


Operating system error number 24 in a file operation.
Error number 24 means 'Too many open files'
Refer to your operating system documentation for operating system error code information.
File ./test123/sbtest2588.ibd: 'open' returned OS error 124. Cannot continue operation
240705 15:02:32 [09]        ...done
Cannot continue operation.
xtrabackup: Can't create/write to file '/data/backup/full1/test123/sbtest3789.ibd' (OS errno 24 - Too many open files)[mysql@VM-20-8

报错显示
open files limit值不对,查看配置文件open_files_limit=65535,mysql操作系统用户的限制为1000

(3)登录数据库查看
open_files_limit | 1000

备份成功的情景

(1)使用root用户重启数据库

/bin/sh /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my8.cnf &

(2)使用xtrabackup备份


xtrabackup: open files limit requested 65535, set to 100001


xtrabackup: Transaction log of lsn (494232950) to (494232960) was copied.
240705 15:19:31 completed OK!

(3)登录数据库查看

| open_files_limit           | 65535 |

问题总结

可以看到不同的用户启动数据库,导致open_files_limit的生效值不同。
open_files_limit : 如果是root账号启动 以my.cnf文件里面的值为准, 如果是mysql启动, 就可能是 ulimit -n 看到的那个值。

在my.cnf中配置open_files_limit=65535 ,当我们以mysql用户启动(mysql用户文件句柄数限制为1000),数据库中open_files_limit的生效值采用的事1000,疑问备份需要打开的表超过1000,因此备份失败;
而当我们以root用户启动数据,open_files_limit的生效值采用了my.cnf的值,该参数值大于备份需要打开的文件数,因此备份成功。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论