NFS
network file system (網(wǎng)絡(luò)文件系統(tǒng)),可以把網(wǎng)絡(luò)中的一個硬盤當(dāng)成本機(jī)的來使用忠荞。
背景:解決多個服務(wù)器之間數(shù)據(jù)共享
環(huán)境
CentOS 7.2
linux 主機(jī) s1 服務(wù)端:192.168.134.33
linux 主機(jī) c1 客戶端:192.168.134.131
開始操作
一 環(huán)境檢查:
1湃密、檢查服務(wù)器是否安裝nfs服務(wù)
rpm -q nfs-utils
2占调、如果沒有安裝的話執(zhí)行
yum install nfs-utils -y
3正什、啟動rpcbind
/etc/init.d/rpcbind start #centos 6
/bin/systemctl start rpcbind.service #centos 7
4蝌焚、啟動nfs
/etc/init.d/nfs start #centos 6
/bin/systemctl start nfs.service #centos 7
二 開始配置
1. 在s1上面編輯一個配置文件 /etc/exports
/www/ *(rw,sync) #允許所有的ip訪問
/www/ 192.168.134.131(rw,sync,no_root_squash)
/www/ 192.168.134.0/24(rw,sync,all_squash,anonuid=501,anongid=501)
文件編寫說明:
rw :讀寫裹唆;
ro :只讀;
sync :同步模式只洒,內(nèi)存中數(shù)據(jù)時時寫入磁盤许帐;
async :不同步,把內(nèi)存中數(shù)據(jù)定期寫入磁盤中毕谴;
norootsquash :加上這個選項后成畦,root用戶就會對共享的目錄擁有至高的權(quán)限控制距芬,就像是對本機(jī)的目錄操作一樣。不安全循帐,不建議使用框仔;
root_squash:和上面的選項對應(yīng),root用戶對共享目錄的權(quán)限不高拄养,只有普通用戶的權(quán)限离斩,即限制了root;
all_squash:不管使用NFS的用戶是誰瘪匿,他的身份都會被限定成為一個指定的普通用戶身份跛梗;
anonuid/anongid :要和rootsquash 以及allsquash一同使用,用于指定使用NFS的用戶限定后的uid和gid棋弥,前提是本機(jī)的/etc/passwd中存在這個uid和gid核偿。
介紹了上面的相關(guān)的權(quán)限選項后,再來分析一下剛配置的那個/etc/exports文件顽染。其中要共享的目錄為/home漾岳,信任的主機(jī)為192.168.134.0/24這個網(wǎng)段,權(quán)限為讀寫家乘,同步蝗羊,限定所有使用者,并且限定的uid和gid都為501仁锯。
2. 重啟rpcbind nfs
/bin/systemctl restart rpcbind.service
/bin/systemctl restart nfs.service
/bin/systemctl enable rpcbind.service #開機(jī)啟動
/bin/systemctl enable nfs.service #開機(jī)啟動
3.在s1執(zhí)行以下命令使上面目錄生效
exportfs -arv #讓上面的目錄執(zhí)行成功
4.在客戶端c1上操作
showmount -e 192.168.134.33
# 報錯 clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
# 關(guān)s1防火墻或開相應(yīng)端口
mount -t nfs 192.168.134.33:/guazai /nfsdir #掛載耀找,開機(jī)之后會失效
vim /etc/fstab #編輯開機(jī)掛載文件
192.168.134.33:/guazai /nfsdir nfs defaults 0 0