day34-2019年4月17日nfs基礎(chǔ)配置


一、名詞解釋

1、什么是NFS?

全稱 network file system網(wǎng)絡(luò)文件系統(tǒng)

通過網(wǎng)絡(luò)存儲和組織文件的一種方法或機制2、什么是文件系統(tǒng)

文件系統(tǒng)是操作系統(tǒng)用于明確存儲設(shè)備(常見的是磁盤,也有基于NAND Flash的固態(tài)硬盤)或分區(qū)上的文件的方法和數(shù)據(jù)結(jié)構(gòu);即在存儲設(shè)備上組織文件的方法。操作系統(tǒng)中負責管理和存儲文件信息的軟件機構(gòu)稱為文件管理系統(tǒng),簡稱文件系統(tǒng)。文件系統(tǒng)由三部分組成:文件系統(tǒng)的接口,對對象操縱和管理的軟件集合,對象及屬性。從系統(tǒng)角度來看,文件系統(tǒng)是對文件存儲設(shè)備的空間進行組織和分配,負責文件存儲并對存入的文件進行保護和檢索的系統(tǒng)。具體地說,它負責為用戶建立文件,存入、讀出、修改、轉(zhuǎn)儲文件,控制文件的存取,當用戶不再使用時撤銷文件等。

3、為什么要用共享存儲

前端所有的應(yīng)用服務(wù)器接受到用戶上的圖片、文件、視頻,都會統(tǒng)一的放到后端的存儲上。

為什么要共享存儲?所有節(jié)點服務(wù)器都需要將內(nèi)容存到存儲上,取的統(tǒng)一來取

4、共享存儲的種類

單點存儲系統(tǒng)就是NFS,中小型企業(yè),阿里云服務(wù)器的NAS服務(wù)。OSS對象存儲

大型企業(yè)用FastDFS、Ceph、GlsterFS、Mfs

硬件存儲:傳統(tǒng)企業(yè):穩(wěn)定、2臺 雙主機頭 幾十塊硬盤 RAID10



二、原理及實現(xiàn)

1、NFS工作原理

NFS網(wǎng)絡(luò)文件系統(tǒng)

啟動NFS服務(wù),而且還要啟動很多端口

NFS功能,需要很多服務(wù)。每個服務(wù)都有端口,而且經(jīng)常變化

如何要讓客戶端找到這些端口呢?就需要一個rpc服務(wù)

NFS服務(wù):

1、NFS服務(wù)(有很多進程和端口)? ?port:2049

2、RPC服務(wù)(對外固定端口111)

客戶端請求NFS服務(wù),先找RPC 111端口,找到NFS的端口。


NFS工作流程圖


NFS工作原理流程簡圖


檢查狀態(tài)

配置文件? /etc/exports

[root@backup backup]# man exports

EXAMPLE

? ? ? # sample /etc/exports file

? ? ? /? ? ? ? ? ? ? master(rw) trusty(rw,no_root_squash)

? ? ? /projects? ? ? proj*.local.domain(rw)

? ? ? /usr? ? ? ? ? ? *.local.domain(ro) @trusted(rw)

? ? ? /home/joe? ? ? pc001(rw,all_squash,anonuid=150,anongid=100)

? ? ? /pub? ? ? ? ? ? *(ro,insecure,all_squash)

? ? ? /srv/www? ? ? ? -sync,rw server @trusted @external(ro)

? ? ? /foo? ? ? ? ? ? 2001:db8:9:e54::/64(rw) 192.0.2.0/24(rw)

? ? ? /build? ? ? ? ? buildhost[0-9].local.domain(rw)

? ? ? The? first? line exports the entire filesystem to machines master and trusty.? In addition to write access, all uid squashing is turned off for host trusty.

? ? ? The second and third entry show examples for wildcard hostnames and netgroups (this is the entry `@trusted'). The fourth line shows the entry for the PC/NFS

? ? ? client? discussed? above.? Line 5 exports the public FTP directory to every host in the world, executing all requests under the nobody account. The insecure

? ? ? option in this entry also allows clients with NFS implementations that don't use a reserved port for NFS.? The sixth line exports a directory read-write? to

? ? ? the machine 'server' as well as the `@trusted' netgroup, and read-only to netgroup `@external', all three mounts with the `sync' option enabled. The seventh

? ? ? line exports a directory to both an IPv6 and an IPv4 subnet. The eighth line demonstrates a character class wildcard match.

FILES

? ? ? /etc/exports /etc/exports.d

1)待共享的目錄 存東西的目錄 取東西的目錄 例如:/date

2)訪問的主機

? ? 172.16.1.7 (web1) 單個主機

? ? 172.16.1.0/24? ? ? ? ?網(wǎng)段

? ? 172.16.1.*? ? ? ? ? ? ? 網(wǎng)段

3)()權(quán)限

? ? ? rw? ? ? 可讀? ?read? ?write? ?安全? ?慢?

? ? ?async? 異步寫到遠端緩沖區(qū) 不安全? 快??


實踐:

服務(wù)器端:

0、安裝rpcbind和nfs-utils.x86_64 并啟動服務(wù)

yum install -y nfs-utils.x86_64? rpcbind?

systemctl start nfs-utils.service?

systemctl enable nfs-utils.service?

systemctl start? rpcbind

systemctl enable rpcbind

檢查端口注冊

rpcinfo -p 127.0.0.1

1、修改exports文件

[root@nfs01 172.16.1.31]# cat /etc/exports

#wushuo shared dir at time

/date 172.16.1.0/24(rw,sync)

2、創(chuàng)建文件

[root@nfs01 172.16.1.31]# mkdir -p /data

[root@nfs01 172.16.1.31]# ll -d /data

drwxr-xr-x 2 root root 6 Apr 17 11:53 /data

修改文件所屬主組

[root@nfs01 172.16.1.31]# ll -d /data/

drwxr-xr-x 2 nfsnobody nfsnobody 6 Apr 17 11:53 /data/

3、重啟并檢查檢查服務(wù)

[root@nfs01 172.16.1.31]# exportfs -r或

[root@nfs01 172.16.1.31]# systemctl reload nfs.service?

[root@nfs01 172.16.1.31]# systemctl status nfs.service?

● nfs-server.service - NFS server and services

? ?Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)

? ?Active: active (exited) since Wed 2019-04-17 11:56:12 CST; 1min 2s ago

? Process: 9740 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)

? Process: 9736 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)

? Process: 9735 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)

? Process: 9834 ExecReload=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)

? Process: 9766 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl restart gssproxy ; fi (code=exited, status=0/SUCCESS)

? Process: 9750 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)

? Process: 9748 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=1/FAILURE)

?Main PID: 9750 (code=exited, status=0/SUCCESS)


Apr 17 11:56:12 nfs01 systemd[1]: Starting NFS server and services...

Apr 17 11:56:12 nfs01 exportfs[9748]: exportfs: Failed to stat /date: No such file or directory

Apr 17 11:56:12 nfs01 systemd[1]: Started NFS server and services.

Apr 17 11:56:22 nfs01 systemd[1]: Reloading NFS server and services.

Apr 17 11:56:22 nfs01 exportfs[9789]: exportfs: Failed to stat /date: No such file or directory

Apr 17 11:56:22 nfs01 systemd[1]: Reloaded NFS server and services.

Apr 17 11:57:12 nfs01 systemd[1]: Reloading NFS server and services.

Apr 17 11:57:12 nfs01 systemd[1]: Reloaded NFS server and services.


4、檢查并掛載

[root@nfs01 172.16.1.31]# showmount -e 172.16.1.31

Export list for 172.16.1.31:

/data 172.16.1.0/24

[root@nfs01 172.16.1.31]# mount -t nfs 172.16.1.31:/data /mnt

[root@nfs01 172.16.1.31]# touch /mnt/oldboy.test123




客戶端:

0、安裝rpcbind和nfs-utils.x86_64?

yum install -y nfs-utils.x86_64? rpcbind?

systemctl start nfs-utils.service?

systemctl enable nfs-utils.service?

systemctl start? rpcbind

systemctl enable rpcbind

檢查端口注冊

rpcinfo -p 127.0.0.1

1、啟動并檢查檢查服務(wù)

[root@web01 172.16.1.31]# exportfs -r或

[root@web01 172.16.1.31]# systemctl reload nfs.service?

[root@web01 172.16.1.31]# systemctl status nfs.service?

● nfs-server.service - NFS server and services

? ?Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)

? ?Active: active (exited) since Wed 2019-04-17 11:56:12 CST; 1min 2s ago

? Process: 9740 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)

? Process: 9736 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)

? Process: 9735 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)

? Process: 9834 ExecReload=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)

? Process: 9766 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl restart gssproxy ; fi (code=exited, status=0/SUCCESS)

? Process: 9750 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)

? Process: 9748 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=1/FAILURE)

?Main PID: 9750 (code=exited, status=0/SUCCESS)


Apr 17 11:56:12 nfs01 systemd[1]: Starting NFS server and services...

Apr 17 11:56:12 nfs01 exportfs[9748]: exportfs: Failed to stat /date: No such file or directory

Apr 17 11:56:12 nfs01 systemd[1]: Started NFS server and services.

Apr 17 11:56:22 nfs01 systemd[1]: Reloading NFS server and services.

Apr 17 11:56:22 nfs01 exportfs[9789]: exportfs: Failed to stat /date: No such file or directory

Apr 17 11:56:22 nfs01 systemd[1]: Reloaded NFS server and services.

Apr 17 11:57:12 nfs01 systemd[1]: Reloading NFS server and services.

Apr 17 11:57:12 nfs01 systemd[1]: Reloaded NFS server and services.

2、檢查并掛載

[root@web01 172.16.1.31]# showmount -e 172.16.1.31

Export list for 172.16.1.31:

/data 172.16.1.0/24

[root@web01 172.16.1.31]# mount -t nfs 172.16.1.31:/data /mnt

[root@web01 172.16.1.31]# touch /mnt/oldboy.test123

[root@web01 ~]# df

Filesystem? ? ? ? 1K-blocks? ? Used Available Use% Mounted on

/dev/sda3? ? ? ? ? 19911680 2575988? 17335692? 13% /

devtmpfs? ? ? ? ? ? ?229008? ? ? ?0? ? 229008? ?0% /dev

tmpfs? ? ? ? ? ? ? ? 239908? ? ? ?0? ? 239908? ?0% /dev/shm

tmpfs? ? ? ? ? ? ? ? 239908? ? 5664? ? 234244? ?3% /run

tmpfs? ? ? ? ? ? ? ? 239908? ? ? ?0? ? 239908? ?0% /sys/fs/cgroup

/dev/sda1? ? ? ? ? ? 258724? 120952? ? 137772? 47% /boot

tmpfs? ? ? ? ? ? ? ? ?47984? ? ? ?0? ? ?47984? ?0% /run/user/0

172.16.1.31:/data? 19911680 2602688? 17308992? 14% /mnt


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容