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



相关内容

热门资讯

“爱泼斯坦被软禁时,性侵了我” 据英国广播公司BBC报道,一名曾遭受杰弗里·爱泼斯坦性侵的幸存者讲述了这位已故性侵犯者,在因引诱未成...
凤凰女记者战地日记丨一边装行李... 今天早上起来一睁眼,就看看伊朗的局势。美伊昨晚在波斯湾又发生了零星冲突,凌晨12点伊朗说靠近格什姆岛...
菲军方称向参议院派兵负责安保执... 新华社马尼拉5月13日电(记者赵晨捷 李萌)菲律宾武装部队13日发表声明称,当天出现在参议院内的军方...
公众进入武汉大学已无需预约,带... 据“正在新闻”微信公众号、“中国网湖北”微信公众号消息,5月13日,多位市民发视频表示,社会公众进入...
以总理办公室:内塔尼亚胡在对伊... △内塔尼亚胡(资料图)当地时间5月13日晚,以色列总理办公室发表声明称,在“咆哮的狮子”军事行动期间...
伊朗外长:科威特“非法”攻击伊... △伊朗外长阿拉格齐(资料图)当地时间13日晚,伊朗外长阿拉格齐对外表示,科威特“非法”攻击了一艘伊朗...
欧盟召开紧急会议,协调应对汉坦... 当地时间13日,欧盟各成员国常驻欧盟代表在布鲁塞尔举行紧急会议,重点讨论在汉坦病毒疫情背景下加强跨境...
菲律宾总统称未下达逮捕德拉罗萨... 新华社马尼拉5月13日电(记者赵晨捷 李萌)据菲律宾媒体报道,菲总统马科斯13日称未下达逮捕参议员德...
时隔九年再度来京,特朗普有何诉... ◆5月12日,特朗普登上“空军一号”前对着镜头挥手告别。(图源:美联社)文/何平编辑/漆菲5月13日...
硬科技管控,中美关系的新压舱石 特朗普此次访华,英伟达CEO黄仁勋随行的消息提振美股市场,凸显芯片与人工智能已成为中美关系的核心议题...