【问题】
折腾:
期间,
虽然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
参考:
2.参考:
去看看所谓的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 ] [name]
chkconfig --add
chkconfig --del
chkconfig --override
chkconfig [--level ] [--type ]
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.参考:
想办法去:
发现此处的NFS的版本号的确是4。
所以继续去找其他原因。
4.去开启netfs,结果出错:root@chantyou:~# chkconfig netfs on
error reading information on service netfs: No such file or directory
5.参考:
去给rc.local中最后添加一行:
mount -a
但是对于CentOS 7中的rc.local在哪里都不知道。
所以再去搜:
centos 7 rc.local
参考:
所以去给:
/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。
在CentOS7系统中,通过编辑fstab添加NFS自动挂载配置后,发现服务器重启并未自动挂载。解决方法包括:检查netfs服务是否启动,尝试开启netfs服务,发现rc.local文件无执行权限,给予rc.local执行权限,并在其中添加`mount -a`命令,重启后NFS成功挂载。
2667

被折叠的 条评论
为什么被折叠?



