NFS的简单使用
admin
2023-05-06 20:22:07
0


在NFS服务器建一个目录,用来存共享文件,提供NFS磁盘空间

[root@PROD2 ~]# mkdir -p /u01/nfs_shares

[root@PROD2 ~]# ll /u01

总用量 8

drwxr-xr-x 4 oracle oinstall 4096 11月 30 16:18 app

drwxr-xr-x 2 root   root     4096 12月  4 18:25 nfs_shares

将该目录用于NFS共享

[root@PROD2 ~]# vi /etc/exports 

[root@PROD2 ~]# cat /etc/exports

/u01/nfs_shares               *(rw,sync,no_wdelay,insecure_locks,no_root_squash)


启动NFS服务(配置信息需要NFS重启生效)

[root@PROD2 ~]# service nfs status

rpc.svcgssd is stopped

rpc.mountd is stopped

nfsd is stopped

rpc.rquotad is stopped

[root@PROD2 ~]# service nfs start

Starting NFS services:                                     [  OK  ]

Starting NFS quotas:                                       [  OK  ]

Starting NFS mountd:                                       [  OK  ]

Starting NFS daemon:                                       [  OK  ]

Starting RPC idmapd:                                       [  OK  ]


在使用NFS服务的机器上,创建一个目录作为挂载点,并挂载共享的目录

[root@PROD1 ~]# mkdir -p /u01/oradata

[root@PROD1 ~]# mount -t nfs -o rw PROD2:/u01/nfs_shares /u01/oradata/

[root@PROD1 ~]# mount

/dev/sda3 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

PROD2:/u01/nfs_shares on /u01/oradata type nfs (rw,vers=4,addr=192.168.56.62,clientaddr=192.168.56.61)


其他用户可以使用这个目录,只是需要给予相应权限

[root@PROD1 ~]# su - oracle

[oracle@PROD1 ~]$ cd /u01/oradata/

[oracle@PROD1 oradata]$ ll

total 0

[oracle@PROD1 oradata]$ touch haha

touch: cannot touch `haha': Permission denied

[oracle@PROD1 oradata]$ logout

[root@PROD1 ~]# chown oracle:oinstall /u01/oradata

[root@PROD1 ~]# su - oracle

[oracle@PROD1 ~]$ cd /u01/oradata/

[oracle@PROD1 oradata]$ touch haha

[oracle@PROD1 oradata]$ ll

total 0

-rw-r--r-- 1 oracle oinstall 0 Dec  4 18:43 haha


卸载NFS共享目录以后,会发现新建的文件不见了

[oracle@PROD1 oradata]$ logout

[root@PROD1 ~]# umount /u01/oradata/

[root@PROD1 ~]# mount

/dev/sda3 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

[root@PROD1 ~]# ll /u01/oradata/

总用量 0


在NFS服务器上查看,文件在这里出现了

[root@PROD2 ~]# ll /u01/nfs_shares/

总用量 0

-rw-r--r-- 1 oracle oinstall 0 12月  4 18:43 haha


同时,一个神奇的事情发生,这个目录的所有者改变了

[root@PROD2 ~]# ll /u01

总用量 8

drwxr-xr-x 4 oracle oinstall 4096 11月 30 16:18 app

drwxr-xr-x 2 oracle oinstall 4096 12月  4 18:43 nfs_shares



相关内容

热门资讯

Google在港推出AI代理G... 观点网讯:7月29日,Google在香港推出AI代理Gemini Spark,该代理可全天候在后台运...
5G+165Hz!联想新品官宣... 近两年来,小屏平板一直是比较有趣的一个品类。 不同于大平板注重效率、手机追求万能的特点,拯救者Y70...
原创 马... 马斯克又出来了。这次说2036年钱就没用了。 理由是人工智能加机器人,东西多到你用不完,还拿钱干嘛...
美的集团:我国智能家居互联互通... IT之家 7 月 30 日消息,美的集团今日发布公告,7 月 21 日至 23 日,智能家居互联互通...
华为新款MatePad Pro... 【CNMO科技消息】7月30日,@华为终端 官宣全新旗舰平板华为MatePad Pro。 新款华为...
从实验室到实景验证:6G光子太... 全息通信是第六代移动通信(6G)的典型应用场景之一,旨在通过融合无线传输与全息三维成像技术,实现超大...
从“能对话”到“能干活”——人... 【经济界面】 光明日报记者 刘坤 李晓东 周洪双 人工智能(AI)眼镜化身为个人“助理”,实时进行...
【全新发布】UminiP Pr... (来源:洲明科技)
日本通过“H3火箭8号”发射失... △H3火箭(资料图) 日本文部科学省30日召开关于去年“H3火箭8号”发射失败的会议。会议通过的最终...
互联网巨头抢滩健康硬件,上游芯... 封面新闻记者 付文超 当下,互联网巨头对健康硬件的押注,正在成为产业现实,加速拉动整个产业链步入新一...