Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

NFS 服務端與客戶端部署實戰(CentOS 6.8)

環境:CentOS release 6.8 (Final),內核 2.6.32-642.el6.x86_64,已配置 EPEL 源(https://mirrors.aliyun.com/repo/epel-6.repo),SELinux 已 Disabled,iptables 未運行。

服務端

1. 確認是否安裝 nfs-utils 與 rpcbind

[root@backup ~]# rpm -qa nfs-utils rpcbind
nfs-utils-1.2.3-70.el6_8.1.x86_64
rpcbind-0.2.0-12.el6.x86_64

若未安裝:

[root@oldboy ~]# yum install -y nfs-utils rpcbind

2. 啟動服務(注意順序)

必須先啟動 rpcbind,再啟動 nfs:

[root@oldboy ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
[root@oldboy ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]

3. 加入開機自啟動

[root@oldboy ~]# echo "/etc/init.d/rpcbind start" >> /etc/rc.local
[root@oldboy ~]# echo "/etc/init.d/nfs start" >> /etc/rc.local
[root@oldboy ~]# tail -2 /etc/rc.local
/etc/init.d/rpcbind start
/etc/init.d/nfs start

4. 建立共享目錄

[root@nfs01 ~]# mkdir /data -p
[root@nfs01 ~]# id nfsnobody
uid=65534(nfsnobody) gid=65534(nfsnobody) groups=65534(nfsnobody)
[root@nfs01 ~]# ls -ld /data/
drwxr-xr-x. 2 root root 4096 Sep 23 17:48 /data/

5. 把 /data 的屬主屬組改為 nfsnobody

[root@nfs01 ~]# chown -R nfsnobody.nfsnobody /data/
[root@nfs01 ~]# ls -ld /data/
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Sep 23 17:48 /data/

6. 配置 /etc/exports

[root@nfs01 ~]# cat /etc/exports
#share /data by syaving for oldboy stu at 20160925
/data 172.16.1.0/24(rw,sync)

常用參數:

rw          讀寫權限
ro          只讀權限
async       異步:速度快,但有丟失數據的風險
sync        同步:速度慢,但數據安全
all_squash  把權限都壓制成匿名用戶
anonuid     指定匿名用戶 UID
anongid     指定匿名用戶 GID

7. 重載配置

[root@nfs01 ~]# /etc/init.d/nfs reload
# 等效於 exportfs -rv

8. 驗證

[root@nfs01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24

客戶端

1. 確認已安裝

[root@backup ~]# rpm -qa nfs-utils rpcbind

若未安裝:yum install -y nfs-utils rpcbind

2. 啟動服務

客戶端只需啟動 rpcbind:

[root@oldboy ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]

3. 驗證共享

[root@web01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24

4. 掛載

[root@web01 ~]# mount -t nfs 172.16.1.31:/data /mnt
# 注意:換機器使用時,記得把 IP 改掉
[root@web01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 19G 1.5G 17G 9% /
tmpfs 931M 0 931M 0% /dev/shm
/dev/sda1 190M 38M 142M 22% /boot
172.16.1.31:/data 19G 1.5G 7G 9% /mnt

5. 開機自動掛載

[root@web01 ~]# echo "mount -t nfs 172.16.1.31:/data /mnt" >> /etc/rc.local

6. 驗證雙向可寫

客戶端:

[root@web01 ~]# cd /mnt/
[root@web01 mnt]# mkdir 123
[root@web01 mnt]# ls
123

服務端:

[root@nfs01 ~]# ls /data/
123

原文出自「宋某人c」博客:https://syaving.blog.51cto.com/5614476/1862995

Copyright © Linux教程網 All Rights Reserved