centos下安裝nfs
1.安裝
nfs服務(wù)器ip:192.168.44.12
# yum install nfs-utils rpcbind
安裝完以后先不急著啟動驳阎,先來了解一下nfs服務(wù)運行在哪些端口上,它默認(rèn)需要使用5個端口郑藏,其中有4個端口是動態(tài)的衡查,所以如果服務(wù)器和客戶端之間有iptables,就要先把這4個動態(tài)端口設(shè)置成靜態(tài)的必盖,查看iptables是否開啟了拌牲,然后加入進(jìn)防火墻規(guī)則里,需要修改的端口有如下四個(端口可以根據(jù)需求改歌粥,不一定就和我這一樣)
2.編輯nfs配置文件
# vi /etc/sysconfig/nfs
LOCKD_TCPPORT=30001 #TCP鎖使用端口
LOCKD_UDPPORT=30002 #UDP鎖使用端口
MOUNTD_PORT=30003 #掛載使用端口
STATD_PORT=30004 #狀態(tài)使用端口
# service iptables status
除了以上四個端口要通過iptables塌忽,還有nfs協(xié)議端口2049以及rpc的111端口,這樣才能順利的使用nfs服務(wù)
# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 111 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 2049 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3001 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3002 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3003 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3004 -j ACCEPT
# service iptables reload
3.創(chuàng)建測試文件
# mkdir /home/wwwroot/default/upload
# touch /home/wwwroot/default/upload/test
4.添加客戶端機(jī)器
# vi /etc/exports
把/home/wwwroot/default目錄共享給192.168.44.13 主機(jī)失驶,可以寫主機(jī)名土居、域名等,使用默認(rèn)參數(shù)(ro,sync,wdelay,root_squash)
/home/wwwroot/default/upload 192.168.44.13(rw,sync,no_root_squash)
/home/wwwroot/default/upload 192.168.44.11(rw,sync,no_root_squash)
5.參數(shù)詳解
- ro #只讀共享
- rw #讀寫共享
- sync #同步寫操作
- async #異步寫操作
- wdelay #延遲寫操作
- root_squash #屏蔽遠(yuǎn)程root權(quán)限
- no_root_squash #不屏蔽遠(yuǎn)程root權(quán)限
- all_squash #屏蔽所有遠(yuǎn)程用戶的權(quán)限
6.啟動nfs服務(wù)
# service nfs start
# service rpcbind start
# chkconfig nfs on
# chkconfig rpcbind on
1.客戶端安裝nfs
# yum install nfs-utils
2.掛載
查看掛載的情況
# mount -l
掛載nfs服務(wù)器的共享目錄到/home/wwwroot/default/
# mount -t nfs 192.168.44.12:/home/wwwroot/default/upload /home/wwwroot/default/upload
取消掛載
# umount -l /home/wwwroot/default/upload
3.開機(jī)自動掛載,添加在客戶端機(jī)器
# echo "192.168.44.12:/home/wwwroot/default/upload /home/wwwroot/default/upload nfs defaults 0 0" >> /etc/fstab
其它的客戶端的nfs安裝一樣嬉探,并且需要在nfs服務(wù)器的/etc/exports下新增下ip擦耀。