关于NFS客户端挂载与mount的几点探讨

最近在学习网络文件系统(NFS),发现mount这个学问很多,在这里总结一下。

NFS客户端开机自动挂载的方法:

第一种方法:将挂载命令写入/etc/rc.local

缺点:偶尔开机挂载不上,工作中除了开机自动配置,还要对是否挂载做监控。

第二种方法:将挂载命令放在/etc/fatab里

单这种配置方法有个误区:fstab会先于网络被Linux系统加载。网络没启动时执行fstab会导致连接不上NFS服务器端,无法实现开机挂载。而且,即使是本地文件,也要注意,fstab最后两列要设置为 0 0.否则有可能会导致无法启动服务器的问题。因此NFS网络文件系统最好不要放在fstab里实现开机挂载。

PS:关于ubuntu系统每次开机都会有1分30秒的等待时间

fstab这个文件大家最好不要乱动,修改前先做备份,我之前就由于不小心删除了一个条目,导致无法开机。由于我电脑装了4个系统,三个linux系统(Ubuntu、Kali、Deeoin),都公用一个swap分区,每次重装或者更改系统时Linux会自动格式化swap分区,导致了这与ubuntu中/etc/fatab中记录的uuid不一样,然后就开机漫长的等待1分30秒才开机,出现:A start job is running for dev-disk-by/x2uuid-7ea*.device(**/1min30s )这样的提示,导致开机也未挂载上swap.解决方法如下:

[code lang=”bash”]
jian@N4010:~$ sudo blkid
[sudo] jian 的密码:
/dev/sda1: UUID="54DE803EDE801A7E" TYPE="ntfs" PARTUUID="ad078914-01"
/dev/sda5: UUID="46957b90-fc30-47ca-b256-049e267e7cf5" TYPE="ext4" PARTUUID="ad078914-05"
/dev/sdb1: UUID="2661b44d-6408-4b1c-b92c-2ab42deca270" TYPE="ext4" PARTUUID="000cf9af-01"
/dev/sdb5: UUID="120e4dc8-74a4-4573-bff0-1685412ca365" TYPE="swap" PARTUUID="000cf9af-05"
/dev/sdb6: LABEL="M-hM-=M-/M-dM-;M-6" UUID="0000678400004823" TYPE="ntfs" PARTUUID="000cf9af-06"
/dev/sdb7: LABEL="M-fM-^VM-^GM-fM-!M-#" UUID="0000678400004823" TYPE="ntfs" PARTUUID="000cf9af-07"
/dev/sdb8: LABEL="M-eM-(M-1M-dM-9M-^P" UUID="0000678400004823" TYPE="ntfs" PARTUUID="000cf9af-08"
/dev/sdb9: LABEL="M-eM-^JM-^^M-eM-^EM-," UUID="0000678400004823" TYPE="ntfs" PARTUUID="000cf9af-09"
/dev/sdb10: UUID="43409185-fa0a-4e17-96f1-f666685aa81e" TYPE="ext4" PARTUUID="000cf9af-0a"
[/code]

使用sudo fdisk -l产看所有分区信息,找到swap对应的swap分区如下:

/dev/sdb5 156258304 167772159 11513856 5.5G 82 Linux 交换 / Solaris

将sbd5对应的UUID=”120e4dc8-74a4-4573-bff0-1685412ca365″,重新写入到fstab:

[code language=”bash”]

jian@N4010:~$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use ‘blkid’ to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type><options> <dump> <pass>
# / was on /dev/sda5 during installation
UUID=46957b90-fc30-47ca-b256-049e267e7cf5 / ext4 errors=remount-ro 0 1
# swap was on /dev/sdb5 during installation
UUID=120e4dc8-74a4-4573-bff0-1685412ca365 none swap sw 0 0

[/code]

从启发现再没有恼人的1分30秒等待了

二、关于fstab中的格式与参数说明,MAN给出的信息如下:

The first field (fs_spec).—->This field describes the block special device or remote filesystem to be mounted.

The second field (fs_file).—->This field describes the mount point for the filesystem. For swap partitions, this field
should be specified as `none’. If the name of the mount point contains spaces these can be
escaped as `\040′.

The third field (fs_vfstype).—->This field describes the type of the filesystem.

The fourth field (fs_mntops).T—->his field describes the mount options associated with the filesystem.

The fifth field (fs_freq).—->:This field is used by dump(8) to determine which filesystems need to be dumped. Defaults to
zero (don’t dump) if not present.(意思是是否要转储,应该是读写缓存的意思,实时读写就是0,防止因异常断电导致的数据丢失。)

The sixth field (fs_passno).—->This field is used by fsck(8) to determine the order in which filesystem checks are done at
boot time. The root filesystem should be specified with a fs_passno of 1. Other filesystems
should have a fs_passno of 2. Filesystems within a drive will be checked sequentially, but
filesystems on different drives will be checked at the same time to utilize parallelism
available in the hardware. Defaults to zero (don’t fsck) if not present.

(大概意思是:通过此字段来设置启动时检测文件系统的顺序应该 1 指定文件系统其他文件系统应该用  2。按顺序检查驱动器文件系统不同驱动器文件系统同时利用并行性检查硬件可用默认值零不检查)

所以不重要的文件系统可以设置为0 0,防止因为一些异常而无法开机。

三、fstab与mount的关系

通过mount -o指定挂载参数与在/etc/fstab里指定挂载参数的效果是一样的。

执行mount -a会自动执行/etc/fstab中的挂载参数。(mount  -a, –all  —-> mount all filesystems mentioned in fstab)

四、NfS客户端挂载优化(考虑安全与性能两个方面)

兼顾到安全与性能的挂载方式:

[code lang=”bash”]mount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,intr,rsize=131072,wsize=131072 10.0.100.128:/date/nfs  /mnt/share[/code]

如果是本地文件系统,使用如下命令:

[code lang=”bssh”]mount  /dev/sdb5 /mnt -o defaults,async,noatime,data=writeback,barrier=0[/code]

本地文件系统挂载时,如果加nodirtime会报错。

五、NFS内核优化建议#NFS内核优化建议

[code lang=”bash”]

vim /etc/sysctl.conf

net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
ne.core.wmem_max = 16777216

执行sysctl -p生效 [/code]

注:如果卸载的时候提示:“umount:/mnt:device is busy”,注意需要退出挂载的目录在进行卸载,如果是NFS server宕机了,则需要强制卸载,可执行umount -lf /mnt
大型网站NFS网络文件系统的替代软件为分布式文件系统Moosefs(mfs)、GlusterFS、FastDFS.

 

“关于NFS客户端挂载与mount的几点探讨”的一个回复

  1. It is the best time to make a few plans for the long run and it’s time to be
    happy. I’ve read this publish and if I may just I wish to counsel you some interesting issues or suggestions.

    Maybe you can write next articles regarding this article.

    I want to learn more issues approximately it! http://yahoo.org

发表评论

电子邮件地址不会被公开。 必填项已用*标注