一、NFS概述; 二、案例:搭建NFS網(wǎng)絡(luò)共享存儲(chǔ) 一、NFS概述; 概述:NFS是一種基于TCP/IP傳輸?shù)木W(wǎng)絡(luò)文件系統(tǒng)協(xié)議,最初由SUN公司開發(fā)。 通過NFS協(xié)議,客戶機(jī)可以像訪問本地目錄一樣訪問遠(yuǎn)程服務(wù)器中的共享資源。 NFS得到了如NAS等網(wǎng)絡(luò)存儲(chǔ)的設(shè)備極好支持。也是LVS共享存儲(chǔ)的首選。 二、案例:搭建NFS網(wǎng)絡(luò)共享存儲(chǔ); 案例環(huán)境:
案例步驟: ?服務(wù)端安裝nfs-utils、rcpbind軟件包; ?服務(wù)端設(shè)置共享目錄; ?服務(wù)器端啟動(dòng)nfs服務(wù)程序; ?客戶端安裝NFS客戶端程序; ?客戶機(jī)普通mount方式掛載使用nfs共享; ?服務(wù)端驗(yàn)證存儲(chǔ)目錄是否成功存儲(chǔ)文件: ?客戶端以autofs自動(dòng)掛載方式進(jìn)行掛載; ?服務(wù)端安裝nfs-utils、rcpbind軟件包; [root@nfs ~]# yum -y install nfs-utils rpcbind ##rpcbind軟件包提供RPC(遠(yuǎn)程系統(tǒng)調(diào)用)機(jī)制支持,nfs軟件包提供共享服務(wù) [root@nfs ~]# for i in rpcbind nfs;do systemctl enable $i; done ##設(shè)置為開機(jī)啟動(dòng) ?服務(wù)端設(shè)置共享目錄; [root@nfs ~]# mkdir /opt/wwwroot [root@nfs ~]# chmod 777 /opt/wwwroot ##設(shè)置權(quán)限 [root@nfs ~]# vi /etc/exports ##nfs配置共享位置的配置文件,新建 /opt/wwwroot 192.168.100.0/24(rw,sync,no_root_squash) 注解: 文件格式:目錄 主機(jī)(權(quán)限) 權(quán)限:rw讀寫 ro只讀 sync同步寫入 no_root_squash表示客戶機(jī)以root身份訪問時(shí),賦予其本地root權(quán)限,默認(rèn)是root_squash,表示以nfsnobody用戶降權(quán)使用 ?服務(wù)器端啟動(dòng)nfs服務(wù)程序; [root@nfs ~]# systemctl start rpcbind ##先啟動(dòng)rpcbind服務(wù),在啟動(dòng)nfs服務(wù) [root@nfs ~]# kill -HUP `cat /run/gssproxy.pid` ##不然啟動(dòng)nfs失敗 [root@nfs ~]# systemctl start nfs [root@nfs ~]# netstat -utpln |grep rpc tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 16708/rpc.mountd tcp 0 0 0.0.0.0:41884 0.0.0.0:* LISTEN 16632/rpc.statd udp 0 0 0.0.0.0:20048 0.0.0.0:* 16708/rpc.mountd udp 0 0 0.0.0.0:111 0.0.0.0:* 16611/rpcbind udp 0 0 0.0.0.0:670 0.0.0.0:* 16611/rpcbind udp 0 0 127.0.0.1:703 0.0.0.0:* 16632/rpc.statd udp 0 0 0.0.0.0:53500 0.0.0.0:* 16632/rpc.statd [root@nfs ~]# showmount -e 192.168.100.101 ##查看本機(jī)共享的目錄 Export list for 192.168.100.101: /opt/wwwroot 192.168.100.0/24 ?客戶端安裝NFS客戶端程序; [root@client ~]# yum -y install nfs-utils rpcbind [root@client ~]# systemctl start rpcbind [root@client ~]# kill -HUP `cat /run/gssproxy.pid` ##不然啟動(dòng)nfs失敗 [root@client ~]# systemctl start nfs [root@client ~]# systemctl enable nfs [root@client ~]# systemctl enable rpcbind [root@client ~]# showmount -e 192.168.100.101 Export list for 192.168.100.101: /opt/wwwroot 192.168.100.0/24 [root@client ~]# echo 3 >/proc/sys/vm/drop_caches ##清除系統(tǒng)的緩存 ?客戶機(jī)普通mount方式掛載使用nfs共享; [root@client ~]# mkdir /benet [root@client ~]# mount 192.168.100.101:/opt/wwwroot /benet/ [root@client ~]# mount |grep nfs 192.168.100.101:/opt/wwwroot on /benet type nfs4 (rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.100.102,local_lock=none,addr=192.168.100.101) [root@client ~]# vi /etc/fstab 192.168.100.250:/opt/wwwroot /var/www/html nfs defaults,_netdev 0 0 :wq 注:_netdev表示設(shè)備需要網(wǎng)絡(luò) [root@client ~]# mount -a [root@client ~]# touch /benet/1.file [root@client ~]# ls /benet/ 1.file ?服務(wù)端驗(yàn)證存儲(chǔ)目錄是否成功存儲(chǔ)文件: [root@nfs ~]# ls /opt/wwwroot/ 1.file ?客戶端autofs自動(dòng)掛載方式掛在使用nfs共享; [root@client ~]# umount /benet/ 刪除/etc/fstab文件中最末尾的掛載一行; [root@client ~]# tail -1 /etc/fstab /dev/mapper/centos_lwh-swap swap swap defaults 0 0 [root@client ~]# yum -y install autofs [root@client ~]# vi /etc/auto.master ##最后一行添加 /benet /etc/auto.share --timeout=60 注解:/etc/auto.master文件格式 /benet /etc/auto.share --timeout=60 掛載點(diǎn)目錄的第一層 加載第二個(gè)autofs的配置文件 掛載超時(shí)時(shí)間 [root@client ~]# vi /etc/auto.share ##創(chuàng)建的文件 a -fstype=nfs 192.168.100.101:/opt/wwwroot 注解:/etc/auto.share文件格式 a -fstype=nfs 192.168.100.101:/opt/wwwroot 掛載點(diǎn)目錄的第二層 文件系統(tǒng)格式 掛載的源位置 [root@client ~]# systemctl restart rpcbind [root@client ~]# kill -HUP `cat /run/gssproxy.pid` [root@client ~]# systemctl restart nfs [root@client ~]# systemctl start autofs ##啟動(dòng)autofs,加載掛載關(guān)系 [root@client ~]# systemctl enable autofs [root@client ~]# mount |grep nfs |grep 192.168.100.101 [root@client ~]# ls /benet/ [root@client ~]# ls /benet/a 1.file [root@client ~]# mount |grep nfs |grep 192.168.100.101 192.168.100.101:/opt/wwwroot on /benet/a type nfs4 (rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.100.102,local_lock=none,addr192.168.100.101) |
|