之前配置了一个web集群(其实就3个服务器),想实现数据共享和动静分离,感觉配置分布式存储比较复杂,也没必要,就打算在搭建一个NFS服务器,共享几个目录,挂载在几个web服务器上。
  搭建NFS服务过程很顺利,手动挂载也没问题,然后打算将挂载信息写进/etc/fstab配置文件,实现开机自动挂载。

#
# /etc/fstab
# Created by anaconda on Wed Oct  9 08:35:16 2019
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=100a90e3-01ac-43aa-b6da-a10a6c105282 /boot                   ext4    defaults        1 2
/dev/mapper/cl-data     /data                   xfs     defaults        0 0
/dev/mapper/swap-swap   swap                    swap    defaults        0 0
/dev/sr0                /cdrom                  iso9660 defaults        0 0
192.168.32.85:/data/nfsshare /apps/nginx/html/wordpress/wp-content/uploads nfs defaults,_netdev  0 0

  以为一切万事大吉之后,重启了机子测试下,df命令一看,发现竟然没有显示,用mount -l命令看了下,也没有挂载信息——竟然没有自动挂载。
  开始以为配置文件格式写错了,结果尝试一下mount -a发现一下就挂载成功了。
  这就很奇怪了,说明配置文件格式也没问题。
  NFS服务器也没任何报错,应该跟NFS服务器没有关系,只是出于某种原因不能自动挂载而已。
  可是本地光盘确实可以开机正常挂载的,于是我怀疑是参数写的有问题,不过仔细确认了下,之前参数就是这样的也是可以成功挂载的,抑或是CentOS8有些新特性和改动。上面确实提示After editing this file, run 'systemctl daemon-reload' to update systemd units generated from this file,我也尝试了,没有效果,不过既然其他挂载项都没问题,说明问题就在NFS这一行。
  于是去查看下系统日志,发现了问题的端倪

[root@CentOS8 ~]#tail /var/log/boot.log
See 'systemctl status "apps-nginx-html-wordpress-wp\\x2dcontent-uploads.mount"' for details.
[DEPEND] Dependency failed for Remote File Systems.
         Starting Permit User Sessions...
         Starting The nginx HTTP and reverse proxy server...
         Starting Crash recovery kernel arming...
[  OK  ] Started OpenSSH server daemon.
[  OK  ] Started Permit User Sessions.
         Starting Terminate Plymouth Boot Screen...
         Starting Hold until boot process finishes up...
[  OK  ] Started Command Scheduler.

  显示远程服务系统也就是NFS服务挂载失败,查看详细信息。

[root@CentOS8 ~]#systemctl status "apps-nginx-html-wordpress-wp\\x2dcontent-uploads.mount"
● apps-nginx-html-wordpress-wp\x2dcontent-uploads.mount - /apps/nginx/html/wordpress/wp-content/uploads
   Loaded: loaded (/etc/fstab; generated)
   Active: failed (Result: resources)
    Where: /apps/nginx/html/wordpress/wp-content/uploads
     What: 192.168.32.85:/data/nfsshare
     Docs: man:fstab(5)
           man:systemd-fstab-generator(8)

Nov 11 16:02:39 CentOS8 systemd[1]: apps-nginx-html-wordpress-wp\x2dcontent-uploads.mount: Mount path /apps/nginx/html/wordpress/wp-content/uploads is not canonical (contains a symlink).
Nov 11 16:02:39 CentOS8 systemd[1]: apps-nginx-html-wordpress-wp\x2dcontent-uploads.mount: Failed to run 'mount' task: Too many levels of symbolic links
Nov 11 16:02:39 CentOS8 systemd[1]: apps-nginx-html-wordpress-wp\x2dcontent-uploads.mount: Failed with result 'resources'.
Nov 11 16:02:39 CentOS8 systemd[1]: Failed to mount /apps/nginx/html/wordpress/wp-content/uploads.

  说挂载失败,挂载路径不符合规范is not canonical (contains a symlink).。路径写法应该没问题的,难道是因为Too many levels of symbolic links,层级太多了吗?我记得之前挂载点目录层级结构,比这还长都可以挂载成功的,难道又要归结为CentOS8的新特性了么。
  一通百度、google之后,竟然没有人和我遇到的问题一样,挂载点的最大层级数是多大也没人提到过,官方文档也没有查到。
  正当我打算将层数改小一些再尝试下的时候,突然看到一篇博客提到Too many levels of symbolic links,不过是在软链接中的报错。我突然想起来,当时我安装完系统后,规划的是讲文档和应用都装在/data目录下,可是我实际操作中比较习惯使用/apps/目录来找各种应用,于是之前编译安装nginx及php之前,我创建了一个软链接ln -s /data/apps /apps,以便/apps下的数据跟系统分区隔离开,在一个单独分区。或许这个is not canonical (contains a symlink).中的symlink说的就是指软链接。
  将配置文件修改为192.168.32.85:/data/nfsshare /data/apps/nginx/html/wordpress/wp-content/uploads nfs defaults,_netdev 0 0后,再次重启。df命令查看

[root@CentOS8 ~]#df
Filesystem                   1K-blocks    Used Available Use% Mounted on
devtmpfs                        393080       0    393080   0% /dev
tmpfs                           408620       0    408620   0% /dev/shm
tmpfs                           408620    5816    402804   2% /run
tmpfs                           408620       0    408620   0% /sys/fs/cgroup
/dev/mapper/cl-root           52399108 2700076  49699032   6% /
/dev/sr0                       6967726 6967726         0 100% /cdrom
/dev/nvme0n1p1                 8191416  163348   7592256   3% /boot
/dev/mapper/cl-data           41926656  585412  41341244   2% /data
192.168.32.85:/data/nfsshare  41926656  535040  41391616   2% /data/apps/nginx/html/wordpress/wp-content/uploads
tmpfs                            81724       0     81724   0% /run/user/0
[root@CentOS8 ~]#

  挂载成功~问题解决!原来纯属自己挖的坑!
  记录一下,也算,增长点见识,吸取些教训。


一个低调的男人