记一次kvm虚机mysql数据库磁盘扩容操作步骤及其问题小坑

发布时间 2023-04-12 10:20:20作者: jmucai

背景:

业务量持续增加,原来规划的1T磁盘空间不足以支撑业务发展存储使用,需要对数据库磁盘进行扩容。
目前物理机有新增了2块3.5Tssd的数据盘用于数据库虚机磁盘扩容使用。需要安排时间对其进行操作扩容。

操作思路:

1、完成磁盘raid1操作,将新磁盘挂载到物理机上并添加到kvm的存储空间中,创建好对应的数据盘,将数据盘挂载到数据库虚机的服务器上

2、将数据盘挂载数据库服务器上/opt目录,增量同步/hskj目录下的数据到/opt目录

3、正式操作前关闭数据库服务,增量同步/hskj目录下的数据到/opt目录,卸载旧数据盘,挂载新数据盘到/hskj,启动mysql服务

核心是停数据库服务,使用rsync -arvtp同步数据库数据

操作步骤:

物理机上操作

0、查看对应的磁盘

MegaCli pdlist a0 |egrep 'Enclosure Device ID:|Slot|Fir|Raw' |sed 's/En/\n---------\nEn/g'

1、将112-4上的2块3.492T的磁盘做raid1(done)

MegaCli -CfgLdAdd -r1[32:10,32:11] WB Direct -a0

2、将初始化后的数据盘

parted /dev/sdc

(parted) mklabel gpt
(parted) mkpart primary xfs 4096s 100%  

mkfs.xfs /dev/sdc1

3、挂载到/hskj/images并写入开机启动中/etc/fstab

mount /dev/sdc1 /hskj/images

加入到/etc/fstab中

/dev/sdc1 /hskj/images xfs defaults 0 0

4、安装kvm tools相关的工具包

yum -y groupinstall  'Virtualization' 'Virtualization Client' 'Virtualization Platform'

5、调整centos7上ssh服务端口,设置为仅监听ipv4地址。否则会无法打开virt-manager图形窗口。

sed -i 's/#AddressFamily any/AddressFamily inet/g' /etc/ssh/sshd_config
systemctl restart sshd

6、使用xshell登录并验证KVM服务,需要能正常打开图形化的管理窗口

virt-manager

虚机上操作

使用root直接登录,bjxtb会有/hskj无法卸载的情况出现。

网络组同时提前放行办公网络访问权限,便于系统人员操作

1、格式化新挂载的数据盘,将数据盘挂载到/opt目录下

parted /dev/sdc
(parted) mklabel gpt
(parted) mkpart primary xfs 4096s 100%  
mkfs.xfs /dev/sdc1

挂载到/opt目录下

mount /dev/sdc1 /opt

2、同步/hskj目录下的所有数据文件到/opt目录

cd /hskj/;
time rsync -arvtp * /opt
rsync -arvtp .bash* /opt

rsync -arvtp .ssh /opt

隔天的时间操作

3、关闭mysql服务,在重新同步/hskj目录(需要知会相关产品组)

systemctl stop mysqld
cd /hskj/;
rsync -arvtp * /opt

Warning: Identity file /hskj/.ssh/id_rsa not accessible: No such file or directory.

4、卸载/hskj目录,将/opt的数据盘挂载到/hskj目录

umount /hskj
umount /opt
mount /dev/sdc1 /hskj
systemctl start mysqld
systemctl status mysqld



问题小坑:
The file './rcs_msg/rcs_up_20230312.ibd' already exists though the corresponding table did not exist in the InnoDB data dictionary.
 情况1:Have you moved InnoDB .ibd files around without using the SQL commands DISCARD TABLESPACE and IMPORT TABLESPACE, 
情况2:did mysqld crash in the middle of CREATE TABLE? 
You can resolve the problem by removing the file './rcs_msg/rcs_up_20230312.ibd' under the 'datadir' of MySQL.
在前一天使用rsync同步msyql目录数据后,数据库定时脚步有过删除对应的表,到时新服务器主机有对应的表信息

处理方式:

移走对应的报错表文件

You can resolve the problem by removing the file './rcs_msg/rcs_up_20230312.ibd' under the 'datadir' of MySQL.

2023-04-04T19:55:15.407698+08:00 5349 [ERROR] InnoDB: The file './rcs_msg/rcs_up_20230312.ibd' already exists though the corresponding table did not exist in the InnoDB data dictionary. Have you moved InnoDB .ibd files around without using the SQL commands DISCARD TABLESPACE and IMPORT TABLESPACE, or did mysqld crash in the middle of CREATE TABLE?