如果想要實現自動掛載,應該掛在客戶端!!!!!
客戶端:
[root@localhost ~]# yum install nfs-utils -y (下載軟件)
[root@localhost ~]# systemctl start nfs-utils.service (啟動該軟件的服務)[root@localhost ~]# mkdir? ? /bendi_dir(創建/bendi_dir目錄)[root@localhost ~]# mount 192.168.25.131:/data_server ?/bendi_dir(將客戶端的目錄/bendi_dir掛載到服務端的/data_server上,其中IP地址為服務端的)[root@localhost ~]# systemctl start rpcbind.service (啟動該軟件的服務)[root@localhost ~]# yum search autofs(尋找可以自動掛載的軟件)[root@localhost ~]# yum install autofs.x86_64 -y (下載軟件)
[root@localhost ~]# systemctl start autofs.service (啟動軟件)root@localhost ~]# vim /etc/auto.master(進入文件進行編輯)
接著進入
[root@localhost ~]# vim??/etc/auto.misc
紅框為我們所要加的內容,藍框為服務端的地址以及目錄
[root@localhost ~]# systemctl restart autofs.service (重啟服務使配置生效)
服務端:
IP地址為192.168.25.131
[root@localhost ~]# mount /dev/sr0 /mnt? (掛載)[root@localhost ~]# mkdir /data_server(創建目錄)[root@localhost ~]# yum install nfs-utils.x86_64 -y(下載軟件)[root@localhost ~]# systemctl start nfs-server.service (啟動軟件)[root@localhost ~]# vim /etc/exports.d/xx.exports(進入目錄)/data_server ?*(rw)? ? ? ?(把/data_server目錄導出來用,并讓其下的所有主機可以讀和寫)[root@localhost ~]# systemctl restart nfs-utils.service (重啟服務使配置生效)[root@localhost ~]# systemctl stop firewalld.service (關閉防火墻)[root@localhost ~]# exportfs? ? ? -ar(如果不想重啟服務,可以使用這條語句)
[root@localhost ~]# chmod? ?o+w? ?/data_server/? (給客戶端權限)
效果展示:
?
[root@localhost ~]# df -h(檢查掛載)
發現/bendi.dir已經掛載
[root@localhost ~]# umount? ? /bendi_dir? (取消/bendi_dir的掛載)[root@localhost ~]# cd /nfs_share/xixi? (進入到剛才編輯的/nfs_share/xixi查看)[root@localhost ~]# df -h(檢查掛載)
由此可見,自動掛載已經成功!!!!!!
技巧:
在客戶端中我們能看到
[root@localhost ~]# vim /etc/auto.master(進入)
/nfs_share ? ? ?/etc/auto.misc(插入的內容)[root@localhost ~]# vim /etc/auto.misc(進入)
xixi ? ? ? ? ? ?-fstype=nfs ? ? 192.168.5.123:/data_server(插入的內容)這兩個操作可以合并,一起后為mount ? ?192.168.5.123:/data_server ? ? ?/nfs_share/misc ? ?