天天看點

linux企業常用服務---nfs

NFS是一種基于TCP/IP傳輸的網絡檔案系統協定,最初由SUN公司開發。

通過NFS協定,客戶機可以像通路本地目錄一樣通路遠端伺服器中的共享資源。

NFS得到了如NAS等網絡存儲的裝置極好支援。也是LVS共享存儲的首選。

nfs相關服務

軟體包:nfs-utils,rpcbind

配置檔案:/etc/exports

相關指令:

exportfs

showmount

rpcinfo

mount

基本配置檔案;

/etc/exports

/ 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)

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

部署前準備

配置系統鏡像為本地yum源,配置yum檔案

環境介紹:

使用母盤克隆虛拟機,IP設定為:192.168.100.250并将虛拟機命名為存儲伺服器,使用192.168.100.100作為用戶端。

1.安裝nfs-utils、rcpbind軟體包

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

[root@localhost ~]# for i in rpcbind nfs;do chkconfig $i on; done   ##設定為開機啟動

2.設定共享目錄

[root@localhost ~]# mkdir /opt/wwwroot

[root@localhost ~]# mkdir -p /var/ftp/pub

[root@localhost ~]# chmod 777 /opt/wwwroot  ##設定權限

vi /etc/exports

/opt/wwwroot 192.168.100.0/24(rw,sync,no_root_squash)

/var/ftp/pub 192.168.0.10(ro) 192.168.0.200(rw)

3.啟動nfs服務程式

[root@localhost ~]# /etc/init.d/rpcbind start

[root@localhost ~]# /etc/init.d/nfs start

[root@localhost ~]# netstat -utpnl |grep rpcbind

[root@localhost ~]# showmount -e ##檢視本機共享的目錄

4.客戶機設定

chkconfig rpcbind on

[root@localhost ~]# showmount -e 192.168.100.250

[root@localhost ~]# echo 3 >/proc/sys/vm/drop_caches  ##當nfs因為緩存沒有及時而導緻錯,可以使用該指令

5.客戶機挂載使用nfs共享

[root@localhost ~]# mkdir -p /var/www/html

[root@localhost ~]# mount 192.168.100.250:/opt/wwwroot /var/www/html/

[root@localhost ~]# mount |grep nfs

[root@localhost ~]# vi /etc/fstab 

192.168.100.250:/opt/wwwroot /var/www/html nfs defaults,_netdev 0 0

:wq

[root@localhost ~]# mount -a

驗證:

[root@localhost ~]# cd /var/www/html/

[root@localhost html]# touch a.file

[root@localhost html]# ll