多语言展示
当前在线:447今日阅读:126今日分享:42

设置NFS开机自动挂载?

Linux下提供了NFS的技术方案实现不同服务器之间存储共享的需求,本地服务器将远程主机的共享磁盘挂载到本地实现存储共享,那么NFS自动挂载怎么设置开机自动挂载呢?
工具/原料
1

NFS

2

Linux

3

shell

方法/步骤
1

步骤一:编辑shell脚本/usr/local/sbin/nfsboot.sh,内容如下[root@knode1 ~]# cat /usr/local/sbin/nfsboot.sh #!/bin/bash## This is NFS disk automount shell scriptecho 'NFS启动时间点:$(date +'%F %T')' >>nfs.log;val=`df -h|grep website | wc -l`if [ $val -eq 1 ] then          echo  'NFS目录/tmp/website已经挂载,无需再挂' >> nfs.log; else  mount  -o vers=3   10.200.18.100:/tmp/website/ /tmp/website/ echo  'NFS目录/tmp/website挂载成功' >> nfs.log; exitfiecho '执行完毕' >> nfs.log

2

步骤二:给脚本赋予执行权限chmod +x /usr/local/sbin/nfsboot.sh

3

步骤三:将脚本加入开机自启动中如下,将/usr/local/sbin/nfsboot.sh脚本加入自启动中[root@knode1 ~]# cat /etc/rc.d/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/usr/local/sbin/nfsboot.sh

4

步骤四:赋予脚本执行权限chmod +x     /etc/rc.d/rc.local然后服务器重启验证是否自动挂载

注意事项
1

喜欢记得关注我哦!

2

技术文档持续更新!

推荐信息