linux trim raid,CentOS7下组建软Raid磁盘阵列并开启Trim|延长SSD寿命

给自己24核24G内存的独服买了个120G的SSD作OS盘,然后两个1.5T的SSD组raid1作数据库盘,加上原有的3个2THDD组raid5作仓库盘。不多说了直接上干货:

先fdisk -l看看磁盘分区情况,可以看到总共有6个盘,分别是sd[a~f]:

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes, 3907029168 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sda: 120.0 GB, 120034123776 bytes, 234441648 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x00007ae4

Device Boot Start End Blocks Id System

/dev/sda1 * 2048 2099199 1048576 83 Linux

/dev/sda2 2099200 234440703 116170752 8e Linux LVM

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes, 3907029168 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes, 3907029168 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sde: 1500.3 GB, 1500301910016 bytes, 2930277168 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sdf: 1500.3 GB, 1500301910016 bytes, 2930277168 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

记下每个盘对应的盘号,留着备用。

然后安装centos下的软raid阵列工具mdadm:

yum -y install mdadm

安装完后即可配置阵列:

[root@hostname ~]# mdadm -C /dev/md0 -ayes -l5 -n3 /dev/sd[b,c,d]

mdadm: Defaulting to version 1.2 metadata

mdadm: array /dev/md0 started.

[root@hostname ~]# mdadm -C /dev/md1 -ayes -l1 -n2 /dev/sd[e,f]

mdadm: Note: this array has metadata at the start and

may not be suitable as a boot device. If you plan to

store '/boot' on this device please ensure that

your boot-loader understands md/v1.x metadata, or use

--metadata=0.90

Continue creating array? y

mdadm: Defaulting to version 1.2 metadata

mdadm: array /dev/md1 started.

中间如果弹出警告不管他就好,反正是作为数据盘用而不是作为启动盘。

上述步骤操作完之后系统就自动开始奇偶校验了,然后通过以下命令查看进度:

[root@hostname ~]# cat /proc/mdstat

Personalities : [raid6] [raid5] [raid4] [raid1]

md1 : active raid1 sdf[1] sde[0]

1465006464 blocks super 1.2 [2/2] [UU]

[=>...................] resync = 7.5% (110671488/1465006464) finish=229.2min speed=98449K/sec

bitmap: 11/11 pages [44KB], 65536KB chunk

md0 : active raid5 sdd[3] sdc[1] sdb[0]

3906764800 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]

[>....................] recovery = 3.2% (63790592/1953382400) finish=571.6min speed=55093K/sec

bitmap: 0/15 pages [0KB], 65536KB chunk

等奇偶校验好了之后需要创建配置文件:

echo DEVICE /dev/sd{b,c,d} >> /etc/mdadm.conf

echo DEVICE /dev/sd{e,f} >> /etc/mdadm.conf

mdadm -Evs >> /etc/mdadm.conf

然后格式化、写入挂载信息、挂载

开启trim和定期指定trim:

fstrim --verbose --all

systemctl enable fstrim.timer

另外linux会划出来一部分磁盘空间做swap,会导致大量写入,因此需要做一些限制:

vi /etc/sysctl.conf

#写入系统文件,增加下面两行:

vm.swappiness=1

vm.vfs_cache_pressure=50

#保存并生效:

sysctl -p

#启动tmpfs服务

systemctl enable tmp.mount

另外关于磁盘格式的问题,数据库还是选用xfs吧,具体可以参考其他文章中对磁盘格式的对比

This article is under CC BY-NC-SA 4.0 license.

Please quote the original link:https://www.liujason.com/article/195.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LinuxSSD TRIM是一种用于优化固态硬盘(SSD)性能和寿命的技术。TRIM是一项操作系统级别的指令,用于通知SSD哪些数据块不再被使用,可以被擦除和重写。这有助于提高SSD的写入性能,并减少因为重写未使用数据块而引起的性能下降。 要启用SSD TRIM功能,您需要进行以下步骤: 1. 确保您的SSD支持TRIM。大多数现代SSD都支持这个功能,但一些较旧或低端的SSD可能不支持。您可以查看SSD制造商的文档或技术规格来确认它是否支持TRIM。 2. 检查您的Linux发行版是否已启用TRIM。大多数现代Linux发行版默认情况下已启用TRIM。您可以运行以下命令来检查: ``` sudo systemctl status fstrim.timer ``` 如果输出显示"active"或"enabled",则表示TRIM已启用。 3. 确保您的文件系统支持TRIM。大多数常见的文件系统,如ext4和XFS,都支持TRIM。您可以通过检查`/etc/fstab`文件中的文件系统挂载选项来确认是否启用了TRIM。 例如,对于ext4文件系统,您应该看到类似于以下内容的挂载选项: ``` UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx / ext4 discard,noatime,errors=remount-ro 0 1 ``` 请注意,`discard`选项用于启用TRIM。 4. 手动运行TRIM命令。如果TRIM没有自动运行,您可以手动运行TRIM命令来清理未使用的数据块。使用以下命令: ``` sudo fstrim -av ``` 这将触发对所有已挂载文件系统的TRIM操作。 请谨慎使用TRIM命令,因为它会触发SSD上的擦除操作,可能会导致数据丢失。确保在运行TRIM之前备份重要数据。 希望这些信息对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值