搭建NFS伺服器

2022-05-24 12:00:08 字數 2493 閱讀 9965

nfs即網路檔案系統,允許與他人共享目錄和檔案。

(1).實驗環境

nfs伺服器youxi1  192.168.1.6

測試主機youxi2  192.168.1.7

nfs是c/s模式,監聽2049埠。

(2).實驗

1)在nfs伺服器youxi1上安裝nfs

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

2)啟動nfs,並開機自啟

[root@youxi1 ~]# systemctl start rpcbind

[root@youxi1 ~]# systemctl enable rpcbind

[root@youxi1 ~]# systemctl start nfs-server  //nfs依賴rpcbind進行通訊,所以要先啟動rpcbind

[root@youxi1 ~]# systemctl enable nfs-server

[root@youxi1 ~]# netstat -antup | grep 2049

tcp 0 0 0.0.0.0:2049 0.0.0.0:* listen -

tcp6 0 0 :::2049 :::* listen -

udp 0 0 0.0.0.0:2049 0.0.0.0:* -

udp6 0 0 :::2049 :::* -

3)測試主機youxi2安裝nfs-utils

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

4)測試主機youxi2第一次測試

[root@youxi2 ~]# showmount -e 192.168.1.6

export list for 192.168.1.6:  //提示是空的

5)修改nfs伺服器的配置檔案/etc/exports,將已有的/www/html/資料夾共享出去

[root@youxi1 ~]# ll -d /www/html/

drwxr-xrwx 2 root root 20 5月 19 19:37 /www/html/

[root@youxi1 ~]# vim /etc/exports

/www/html/ 192.168.1.7(rw,no_root_squash)  //可以共享給指定ip(192.168.1.7),也可以共享給指定網段(192.168.1.0),還可以共享給所有ip(*).rw代表讀寫許可權。

[root@youxi1 ~]# exportfs -rv  //重新讀取配置檔案,而不中斷服務

exporting 192.168.1.7:/www/html

/etc/exports配置檔案中許可權引數常用的有如下五個:

ro唯讀許可權

rw讀寫許可權

sync同步寫入記憶體與磁碟當中

no_all_squash保留共享檔案的uid和gid(預設)

no_root_squash使得root使用者具有根目錄的完全訪問許可權

6)測試主機youxi2第二次測試

[root@youxi2 ~]# showmount -e 192.168.1.6

export list for 192.168.1.6:

/www/html 192.168.1.7

7)在測試主機youxi2上掛載nfs

[root@youxi2 ~]# mkdir /html

[root@youxi2 ~]# mount -t nfs 192.168.1.6:/www/html/ /html  //這時候共享才開始正常使用

[root@youxi2 ~]# ls /html

passwd

還可以做開機掛載

[root@youxi2 ~]# vim /etc/fstab 

192.168.1.6:/www/html /html nfs defaults 0 0  //新增一行

新建乙個檔案

[root@youxi2 ~]# touch /html/1.txt

[root@youxi2 ~]# ls /html/

1.txt passwd

8)nfs高併發下掛載優化常用引數(mount -o選項)

async:非同步同步,此引數會提高i/o效能,但會降低資料安全(除非對效能要求很高,對資料可靠性不要求的場合。一般生產環境,不推薦使用)。

noatime:取消更新檔案系統上的inode訪問時間,提公升i/o效能,優化i/o目的,推薦使用。

nodiratime:取消更新檔案系統上的directory inode訪問時間,高併發環境,推薦顯式應用該選項,提高系統效能,推薦使用。

當然也可以寫入/etc/fstab配置檔案

192.168.1.6:/www/html /html nfs noatime,nodiratime 0 0

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...

搭建NFS伺服器。

本指導中的nfs客戶端指執行harmonyos核心的裝置。硬體連線設定。harmonyos核心裝置連線到nfs伺服器的網路。設定兩者ip,使其處於同一網段。比如,設定nfs伺服器的ip為10.67.212.178 24,設harmonyos核心裝置ip為10.67.212.3 24。harmonyo...