时间:2021-07-01 10:21:17 帮助过:7人阅读
lvextend -l +100%FREE /dev/cl_gr61/root xfs_growfs /dev/cl_gr61/root
重新格式化home分区为xfs格式,挂载home分区,还原数据。
mkfs.xfs -f /dev/cl_gr61/home xfsrestore /home.xfsdump /home mount /home
完成后,分区信息如下
df -h
Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl_gr61-root 108G 9.1G 99G 9% / devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 8.3M 3.9G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda2 1014M 174M 841M 18% /boot /dev/sda1 200M 9.5M 191M 5% /boot/efi /dev/mapper/cl_gr61-home 10G 1.7G 8.4G 17% /home tmpfs 782M 0 782M 0% /run/user/0
方案二,虚拟机扩展硬盘或更换大硬盘DD克隆后,扩展lvm分区,危险,仅做实验。
使用parted工具对磁盘已扩大的sda磁盘进行分区处理
parted /dev/sda
更改显示单位为磁盘扇区,查询磁盘状态,因磁盘大小已变更,如有提示修复分区,请按F回车修复
(parted) unit s (parted) print free Error: The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the backup to the end (and removing the old backup)? Fix/Ignore/Cancel? Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 41943040 blocks) or continue with the current setting? Fix/Ignore? Number Start End Size File system Name Flags 34s 2047s 2014s Free Space 1 2048s 411647s 409600s fat16 EFI System Partition boot 2 411648s 2508799s 2097152s xfs 3 2508800s 266336255s 263827456s lvm 266336256s 629145566s 362809311s Free Space
删除lvm分区3,将剩余空间一起重新分区,此操作可能会损失所有数据,注意4K对齐。
(parted) rm 3 (parted) mkpart Partition name? [] #分区名,无就直接回车。 File system type? [ext2] #文件分区类型,请勿填写,不然有可能格式化丢数据,直接回车。 Start? 508800s #原lvm分区开始扇区。 End? 629143551s #磁盘结束扇区。 Flags? lvm #磁盘标识,填写lvm回车。——如果没有,请使用set命令更改flags(set NUMBER FLAG STATE) Error: Partition(s) 3 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes. Ignore/Cancel? I # /dev/sda 分区 3 变更已写入,但未能告知内核,分区可能在使用。因此,旧的分区将保留在 使用。在做其它变更前请重新启动。——这里选择忽略,不要重启系统
查看分区信息并退出parted。
(parted)print free Number Start End Size File system Name Flags 34s 2047s 2014s Free Space 1 2048s 411647s 409600s fat16 EFI System Partition boot 2 411648s 2508799s 2097152s xfs 3 2508800s 629143551s 626634752s lvm 629143552s 629145566s 2015s Free Space (parted)quit
允许lvm分区sda3进行PE物理块分配,并加10G到/home,剩余空间分配到/root,用xfs_growfs进行xfs文件分区扩展。可额外使用pvs,vgs,lvs查看lvm相关信息。
pvchange -x y /dev/sda3 #允许分配指定物理卷上的PE lvextend -L +10G /dev/cl_gr61/home #增加10G空间到/home分区 xfs_growfs /dev/cl_gr61/home #扩展/home分区表到新增空间 lvextend -l +100%free /dev/cl_gr61/root #增加剩余的所有空间到/root分区 xfs_growfs /dev/cl_gr61/root #扩展/root分区表到新增空间
完成后,分区信息如下
df -h
Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl_gr61-root 271G 9.1G 262G 4% / devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 8.3M 3.9G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda2 1014M 174M 841M 18% /boot /dev/sda1 200M 9.5M 191M 5% /boot/efi /dev/mapper/cl_gr61-home 20G 1.7G 19G 9% /home tmpfs 782M 0 782M 0% /run/user/0
方案三,增加硬盘作为mysql数据专用盘,将/var/lib/mysql迁移到新硬盘/mysqldata/
创建 LVM 的一般过程:
对磁盘分区(prated) --> 创建物理卷(pvcreate) --> 创建卷组(vgcreate) --> 创建逻辑卷(lvcreate) --> 创建文件系统(mkfs) --> 挂载文件系统(mount) --> 添加到文件系统列表(/etc/fstab)
使用prated工具对新增硬盘进行处理
prarted (parted) print all #显示所有硬盘 Model: Msft Virtual Disk (scsi) Disk /dev/sdb: 2199GB #新增的硬盘 Sector size (logical/physical): 512B/4096B Partition Table: Disk Flags: (parted) select /dev/sdb #选择要操作的硬盘,一定要再三确认 (parted) mklabel gpt #创建分区表格式为gpt Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? yes (parted) mkpart Partition name? []? File system type? [ext2]? Start? 0% End? 100%
查看硬盘信息
(parted) print Model: Msft Virtual Disk (scsi) Disk /dev/sdb: 2199GB Sector size (logical/physical): 512B/4096B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 2199GB 2199GB
检查4k对齐
(parted) unit s #改变单位为扇区。 (parted) print #查看4K是否对齐。2048s(开始扇区)*512B(扇区逻辑大小)/4096B(4KB),能整除一般4K就对齐。 Model: Msft Virtual Disk (scsi) Disk /dev/sdb: 4294967296s Sector size (logical/physical): 512B/4096B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 2048s 4294965247s 4294963200s
设置分区标识为lvm
(parted) unit compact #改变现实单位为混合(默认的选项) (parted) set 1 #设置分区1名字为lvm Flag to Invert? lvm New state? [on]/off?
创建LVM物理卷
pvcreate /dev/sdb1 #创建LVM物理卷 Physical volume "/dev/sdb1" successfully created. pvs PV VG Fmt Attr PSize PFree /dev/sdb1 lvm2 --- 2.00t 2.00t
创建LVM卷组
vgcreate cl_gr61_mysql /dev/sdb1 #创建LVM卷组 Volume group "mysql" successfully created vgs VG #PV #LV #SN Attr VSize VFree mysql 1 0 0 wz--n- 2.00t 2.00t
创建LVM分区
lvcreate cl_gr61_mysql -l 100%free -n mysql #在lvm卷组cl_gr61_mysql上创建mysql分区 Logical volume "mysql" created. lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mysql cl_gr61_mysql -wi-a----- 2.00t
用xfs格式,格式化分区
mkfs.xfs /dev/cl_gr61_mysql/mysql meta-data=/dev/cl_gr61_mysql/mysql isize=512 agcount=4, agsize=134217472 blks = sectsz=4096 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=536869888, imaxpct=5 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=262143, version=2 = sectsz=4096 sunit=1 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
创建mysql存储目录
mkdir /mysql mount /dev/mapper/cl_gr61_mysql-mysql /mysql df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl_gr61_mysql-mysql 2.0T 33M 2.0T 1% /mysql vi /etc/fstab /dev/mapper/cl_gr61_mysql-mysql /mysql xfs defaults 0 0
停止mysql服务,复制数据库数据到新目录
systemctl stop mysqld.service cp -a -v /var/lib/mysql /mysql
变更mysql配置,修改存储目录地址
vi /etc/my.cnf datadir = /mysql/mysql/ socket = /mysql/mysql/mysql.sock
启动mysql服务,检查数据是否正常。
systemctl start mysqld.service
本文出自 “专注打孔100年” 博客,请务必保留此出处http://titandeng.blog.51cto.com/823817/1933384
Centos7.3,mysql5.7环境,数据存储空间加大调整方案。
标签:mysql