Centos7 x 安裝配置NFS服務和掛載

2021-10-11 03:07:25 字數 4247 閱讀 5969

2.4、啟動nfs服務

2.5、開機自啟服務設定

2.6、將服務端的`/nfs/data`對映到`/upload`目錄

2.7、防火牆新增規則

2.8、建立乙個檔案到共享目錄中

三、客戶端的操作

3.1、安裝nfs-utils

3.2、檢測rpc是否啟動

3.3、使用showmount -e 192.168.118.225檢視

3.3、遠端目錄掛載至本地/upload目錄

3.4、檢視掛載的資料

由於目前公司的專案都是直接將上傳的檔案存放到服務的某個位置,所以如果部署多台伺服器進行集群的話,獲取上傳了的檔案將會是乙個問題。

例如:在192.168.118.225部署了專案,那麼使用者上傳的檔案則會將檔案存放到192.168.118.225伺服器;但是如果我再多個伺服器都部署了專案(192.168.118.225192.168.118.226192.168.118.227),那麼使用者在使用負載均衡的時候會切換到不同節點,就會將檔案上傳到不同的伺服器,那麼上傳的檔案會分散在不同的伺服器(有可能會找不到附件)。

所以就需要將檔案統一存放到乙個伺服器中(例如:192.168.118.225)的某個目錄(/nfs/data),然後將伺服器(192.168.118.225)的目錄像響到本地的某個資料夾,這樣就完美解決了問題

本地使用三颱伺服器,具體說明如下:

因為centos7自帶了rpcbind,所以不用安裝rpc服務,rpc監聽在111埠,可以使用ss -tnulp | grep 111檢視rpc服務是否自動啟動,如果沒有啟動,就systemctl start rpcbind啟動rpc服務。

rpc在nfs伺服器搭建過程中至關重要,因為rpc能夠獲得nfs伺服器端的埠號等資訊,nfs伺服器端通過rpc獲得這些資訊後才能連線nfs伺服器端。

如果執行完systemctl start rpcbind命令發現程式沒有報錯,然而111埠也沒有啟動,則需要檢查一下rpcbind的啟動命令;本人在安裝的過程中就遇到了這種問題:

# 檢視一下rpcbind命令路徑

$ find /etc/ -name '*rpcbind.socket*'

/etc/systemd/system/sockets.target.wants/rpcbind.socket

$ vim /etc/systemd/system/sockets.target.wants/rpcbind.socket

[unit]

description=rpcbind server activation socket

[socket]

listenstream=/var/run/rpcbind.sock

[install]

wantedby=sockets.target

將啟動命令修改為如下內容:

[unit]

description=rpcbind server activation socket

[socket]

listenstream=/var/run/rpcbind.sock

listenstream=

[::]:111

listenstream=0.0.0.0:111

bindipv6only=ipv6-only

[install]

wantedby=sockets.target

$ systemctl daemon-reload

$ systemctl start rpcbind

$ yum -y install nfs-utils
檢視是否安裝成功

$ rpm -qa nfs-utils

nfs-utils-1.3.0-0.68.el7.x86_64

建立檔案存放目錄:

$ mkdir -p /nfs/data
編輯/etc/exports,新增以下內容

/nfs/data       192.168.118.0/24(rw,sync,no_root_squash)
2.3.1、內容介紹
# 啟動nfs服務

$ systemctl start nfs

# 使用命令進行檢視

$ rpcinfo -p localhost

program vers proto port service

100024 1 udp 34354 status

100024 1 tcp 51370 status

100005 1 udp 20048 mountd

100005 1 tcp 20048 mountd

100005 2 udp 20048 mountd

100005 2 tcp 20048 mountd

100005 3 udp 20048 mountd

100005 3 tcp 20048 mountd

100003 3 tcp 2049 nfs

100003 4 tcp 2049 nfs

100227 3 tcp 2049 nfs_acl

100003 3 udp 2049 nfs

100003 4 udp 2049 nfs

100227 3 udp 2049 nfs_acl

100021 1 udp 52382 nlockmgr

100021 3 udp 52382 nlockmgr

100021 4 udp 52382 nlockmgr

100021 1 tcp 41087 nlockmgr

100021 3 tcp 41087 nlockmgr

100021 4 tcp 41087 nlockmgr

# nfs服務開機自啟

$ systemctl enable nfs-server.server

# rpc服務開機自啟

$ systemctl enable rpcbind

$ ln -s /nfs/data/ /upload
# 新增入站規則:192.168.0.0 範圍端的內容都可入站

$ firewall-cmd --permanent --add-rich-rule=

"rule family="ipv4" source address="192.168.0.0/16" accept"

# 新增操作後別忘了執行過載

firewall-cmd --reload

# 建立乙個測試檔案

$ touch /nfs/data/abc.txt

# 往測試檔案中新增資料

$ echo

"hello nfs"

>> /nfs/data/abc.txt

# 客戶端上不需要啟動nfs服務,只是為了使用showmount工具

$ yum -y install nfs-utils

$ showmount -e 192.168.118.225

export list for 192.168.118.225:

/nfs/data 192.168.118.0/24

# 掛載之前先建立掛載的資料夾

$ mkdir /upload

# 執行掛載的命令

$ mount -t nfs 192.168.118.225:/nfs/data /upload

$ cat /upload/abc.txt

hello nfs

CentOS7 X 伺服器安裝配置

boot 200m 1t 根目錄和 usr var 1t 存放日誌使用 home 1t 存放資料 data 1t 存放應用安裝程式 boot 200m swap 64g 1t 根目錄和 usr var 1t 存放日誌使用 home 1t 存放資料 data 1t 存放應用安裝程式 外鏈轉存失敗,源站...

CENTOS7 安裝配置 NFS

centos7 安裝配置 nfs環境 nps 192.168.1.97 client 192.168.1.98 一 yum 安裝 yum y install nfs utils rpcbind nfs 的配置檔案 etc expots 預設為空 vi etc exports opt test 192...

CENTOS7 安裝配置 NFS

nps 192.168.1.97 client 192.168.1.98 yum y install nfs utils rpcbindnfs 的配置檔案 etc expots 預設為空 vi etc exports新增共享的配置條目 opt test 192.168.1.0 24 rw,no ro...