一、服务器现有2块300G硬盘做RAID1容量为300G,其中200G挂载到/home下
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 278.9G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 277.9G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 15.7G 0 lvm [SWAP] └─centos-home 253:2 0 212.2G 0 lvm /home sr0 11:0 1 1024M 0 rom [root@localhost ~]#
/home目录下存放mysql数据文件,需要扩容。方案如下:
1、增加3块2T硬盘做RAID5,容量为4T,大于2T的硬盘做分区需要使用GPT分区,而不能使用普通的MBR分区
2、在根目录下创建一个临时目录:/datatemp,将4T硬盘挂载到、/datatemp下
3、将/home下的所有数据复制到/datatemp下
4、停止mysqld服务,并将/home挂载点卸载
5、将/datatemp挂载点卸载
6、将4T硬盘挂载到/home下,并将mysql数据目录授权给mysql用户
7、重启mysqld服务
8、将原来的212G硬盘挂载到其他挂载点使用
二、插入新硬盘,并作RAID,进入系统
查看硬盘
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 278.9G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 277.9G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 15.7G 0 lvm [SWAP] └─centos-home 253:2 0 212.2G 0 lvm /home sdb 8:16 0 3.7T 0 disk sr0 11:0 1 1024M 0 rom [root@localhost ~]#
可以看到/dev/sdb为新增加的3.7T硬盘
三、使用parted进行分区
[root@localhost ~]# parted /dev/sdb GNU Parted 3.1 使用 /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel gpt (parted) unit TB (parted) mkpart primary 0 3 (parted) print Model: DELL PERC H710 (scsi) Disk /dev/sdb: 4.00TB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name 标志 1 0.00TB 3.00TB 3.00TB primary
parted /dev/sdb 对/dev/sdb硬盘进行gpt分区
mklabel gpt 创建gpt分区
unit TB 设置分区大小单位为TB
mkpart primary 0 3 创建主分区,大小从0开始到3,因为单位是TB,所以就是3TB
print 打印当前GPT分区信息
如果发现分区不合适,可以删除分区
rm 1 即可删除number=1分区
(parted) rm 1 (parted) print Model: DELL PERC H710 (scsi) Disk /dev/sdb: 4.00TB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name 标志 (parted)
这里看到刚才创建的分区没有了,我们重新分区分区大小为4TB
[root@localhost ~]# parted /dev/sdb GNU Parted 3.1 使用 /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel gpt 警告: 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? y (parted) unit TB (parted) mkpart primary 0 4 (parted) print Model: DELL PERC H710 (scsi) Disk /dev/sdb: 4.00TB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name 标志 1 0.00TB 4.00TB 4.00TB primary (parted)
quit 退出
四、fdisk查看分区
[root@localhost ~]# fdisk -l 磁盘 /dev/sda:299.4 GB, 299439751168 字节,584843264 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x000452d7 设备 Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 584843263 291372032 8e Linux LVM WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. 磁盘 /dev/sdb:3999.7 GB, 3999688294400 字节,7811891200 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:gpt Disk identifier: 6C3DD9BC-3600-4890-8551-E0E078408A24 # Start End Size Type Name 1 2048 7811889151 3.7T Microsoft basic primary 磁盘 /dev/mapper/centos-root:53.7 GB, 53687091200 字节,104857600 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘 /dev/mapper/centos-swap:16.8 GB, 16844324864 字节,32899072 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘 /dev/mapper/centos-home:227.8 GB, 227826204672 字节,444973056 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节
可以看到/dev/sdb硬盘的磁盘标签类型为:gpt
五、创建文件系统
[root@localhost ~]# mkfs -t ext3 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) 文件系统标签= OS type: Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 244121600 inodes, 976485888 blocks 48824294 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=4294967296 29800 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848, 512000000, 550731776, 644972544 Allocating group tables: 完成 正在写入inode表: 11378/29800
这个过程会比较慢,大概用了20分钟
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848, 512000000, 550731776, 644972544 Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成
六、将3.7T硬盘挂载到datatemp目录
[root@localhost /]# mkdir datatemp [root@localhost /]# mount /dev/sdb1 /datatemp
使用df -h查看
[root@localhost /]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 50G 2.3G 45G 5% / devtmpfs 16G 0 16G 0% /dev tmpfs 16G 0 16G 0% /dev/shm tmpfs 16G 9.2M 16G 1% /run tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/sda1 976M 102M 824M 11% /boot /dev/mapper/centos-home 209G 194M 198G 1% /home tmpfs 3.2G 0 3.2G 0% /run/user/0 /dev/sdb1 3.6T 69M 3.4T 1% /datatemp
硬盘已经挂载到datatemp上了,
七、将/home目录数据复制到datatemp目录下
[root@localhost /]# cd /home/ [root@localhost home]# cp -R *.* /datatemp/
八、将之前的硬盘挂载点/home卸载
[root@localhost /]# umount /home umount: /home:目标忙。 (有些情况下通过 lsof(8) 或 fuser(1) 可以 找到有关使用该设备的进程的有用信息)
报错:目标忙,是因为有进程在使用/home目录下的文件,通过lsof /home,来查看哪些进程在使用
[root@localhost /]# lsof /home/ COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 6625 mysql cwd DIR 253,2 4096 8568835 /home/mysql-5.7.26/data mysqld 6625 mysql 1w REG 253,2 12582 8568836 /home/mysql-5.7.26/log/mysqld.log mysqld 6625 mysql 2w REG 253,2 12582 8568836 /home/mysql-5.7.26/log/mysqld.log mysqld 6625 mysql 3uW REG 253,2 50331648 8568838 /home/mysql-5.7.26/data/ib_logfile0 mysqld 6625 mysql 9uW REG 253,2 50331648 8568839 /home/mysql-5.7.26/data/ib_logfile1 mysqld 6625 mysql 10uW REG 253,2 12582912 8568837 /home/mysql-5.7.26/data/ibdata1 mysqld 6625 mysql 11uW REG 253,2 12582912 8569114 /home/mysql-5.7.26/data/ibtmp1 mysqld 6625 mysql 13uW REG 253,2 98304 8568856 /home/mysql-5.7.26/data/mysql/servers.ibd mysqld 6625 mysql 14uW REG 253,2 9437184 8568864 /home/mysql-5.7.26/data/mysql/help_topic.ibd mysqld 6625 mysql 15uW REG 253,2 98304 8568854 /home/mysql-5.7.26/data/mysql/plugin.ibd mysqld 6625 mysql 16uW REG 253,2 114688 8568866 /home/mysql-5.7.26/data/mysql/help_category.ibd mysqld 6625 mysql 17uW REG 253,2 131072 8568868 /home/mysql-5.7.26/data/mysql/help_relation.ibd mysqld 6625 mysql 18uW REG 253,2 98304 8568878 /home/mysql-5.7.26/data/mysql/time_zone_transition_type.ibd mysqld 6625 mysql 19uW REG 253,2 245760 8568870 /home/mysql-5.7.26/data/mysql/help_keyword.ibd mysqld 6625 mysql 20uW REG 253,2 98304 8568872 /home/mysql-5.7.26/data/mysql/time_zone_name.ibd mysqld 6625 mysql 21uW REG 253,2 98304 8568874 /home/mysql-5.7.26/data/mysql/time_zone.ibd mysqld 6625 mysql 22uW REG 253,2 98304 8568876 /home/mysql-5.7.26/data/mysql/time_zone_transition.ibd mysqld 6625 mysql 23uW REG 253,2 98304 8568880 /home/mysql-5.7.26/data/mysql/time_zone_leap_second.ibd mysqld 6625 mysql 24uW REG 253,2 98304 8568900 /home/mysql-5.7.26/data/mysql/innodb_table_stats.ibd mysqld 6625 mysql 25uW REG 253,2 98304 8568902 /home/mysql-5.7.26/data/mysql/innodb_index_stats.ibd mysqld 6625 mysql 26uW REG 253,2 98304 8568904 /home/mysql-5.7.26/data/mysql/slave_relay_log_info.ibd mysqld 6625 mysql 27uW REG 253,2 98304 8568910 /home/mysql-5.7.26/data/mysql/gtid_executed.ibd mysqld 6625 mysql 28uW REG 253,2 98304 8568906 /home/mysql-5.7.26/data/mysql/slave_master_info.ibd mysqld 6625 mysql 29uW REG 253,2 98304 8568908 /home/mysql-5.7.26/data/mysql/slave_worker_info.ibd mysqld 6625 mysql 30uW REG 253,2 98304 8568912 /home/mysql-5.7.26/data/mysql/server_cost.ibd mysqld 6625 mysql 31uW REG 253,2 98304 8568914 /home/mysql-5.7.26/data/mysql/engine_cost.ibd mysqld 6625 mysql 32uW REG 253,2 98304 8569126 /home/mysql-5.7.26/data/pytest/test_login_data.ibd mysqld 6625 mysql 34uW REG 253,2 98304 8569130 /home/mysql-5.7.26/data/hl_hongxb/tbl_cash_notify_flow.ibd mysqld 6625 mysql 37u REG 253,2 4096 8568848 /home/mysql-5.7.26/data/mysql/user.MYI mysqld 6625 mysql 38u REG 253,2 384 8568849 /home/mysql-5.7.26/data/mysql/user.MYD mysqld 6625 mysql 39u REG 253,2 5120 8568845 /home/mysql-5.7.26/data/mysql/db.MYI mysqld 6625 mysql 40u REG 253,2 976 8568846 /home/mysql-5.7.26/data/mysql/db.MYD mysqld 6625 mysql 41u REG 253,2 9216 8569005 /home/mysql-5.7.26/data/mysql/proxies_priv.MYI mysqld 6625 mysql 42u REG 253,2 837 8569006 /home/mysql-5.7.26/data/mysql/proxies_priv.MYD mysqld 6625 mysql 43u REG 253,2 9216 8568858 /home/mysql-5.7.26/data/mysql/tables_priv.MYI mysqld 6625 mysql 44u REG 253,2 1894 8568859 /home/mysql-5.7.26/data/mysql/tables_priv.MYD mysqld 6625 mysql 45u REG 253,2 4096 8568861 /home/mysql-5.7.26/data/mysql/columns_priv.MYI mysqld 6625 mysql 46u REG 253,2 0 8568862 /home/mysql-5.7.26/data/mysql/columns_priv.MYD mysqld 6625 mysql 47u REG 253,2 4096 8568885 /home/mysql-5.7.26/data/mysql/procs_priv.MYI mysqld 6625 mysql 48u REG 253,2 0 8568886 /home/mysql-5.7.26/data/mysql/procs_priv.MYD mysqld 6625 mysql 49u REG 253,2 2048 8568894 /home/mysql-5.7.26/data/mysql/event.MYI mysqld 6625 mysql 50u REG 253,2 0 8568895 /home/mysql-5.7.26/data/mysql/event.MYD
可以看到都是mysql服务在使用,所以我们需要停掉mysqld服务
[root@localhost /]# systemctl stop mysqld
再次卸载/home
[root@localhost /]# umount /home/ [root@localhost /]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 278.9G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 277.9G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 15.7G 0 lvm [SWAP] └─centos-home 253:2 0 212.2G 0 lvm sdb 8:16 0 3.7T 0 disk └─sdb1 8:17 0 3.7T 0 part /datatemp sr0 11:0 1 1024M 0 rom
可以看到212GB的lvm已经没有挂载到/home了,
九、卸载/datatemp挂载点
[root@localhost /]# umount /datatemp/ [root@localhost /]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 278.9G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 277.9G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 15.7G 0 lvm [SWAP] └─centos-home 253:2 0 212.2G 0 lvm sdb 8:16 0 3.7T 0 disk └─sdb1 8:17 0 3.7T 0 part sr0 11:0 1 1024M 0 rom
十、将3.6T硬盘挂载到/home
sr0 11:0 1 1024M 0 rom [root@localhost /]# mount /dev/sdb1 /home [root@localhost /]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 50G 2.3G 45G 5% / devtmpfs 16G 0 16G 0% /dev tmpfs 16G 0 16G 0% /dev/shm tmpfs 16G 9.2M 16G 1% /run tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/sda1 976M 102M 824M 11% /boot tmpfs 3.2G 0 3.2G 0% /run/user/0 /dev/sdb1 3.6T 202M 3.4T 1% /home
可以看到/home目录大小已经变成3.4TB了
十一、将mysql数据文件目录授权给mysql用户,并启动mysqld服务
[root@localhost home]# chown -R mysql:mysql /home/mysql-5.7.26/
[root@localhost /]# systemctl start mysqld
进入mysql查看数据
[root@localhost /]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.26 MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
mysql> use hl_hongxb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select count(*) from tbl_cash_notify_flow; +----------+ | count(*) | +----------+ | 66 | +----------+ 1 row in set (0.00 sec) mysql>
数据未丢失。
十二、永久挂载
[root@localhost /]# vim /etc/fstab
在文件末尾增加
/dev/sdb2 /home ext3 defaults 1 1
并注释掉之前的/home挂载
# # /etc/fstab # Created by anaconda on Tue Jul 27 10:24:56 2021 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/centos-root / ext3 defaults 1 1 UUID=0390c8b2-2038-4f3c-b2a5-09915a66e15a /boot ext3 defaults 1 2 #/dev/mapper/centos-home /home ext3 defaults 1 2 /dev/mapper/centos-swap swap swap defaults 0 0 /dev/sdb1 /home ext3 defaults 1 1
执行:mount -a
[root@localhost /]# mount -a [root@localhost /]#