NFS的簡單使用


在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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章