最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】CentOS 7中fstab中添加了系统启动时自动挂载NFS但无效

CentOS crifan 16648浏览 0评论

【问题】

折腾:

【已解决】在远程Ubuntu服务器中开通NFS服务供别人访问服务器上的文件

期间,

虽然fstab中添加了mount nfs的配置:

121.41.120.185:/home/share/image /root/nfs_client_root/ nfs auto,noatime,nolock,bg,nfsvers=4,intr,tcp,actimeo=1800 0 0

结果服务器重启后,却没有自动mount nfs。

【解决过程】

1.搜:

nfs fstab fail

centos 7 nfs fstab fail

参考:

Bug #1384502 “fstab entry for nfs /home fails to mount on boot” : Bugs : mountall package : Ubuntu

Solving NFS Mounts at Boot Time | The Nubby Admin

2.参考:

Mount /etc/fstab at startup – Server Fault

去看看所谓的netfs是否启动了:

结果chkconfig和ntsysv

试了试,都不太会用。

root@chantyou:~# chkconfig --help
chkconfig version 1.3.61 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage:   chkconfig [--list] [--type <type>] [name]
         chkconfig --add <name>
         chkconfig --del <name>
         chkconfig --override <name>
         chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>
root@chantyou:~# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

aegis           0:off   1:off   2:on    3:on    4:on    5:on    6:off
agentwatch      0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
root@chantyou:~# ntsysv --help
--help: unknown option
root@chantyou:~# ntsysv -h
-h: unknown option
root@chantyou:~# ntsysv netfs

ntsysv 1.3.61 - (C) 2000-2001 Red Hat, Inc.                                                                         
...                                                                                                                                    
root@chantyou:~# 

3.参考:

14.04 – Can’t auto-mount NFS share using fstab – Ask Ubuntu

想办法去:

【已解决】CentOS和Ubuntu中如何确认已安装的NFS的版本

发现此处的NFS的版本号的确是4。

所以继续去找其他原因。

4.去开启netfs,结果出错:

root@chantyou:~# chkconfig netfs on
error reading information on service netfs: No such file or directory

5.参考:

Mount /etc/fstab at startup – Server Fault

去给rc.local中最后添加一行:

mount -a

但是对于CentOS 7中的rc.local在哪里都不知道。

所以再去搜:

centos 7 rc.local

参考:

linux – CentOS – commands in rc.local not run – Unix & Linux Stack Exchange

Make /etc/rc.local works in CentOS 7-Hard Coder

centos 7 /etc/rc.local 开机不执行的问题 – 闲潭小筑 – 51CTO技术博客

所以去给:

/etc/rc.d/rc.local

添加可执行权限:

root@chantyou:~# ls /etc/r
rc0.d/            rc3.d/            rc6.d/            redhat-lsb/       request-key.d/    rpm/              rsyslog.d/
rc1.d/            rc4.d/            rc.d/             redhat-release    resolv.conf       rsyncd.conf       rwtab
rc2.d/            rc5.d/            rc.local          request-key.conf  rpc               rsyslog.conf      rwtab.d/
root@chantyou:~# ls /etc/rc.
rc.d/     rc.local  
root@chantyou:~# ls /etc/rc.local  -l
lrwxrwxrwx 1 root root 13 Jun  4 15:19 /etc/rc.local -> rc.d/rc.local
root@chantyou:~# ls /etc/rc.d/ -l
total 36
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 init.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc0.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc1.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc2.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc3.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc4.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc5.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc6.d
-rw-r--r--  1 root root  473 May 13 03:44 rc.local
root@chantyou:~# chmod +a /etc/rc.d/rc.local 
chmod: invalid mode: ‘+a’
Try 'chmod --help' for more information.
root@chantyou:~# chmod +x /etc/rc.d/rc.local  
root@chantyou:~# ls /etc/rc.d/ -l            
total 36
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 init.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc0.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc1.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc2.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc3.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc4.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc5.d
drwxr-xr-x. 2 root root 4096 Jun  4 15:21 rc6.d
-rwxr-xr-x  1 root root  473 May 13 03:44 rc.local
root@chantyou:~# 

不过也发现,此处其中并没什么内容:

root@chantyou:~# cat /etc/rc.local 
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
root@chantyou:~# 

然后添加mount -a:

root@chantyou:~# vi /etc/rc.local 

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
mount -a
~                                                                                                                                   
"/etc/rc.local" 14L, 482C written
root@chantyou:~# 

然后重启试试效果。

果然重启后,就可以自动mount了:

root@chantyou:~# df -h
Filesystem                        Size  Used Avail Use% Mounted on
/dev/xvda1                         20G  2.0G   17G  11% /
devtmpfs                          488M     0  488M   0% /dev
tmpfs                             497M     0  497M   0% /dev/shm
tmpfs                             497M  6.5M  490M   2% /run
tmpfs                             497M     0  497M   0% /sys/fs/cgroup
121.41.120.185:/home/share/image   20G  1.8G   17G  10% /root/nfs_client_root
root@chantyou:~# ls /etc/rc.local  -l
lrwxrwxrwx 1 root root 13 Jun  4 15:19 /etc/rc.local -> rc.d/rc.local
root@chantyou:~# ls /etc/rc.d/rc.local -l
-rwxr-xr-x 1 root root 482 Jul 25 10:19 /etc/rc.d/rc.local
root@chantyou:~# 

即,通过df中可以看到nfs挂载成功了。

 

【总结】

此处,CentOS 7中,在fstab中添加了自动挂载NFS的配置,但是系统启动后没有成功挂载的解决办法是:

1.先确保CentOS 7中的rc.local系统启动时可以自动运行

->需要确保该文件有可执行的权限

->/etc/rc.local是个软链接,所链接的实际文件是/ect/rc.d/rc.local,CentOS 7中默认没有执行权限

->所以此处要去给/etc/rc.d/rc.local添加可执行权限:

chmod +x /etc/rc.d/rc.local

2.然后再给/etc/rc.local中最后添加一行:

mount -a

其中-a参数的含义是:

-a, –all mount all filesystems mentioned in fstab

如此,系统启动后,就会运行/etc/rc.local,然后就会执行到

mount -a

即执行fstab中的所有项,最终执行到NFS的mount。

转载请注明:在路上 » 【已解决】CentOS 7中fstab中添加了系统启动时自动挂载NFS但无效

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 这个方案仍然不行,我的是centos 7.2 最后没办法,直接在/etc/rc.d/rc.local增加具体的mount命令
    张凡文9年前 (2016-05-27)回复
85 queries in 0.197 seconds, using 22.13MB memory