Simple use of NFS
Create a directory on the NFS server to store shared files and provide NFS disk space
[root@PROD2] # mkdir-p / u01/nfs_shares
[root@PROD2 ~] # ll / U01
Total dosage 8
Drwxr-xr-x 4 oracle oinstall 4096 November 30 16:18 app
Drwxr-xr-x 2 root root 4096 December 4 18:25 nfs_shares
Use this directory for NFS shares
[root@PROD2 ~] # vi / etc/exports
[root@PROD2 ~] # cat / etc/exports
/ u01/nfs_shares * (rw,sync,no_wdelay,insecure_locks,no_root_squash)
Start the NFS service (configuration information requires NFS restart to take effect)
[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]
On the machine that uses the NFS service, create a directory as the mount point and mount the shared directory
[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)
Other users can use this directory, but they need to be given the appropriate permissions
[root@PROD1 ~] # su-oracle
[oracle@PROD1 ~] $cd / u01/oradata/
[oracle@PROD1 oradata] $ll
Total 0
[oracle@PROD1 oradata] $touch
Touch: cannot touch `': 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
[oracle@PROD1 oradata] $ll
Total 0
-rw-r--r-- 1 oracle oinstall 0 Dec 4 18:43
After uninstalling the NFS shared directory, you will find that the newly created file is missing
[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/
Total dosage 0
Check on the NFS server, and the file appears here.
[root@PROD2 ~] # ll / u01/nfs_shares/
Total dosage 0
-rw-r--r-- 1 oracle oinstall 0 December 4 18:43
At the same time, a magical thing happened, and the owner of the directory changed.
[root@PROD2 ~] # ll / U01
Total dosage 8
Drwxr-xr-x 4 oracle oinstall 4096 November 30 16:18 app
Drwxr-xr-x 2 oracle oinstall 4096 December 4 18:43 nfs_shares