NFS伺服器搭建(基礎)

2021-10-08 17:46:40 字數 4010 閱讀 2470

[root@localhost ~]

# rpm -qa | grep rpcbind

rpcbind-0.2.0-23.el7.x86_64

[root@localhost ~]

# rpm -qa | grep nfs

nfs4-acl-tools-0.3.3-13.el7.x86_64

nfs-utils-1.3.0-0.el7.x86_64

libnfsidmap-0.25-9.el7.x86_64

[root@localhost ~]

# systemctl start rpcbind

[root@localhost ~]

# systemctl start nfs

[root@localhost ~]

# vim /etc/exports

/home/share 192.168.11.0/24(rw,ro)

[root@localhost ~]

mkdir -p /home/share

[root@localhost ~]

chmod 755 /home/share

[root@localhost ~]

# ll -d /home/share/

drwxr-xr-x. 2 root root 6 7月 31 10:57 /home/share/

[root@localhost ~]

# systemctl restart rpcbind

[root@localhost ~]

# systemctl restart nfs

[root@localhost ~]

# mkdir /home/share

[root@localhost ~]

# mount -t nfs 192.168.11.10:/home/share /home/share/

[root@localhost ~]

# df -ht

檔案系統 型別 容量 已用 可用 已用% 掛載點

devtmpfs devtmpfs 905m 0 905m 0% /dev

tmpfs tmpfs 914m 136k 914m 1% /dev/shm

tmpfs tmpfs 914m 8.9m 905m 1% /run

tmpfs tmpfs 914m 0 914m 0% /sys/fs/cgroup

/dev/sda1 xfs 497m 119m 379m 24% /boot

192.168.11.10:/home/share nfs4 48g 33m 48g 1% /home/share

/dev/sr0 iso9660 3.5g 3.5g 0 100% /mnt

測試服務端建立檔案

客戶端檢視檔案

cat /var/log/message|

grep nfs

oct120:36:09 servera systemd[1]: nfs-server.service: failed with result 'exit-code'

.0ct7 20:37:42 servera systemd[1]: nfs-server.service: control process exited,code=xited statu

s=1oct 7 20:37:42 servera systemd[1]: nfs-server.service: failed with result 'exit-code '

.0ct7 20:38:05 servera kernel: nfsd: last server has exited,flushing export cache

oct 7 20:38:43 servera kernel: nfsd: last server has exited,flushing export cache

s=10ct7 20:38:43 servera systemd[1]: nfs-server.service: control process exited,code=exited statu

oct 7 20:38:44 servera systemd[1]: nfs-server.service: failed with result 'exit-code'

.oct 7 20:39:10 servera systemd[1]: nfs-server.service:control process exited,code=xited statu

s=1

1、/etc/exports檔案格式

《輸出目錄》 [客戶端1 選項(訪問許可權,使用者對映,其他)] [客戶端2 選項(訪問許可權,使用者對映,其他)](exprots檔案中每一行提供了乙個共享目錄的設定)

2、相關說明

1️⃣:輸出目錄:輸出目錄是指nfs系統中需要共享給客戶機使用的目錄;

2️⃣:客戶端:客戶端是指網路中可以訪問這個nfs輸出目錄的計算機;

客戶端常用的指定方式:

指定ip位址的主機:192.168.10.10

指定子網中的所有主機:192.168.10.0/24 192.168.10.*

指定網域名稱的主機:www.test.com.cn

指定域中的所有主機:.test.com.cn

所有主機:

3️⃣:選項的種類:

1)、訪問許可權選項:

設定輸出目錄唯讀:ro

設定輸出目錄讀寫:rw

2)、使用者對映選項:

all_squash:將遠端訪問的所有普通使用者及所屬組都對映為匿名使用者或使用者組(nfsnobody);

no_all_squash:與all_squash取反(預設設定);

root_squash:將root使用者及所屬組都對映為匿名使用者或使用者組(預設設定);

no_root_squash:與rootsquash取反;

anonuid=***:將遠端訪問的所有使用者都對映為匿名使用者,並指定該使用者為本地使用者(uid=***);

anongid=***:將遠端訪問的所有使用者組都對映為匿名使用者組賬戶,並指定該匿名使用者組賬戶為本地使用者組賬戶(gid=***);

3)、其它選項:

secure:限制客戶端只能從小於1024的tcp/ip埠連線nfs伺服器(預設設定);

insecure:允許客戶端從大於1024的tcp/ip埠連線伺服器;

sync:將資料同步寫入記憶體緩衝區與磁碟中,效率低,但可以保證資料的一致性;

async:將資料先儲存在記憶體緩衝區中,必要時才寫入磁碟;

wdelay:檢查是否有相關的寫操作,如果有則將這些寫操作一起執行,這樣可以提高效率(預設設定);

no_wdelay:若有寫操作則立即執行,應與sync配合使用;

subtree:若輸出目錄是乙個子目錄,則nfs伺服器將檢查其父目錄的許可權(預設設定);

no_subtree:即使輸出目錄是乙個子目錄,nfs伺服器也不檢查其父目錄的許可權,這樣可以提高效率;

no_root_squash:是讓root保持許可權;

root_squash:是把root對映成nobody,no_all_squash 不讓所有使用者保持在掛載目錄中的許可權。

相關說明

NFS伺服器搭建(基礎篇)

客戶端疑難雜症 nfs 是 network file system 的縮寫,即網路檔案系統。功能是讓客戶端通過網路訪問不同主機上磁碟裡的資料,主要用在類unix系統上實現檔案共享的一種方法。nfs version 4 nfsv4 works through firewalls and on the ...

NFS 伺服器搭建

首先在vmware上搭建兩個系統我選擇的兩個ubuntu系統 ubuntu1 ip位址192.168.1.49 ubuntu2 ip位址192.168.1.51 兩個系統分別執行下面的命令 sudo apt get install nfs kernel server 安裝 nfs 伺服器端 sudo...

搭建NFS伺服器

搭建乙個nfs伺服器 nfs應用場景及好處 nfs配置 在服務端和客戶端安裝nfs utils 在服務端啟動服務 systemctl start rpcbind nfs serversystemctl start rpcbind首先建立共享目錄,mkdir p nfs 在修改 etc exports...