CentOS7系統之間設置共享文件夾
說明:有兩臺服務器,ip地址分別爲:192.168.1.135和192.168.1.137
現將135服務器的文件夾/usr/server/tomcatFile/webapps/bidFile/共享給137服務器
(1)安裝NFS
CentOS是自帶NFS,所以無需安裝,若要安裝執行命令:
yum -y installnfs-utils rpcbind
(2)啓用NFS
CentOS默認已啓動,如果沒有啓動,需要執行命令:
service rpcbindstart、service nfs start
(3)配置兩臺服務器的防火牆,執行命令:
firewall-cmd--permanent --add-service=nfs
firewall-cmd--permanent --add-service=mountd
firewall-cmd--permanent --add-service=rpc-bind
firewall-cmd–reload
(4)設置共享目錄
在192.168.1.135服務器上設置共享目錄,編輯/etc/exports,追加以下內容
/usr/server/tomcatFile/webapps/bidFile/ 192.168.1.137(rw,no_root_squash,no_all_squash,sync)
爲了使配置生效,執行命令:
exportfs –r
附:查看已共享的目錄命令:
本機:showmount -e
其他:showmount -e IP
(5)掛載共享文件夾
在192.168.1.137服務器上掛載共享文件夾,輸入命令:
mount -t nfs 192.168.1.135:/usr/server/tomcatFile/webapps/bidFile/ /usr/server/tomcatFile/webapps/bidFile/
(6)測試共享文件夾是否可用
在192.168.1.135服務器的/usr/server/tomcatFile/webapps/bidFile/目錄下新建文件1.txt並填寫一些內容,
打開192.168.1.137服務器的/usr/server/tomcatFile/webapps/bidFile/目錄,若有相同的文件,並且文件中內容一致則表明共享文件夾可用