luckyyyyy / blog

William Chan's Blog
https://williamchan.me/
172 stars 28 forks source link

记录近期在ZFS上遇到的一些坑以及分享我的家用服务器方案 #67

Open luckyyyyy opened 1 year ago

luckyyyyy commented 1 year ago

需求

去年同期因为自身需求原因,准备组建一台家用服务器与NAS的结合体,考虑过大量成熟方案,例如群晖等,但无奈大部分方案都无法满足自身需求,所以决定自己搭建平台。

我对平台的总体要求如下

配置

综上所述,我选择了下面的配置,希望给大家一些启发。至于为何不上AMD EPYC,主要也不是因为价格原因,第一是我对AMD平台并不熟悉,第二是搜索了很多资料发现有许多坑以及兼容性问题,尤其是ZFS问题尤为严重。所以最终依然考虑搭建Intel Xeon平台。

整体方案为 安装ProxmoxVE负责整个平台,使用ZFS RAIDZ1作为数据盘文件系统,创建LXC容器作为SMB以及NFS的Server

关于ZFS为什么需要slog和cache设备,可以参考 https://www.servethehome.com/what-is-the-zfs-zil-slog-and-what-makes-a-good-one/

image

升级

由于最近发现我的服务器硬盘容量不足,并且刚好想把去年的翻新盘升级掉,以免出现意外故此购入了8块 ST8000NM017B 全新,从参数上来看会比我之前的盘优秀许多。 在替换ZFS Pool时其实已经做了许多功课,但没想到依然踩了坑。

主要遇到的是由于 ST400NM0035 在我创建ZFS Pool时,默认被识别的Block大小为512B,所以ashift=9,但新的 ST8000NM017B 参数上Block为4K,所以ashift=12,在使用 zpool replace时报告了一个奇怪的错误zpool disk replacement - already in replacing/spare config; wait for completion or use 'zpool detach',当时很迷惑,理论上我的磁盘已经被标记为UNAVAIL,新磁盘也没有被使用,也重新创建了GPT,理论上zpool replace命令并不需要做格式化和分区的操作,怎么会报告这个错误呢?

经过一番搜索,发现有人和我遇到的同样的问题,但这个问题只是使用ashift=9这个参数绕过去了,原发帖者也不知道是什么意思,只知道和block size有关,具体可以看这里https://forum.proxmox.com/threads/zpool-disk-replacement-already-in-replacing-spare-config-wait-for-completion-or-use-zpool-detach.96554/

抱着试试看的心态成功进行了替换,但也由此埋下了一颗雷。

第一次的zpool replace时间长达1天11个小时,数据总共有12TB左右,特别是最近5%进度时特别慢,这让我非常担心在过程中如果挂掉一块磁盘,我的数据会全部丢失。所幸一切正常,但替换成功后,ZFS报告了一个池中Block与实际硬盘配置不符的问题,可能会降低性能,经过一番搜索,终于理解了相关的含义,现在把我的参考资料发出来给大家看。

https://en.wikipedia.org/wiki/Advanced_Format ,经过这一系列折腾,以及确认我目前的池子已经无法修改block的情况下,我最终决定备份池子重建,整个过程又花费将近3天时间完成,这是一次非常惨痛的教训,期间如果运气不好,数据可能会丢失。还是因为自己对磁盘知识不够了解导致的,需要加强这方面的知识点。

同时大家升级硬盘,一定要考虑好原有的硬盘与新硬盘物理扇区是否一致的问题。

image image image
sensen1 commented 1 year ago

Zfs 的问题,[IT Mastery (7)] , Allan Jude - FreeBSD Mastery_ ZFS (2015, Tilted Windmill Press) 那本书里面 特别提醒过这个问题,直接引过来吧。

The easy way to avoid alignment problems is to make all GPT partitions begin and end on megabyte boundaries. Add the -a 1m argument to your gpart add commands.

Don’t trust that your 4K-sector devices report their sector size. Tell ZFS to insist on always using 4K sectors. A pool variable called the ashift controls sector size. An ashift of 9 tells ZFS to use 512-byte sectors. An ashift of 12 tells ZFS to use 4096-byte sectors. (Why 9 and 12? 2^9 is 512, while 2^12 is 4096.) The way you set ashift depends on your FreeBSD release. FreeBSD 10.1 and Newer Ashift Set the system’s default ashift with the sysctl vfs.zfs.min_auto_ashift, either in /etc/sysctl.conf or at the command line. sysctl vfs.zfs.min_auto_ashift=12 Use the command line during installation, but also set it permanently in /etc/sysctl.conf so you don’t forget when creating new pools.