
linux服务器通过multipath多路径连接到共享存储,那么当文件系统空间不足的时候,有几种方式可以扩展文件系统的大小:
1、pv不变,原lun存储扩大容量,扩大lv,扩大文件系统
2、新增pv,加入到vg中,扩大lv,扩大文件系统
下文是针对场景1的情况下如何 *** 作(但是个人建议采取新建pv的方式2进行):
Environment
If you have this specific scenario, you can use the following steps:
Note: if these lv's are part of a clustered vg, steps 1 and 2 need to be performed on all nodes. 注意:集群模式下步骤1和步骤2两个节点都需要执行。
1) Update block devices
Note: This step needs to be run against any sd devices mapping to that lun. When using multipath, there will be more than one. 通过multipath -ll命令查看每个聚合卷对应的路径。
2) Update multipath device
例子:
3) Resize the physical volume, which will also resize the volume group
4) Resize your logical volume (the below command takes all available space in the vg)
5) Resize your filesystem
6) Verify vg, lv and filesystem extension has worked appropriately
模拟存储端扩容testlv增加
查看客户端多路径情况
客户端更新存储
更新聚合设备
更新pv空间
更新lv空间
更新文件系统空间
Truncate 命令 通常用于将文件缩小或扩展到指定的大小。如果文件大于指定的大小,则会丢失额外的数据。如果文件较短,则会对其进行扩展,并且扩展部分的读数为零字节。
系统环境
Centos 7
安装
通常 *** 作系统会安装truncate 命令 ,该命令在coreutils安装包里面,如果没有安装可以使用下面命令安装:
[root@localhost ~]# yum provides truncateLoaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.comcoreutils-8.22-24.el7.x86_64 : A set of basic GNU tools commonly used in shell scriptsRepo : baseMatched from:Filename : /usr/bin/truncatecoreutils-8.22-24.el7.x86_64 : A set of basic GNU tools commonly used in shell scriptsRepo : @anacondaMatched from:Filename : /usr/bin/truncate
可以看到truncate由coreutils安装包提供,下面安装coreutils安装包:
[root@localhost ~]# yum -y install coreutils
truncate常用选项
下面是truncate的常用选项:
-c, --no-create -->不创建任何文件
-o, --io-blocks -->将大小视为存储块的数量,而不是字节
-r, --reference=RFILE -->参考指定的文件大小
-s, --size=SIZE -->按照指定的字节设置文件大小
使用truncate清除文件内容
这对于清除日志文件很有用。truncate过程基本上删除了文件的所有内容。它不会删除文件本身,但会将它作为零字节文件保留在磁盘上。例如,让我们使用truncate将/var/log/yum.log清除为0个字节。
[root@localhost ~]# du -sh /var/log/yum.log
12K /var/log/yum.log
[root@localhost ~]# truncate -s 0 /var/log/yum.log
再次查看这个文件,发现字节为0了。查看内容是空的了。
[root@localhost ~]# du -sh /var/log/yum.log
0 /var/log/yum.log
[root@localhost ~]# cat /var/log/yum.log
truncate命令将保留文件所有权。可以使用ll -h命令进行确认:
[root@localhost ~]# ll -h /var/log/yum.log
-rw-------. 1 root root 0 Nov 4 18:39 /var/log/yum.log
使用truncate将文件设置为指定大小
下面的示例将文件填充为10K个字节。
[root@localhost ~]# touch file.txt
[root@localhost ~]# ll -h file.txt
-rw-r--r--. 1 root root 0 Nov 4 18:43 file.txt
[root@localhost ~]# truncate -s 10k file.txt
[root@localhost ~]# ll -h file.txt
-rw-r--r--. 1 root root 10K Nov 4 18:43 file.txt
单位有 K, M, G, T, P, E, Z, Y。
使用truncate扩展文件大小
也可以将文件的大小从当前扩展到所需状态。使用-s选项,在数字前面加上+
[root@localhost ~]# cat /etc/passwd >file.txt
[root@localhost ~]# ll -h file.txt
-rw-r--r--. 1 root root 1009 Nov 4 18:47 file.txt
[root@localhost ~]# truncate -s +200k file.txt
[root@localhost ~]# ll -h file.txt
-rw-r--r--. 1 root root 201K Nov 4 18:47 file.txt
通过添加额外的200K,这会将文件大小从1K扩展到201K。
使用truncate减小文件大小
假设有一个500K的文件,并且希望将其缩小到250K。将使用-s选项,在数字前面加上-
[root@localhost ~]# touch file.txt
[root@localhost ~]# truncate -s 500k file.txt
[root@localhost ~]# ll -h
total 4.0K
-rw-------. 1 root root 1.3K Dec 29 2019 anaconda-ks.cfg
-rw-r--r--. 1 root root 500K Nov 5 08:36 file.txt
drwxr-xr-x. 5 root root 107 Nov 4 18:22 test
[root@localhost ~]# truncate -s -250k file.txt
[root@localhost ~]# ll -h
total 4.0K
-rw-------. 1 root root 1.3K Dec 29 2019 anaconda-ks.cfg
-rw-r--r--. 1 root root 250K Nov 5 08:36 file.txt
drwxr-xr-x. 5 root root 107 Nov 4 18:22 test
可以看到当前大小更改为250K。
总结
Truncate命令通常用于将文件缩小或扩展到指定的大小。如果文件大于指定的大小,则会丢失额外的数据。如果文件较短,则会对其进行扩展,并且扩展部分的读数为零字节。
(一) 备份
首先组好备份要更改的分区中的文件. 对磁盘的 *** 作也许会导致数据的丢失. 开始工作之前最好将重要的数据保存到别的分区.
(二) 获取相关信息
1, 运行 $ df , 查看文件系统信息. 记下想要调整的分区对应的挂载点和设备文件.
这一步是为了查看/usr/local对应/dev/中的哪个设备文件. 本文以/dev/hda7为例.
2, 运行 # sudo fdisk /dev/sda . 进入fdisk , 按下p, 查看磁盘分区信息. 记下/dev/sda8的起始柱面号, 终止柱面号. 设他们分别为start, end. 并记下一个"Unit"包含多少字节.
注意, 文件系统大小和磁盘分区大小是不能等同的: 起码他们的计量单位不同. 在文件系统中, 一般用KB, MB, GB为单位. 但在fdisk中, 是以磁盘的"unit"值(即一个柱面中包含的字节数)来计算的. 我们运行 # fdisk /dev/sda后, fdisk显示如下信息:
Disk /dev/sda: 163.9 GB, 163928604672 bytes255 heads, 63 sectors/track, 19929 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
(三)计算终止柱面号
e.g: 原先/usr/local的大小为5000 MB, 起始柱面号为2550, 终止柱面号为3157. 那么现在要将它的大小改为1000MB, 应该这样计算终止柱面号( [3.2] = 4 ):
终止柱面号 = 2550 + [(1000 * 1024 * 1024 ) / 8225280] = 2678
使用fdisk删除原来的分区(以前分区的数据不会丢失!). 然后新建一个分区, 新分区于旧分区唯一的区别就在于分区大小不一样, 这表现在他们终止柱面号不同.
增加分区大小: 终止柱面号设置为空闲空间的最后一个柱面号.减小分区大小: 终止柱面号由计算得出.
开始调整
在开始调整之前, 最好拿一张纸记下要调整的分区的下列信息:
调整前大小, 调整后大小. 它挂载在哪个目录, 对应于/dev/中的哪个设备. 起始, 终止柱面
e.g: 调整前: 5G, 调整后: 1G, 挂载点: /usr/local, 对应于/dev/hda7. 起始,终止柱面分别为2550,3157
1,卸载分区
最好在runlevel=1的情况下卸载.
#umount/dev/2,检查文件系统的一致性
#fsck-n/dev/3,如够是ext3系统,还要去除日志
#tune2fs-O^has_journal/dev/注意:取出日志后的ext3系统是无法挂载的,使用
#tune2fs-j/dev/重建日志.4,调整文件系统大小
#resize_reiserfs-s1000M/dev/hda7调整完文件系统的大小以后,再使用以下命令以文件系统进行全面的检查:
#reiserfsck--check--fix-fixable/dev/hda75,进入fdisk,调整分区大小
#fdisk/dev/hda由于内核仍然使用旧的分区表,重启之后再进行后面的步骤.
通过以上步骤,已经完成了硬盘分区大小调整的 *** 作,接下来回到重新调整文件系统大小的问题上来。由于硬盘分区是按照柱面来计划的,要在resize_reiserfs步骤上就一步到位调整文件系统大小与硬盘分区大小正好相等是比较困难的事情。所以一般是调硬盘分区比文件系统要大一点点,然后再通过以下命令进行同步(当然如果你不在意硬盘分区里面存在部分空间的话也可以忽略以下步骤):
#umount/home/#resize_reiserfs/dev/hda6
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)