安裝部署
yum install nfs-utils -y
systemctl start nfsfirewall-cmd --list-all
firewall-cmd --permanent --add-service=nfs
firewall-cmd --reload
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --reload
firewall-cmd --permanent --add-service=mountd
firewall-cmd --reload
vim /etc/exports #設置共享目錄
exportfs -rv #重新掛載/etc/exports 裏面的設置,並將共享的目錄顯示到屏幕上
-r #重新掛載/etc/exports 裏面的設置
-v #在 export的時候,將共享的目錄顯示到屏幕上
-a #全部掛載(或卸載) /etc/exports文件中設置
-u #卸載某一目錄
客戶端:
showmount -a 172.25.254.133 #顯示當前主機與客戶端NFS連接狀態showmount -e 172.25.254.133 #顯示某臺主機的/etc/exports 所共享目錄數據
mount 172.25.254.127:/westos/nfs /mnt
掛載出錯:
mount.nfs: an incorrect mount option was specified
加上相應參數後掛載
mount -o vers=3,nfsvers=3 172.25.254.133:/westos/nfs /mnt #至於爲什麼要加這個參數,主要是nfs v4的文件與用戶ID對應比較麻煩,容易出現用戶屬主爲nobody的問題
[root@150 ~]# df文件系統 1K-塊 已用 可用 已用% 掛載點
/dev/vda1 10473900 3123308 7350592 30% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 140 942520 1% /dev/shm
tmpfs 942660 17028 925632 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
172.25.254.133:/westos/nfs 10473984 3176448 7297536 31% /mnt
自動掛載:
yum install autofs -y #安裝軟件
systemctl restart autofs
掛載:
vim /etc/autofs.conf 修改默認掛載時間
cd /net/westos/nfs
vim /etc/auto.master
/misc /etc/auto.misc
/westos/linux /etc/auto.nfs #默認掛載點的上層目錄
vim /etc/auto.nfs
[root@227 ~]# cat /etc/auto.nfsnfs -rw,noatme 172.25.254.127:/westos/nfs
systemctl restart autofs.service
[root@227 172.25.254.127]# cd /westos/linux/nfs
[root@227 nfs]# ls
[root@227 nfs]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3212016 7261884 31% /
devtmpfs 493408 0 493408 0% /dev
tmpfs 508996 80 508916 1% /dev/shm
tmpfs 508996 13388 495608 3% /run
tmpfs 508996 0 508996 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2339 451840 1% /home
172.25.254.127:/westos/nfs 10473984 3145856 7328128
[root@227 ~]# cd /westos/linux/nfs
[root@227 nfs]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3212016 7261884 31% /
devtmpfs 493408 0 493408 0% /dev
tmpfs 508996 80 508916 1% /dev/shm
tmpfs 508996 13388 495608 3% /run
tmpfs 508996 0 508996 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2339 451840 1% /home
172.25.254.127:/westos/nfs 10473984 3145856 7328128 31% /westos/linux/nfs
vim /etc/exports
*(sync,rw,)
exportfs -rv
exporting *:/westos/nfs
[root@227 ~]# cd /westos/linux/nfs
[root@227 nfs]# touch file
touch: cannot touch ‘file’: Permission denied
服務端
[root@127 ~]# chmod 777 /westos/nfs
客戶端
[student@227 nfs]$ touch file
[student@227 nfs]$ ls
student@227 nfs]$ touch file
[student@227 nfs]$ ls
file
[student@227 nfs]$
[root@127 ~]# exportfs -rv
exporting 172.25.254.200:/westos/nfs
exporting *:/westos/nfs
[root@127 ~]# cat /etc/exports
/westos/nfs 172.25.254.200(sync,rw,no_root_squash) *(sync,ro) #200主機可以讀寫,別的主機只讀
[student@227 ~]$ cd /westos/linux/nfs/
[student@227 nfs]$ ls
file file3 file9
[student@227 nfs]$ touch file8
touch: cannot touch ‘file8’: Read-only file system