Server端配置
1、環(huán)境配置
關(guān)閉防火墻捎谨、selinux
2脖捻、安裝nfs
[root@nfs ~]# yum install -y nfs-utils rpcbind
3块促、修改配置
//主配置文件/etc/exports默認(rèn)空
允許訪問的客戶端:IP或域名
網(wǎng)段:192.168.1.0/24
主機(jī):192.168.1.171/32
共享權(quán)限:
參數(shù)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 參數(shù)作用
rw? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- 讀寫權(quán)限
ro? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- 存-- 儲目錄是否時只讀權(quán)限
sync? ? ? ? ? ? ? ? ? ? ? ? ? -- 同步方式存儲數(shù)據(jù) 直接將數(shù)據(jù)保存到磁盤(數(shù)據(jù)存儲安全)
async? ? ? ? ? ? ? ? ? ? ? ? -- 異步方式存儲數(shù)據(jù) 直接將數(shù)據(jù)保存到內(nèi)存(提高數(shù)據(jù)存儲效率)
no_root_squash? ? ? ? -- 不要將root用戶身份進(jìn)行轉(zhuǎn)換?
root_squash? ? ? ? ? ? ? -- 將root用戶身份進(jìn)行轉(zhuǎn)換
all_squash? ? ? ? ? ? ? ? -- 將所有用戶身份都進(jìn)行轉(zhuǎn)換
no_all_squash? ? ? ? ?-- 不要將普通用戶身份進(jìn)行轉(zhuǎn)換
anonuid? ? ? ? ? ? ? ? ? ? -- 指定匿名用戶的UID
anongid? ? ? ? ? ? ? ? ? ? --指定匿名用戶的GID
參考寫法:
/data 192.168.1.0/24(rw,all_squash,sync)
/data 192.168.1.171/32(rw,sync)
echo "/data 192.168.1.0/24(rw,all_squash,sync)" > /etc/exports
[root@nfs ~]# echo "/data 192.168.1.0/24(rw,all_squash,sync)" > /etc/exports
設(shè)置nfs運(yùn)行用戶:
[root@nfs ~]# groupadd -g 666 www
[root@nfs ~]# useradd -u666 -g666? -M -s /sbin/nologin www
[root@nfs ~]#mkdir /data
[root@nfs ~]#chown -R nfsnobody.nfsnobody /data
[root@nfs ~]# echo "/data 192.168.1.0/24(rw,all_squash,sync,anonuid=666,anongid=666)" > /etc/exports
4、創(chuàng)建環(huán)境
[root@nfs ~]# mkdir /data
[root@nfs ~]# chown -R nfsnobody.nfsnobody /data
5阔挠、啟動服務(wù)
[root@nfs ~]# systemctl start rpcbind nfs
[root@nfs ~]# systemctl enable rpcbind
[root@nfs ~]# systemctl enable nfs
6、驗(yàn)證是否掛載
[root@nfs ~]# showmount -e
Export list for nfs:
/data 192.168.1.0/24
Client配置
1脑蠕、安裝nfs
[root@localhost ~]# yum install -y nfs-utils rpcbind
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl enable rpcbind
2购撼、實(shí)現(xiàn)遠(yuǎn)程掛載共享目錄
[root@localhost ~]# showmount -e 192.168.1.170
Export list for 192.168.1.170:
/data 192.168.1.0/24
[root@localhost ~]# mount -t nfs 192.168.1.170:/data? /mnt
//如何實(shí)現(xiàn)自動掛載:
01. 利用rc.local
[root@localhost ~]#echo "mount -t nfs 192.168.1.170:/data? /var/www/html >>/etc/rc.local
02. 利用fstab文件
[root@localhost ~]#vim /etc/fstab
192.168.1.170:/data? /var/www/html? nfs? defaults? 0 0
[root@localhost ~]# echo "192.168.1.170:/data /var/www/html nfs defaults 0 0" >>/etc/fsta
//強(qiáng)制卸載(網(wǎng)絡(luò)問題導(dǎo)致無法訪問存儲)
[root@localhost ~]#umount -lf