NFS文件服務器


(1).安裝部署
服務端:
[root@fw126 ~]# yum install nfs-utils
[root@fw126 ~]# systemctl start nfs
[root@fw126 ~]# firewall-cmd --permanent --add-service=nfs
[root@fw126 ~]# firewall-cmd --permanent --add-service=rpc-bind
[root@fw126 ~]# firewall-cmd --permanent --add-service=mountd

[root@fw126 ~]# firewall-cmd --reload

[root@fw126 ~]# firewall-cmd --list-all


[root@fw126 ~]# mkdir /westos/nfs -p

[root@fw126 ~]# vim /etc/exports
/westo/nfs      *(sync)

[root@fw126 ~]# exportfs -rv



客戶端:
[root@kh226 ~]# showmount -e 172.25.254.126    #查看
Export list for 172.25.254.126:
/westos/nfs *
[

[root@kh226 ~]# mount 172.25.254.126:/westos/nfs /mnt    #掛載
[root@kh226 ~]# df
 

#2).客戶端自動掛載

  在不使用是還把nfs文件系統掛載在本機中會佔用資源,可每次使用前都掛載會造成無謂的浪費。而自動掛載可以很好的解決這一矛盾。在使用時自動掛載,不用是自動卸載。

客戶端:
[root@kh226 ~]# yum install autofs.x86_64
[root@kh226 ~]# systemctl start autofs

[root@kh226 ~]# rpm -qc autofs                             #查找配置文件,因爲不同的版本,文件路徑會有區別。



vim /etc/sysconfig/autofs

vim /etc/autofs.conf                               #主配置文件

#
# Define default options for autofs.
#
# MASTER_MAP_NAME - default map name for the master map.
#
#MASTER_MAP_NAME="auto.master"
#
# TIMEOUT - set the default mount timeout in secons. The internal
#           program default is 10 minutes, but the default installed
#           configuration overrides this and sets the timeout to 5
#           minutes to be consistent with earlier autofs releases.
#
TIMEOUT=300            #300秒不用自動卸載
#

[root@kh226 ~]# cd /net/172.25.254.126        #默認掛載目錄
[root@kh226 172.25.254.126]# cd westos/nfs/    #掛載點



#300秒後查看
[root@kh226 nfs]# cd
[root@kh226 ~]# df


#3).設置掛載點
[root@kh226 ~]# vim /etc/auto.master
/westos/linux         /etc/auto.nfs

#掛載點的上層目錄    #子配置文件



[root@kh226 ~]# vim /etc/auto.nfs
nfs         -rw         172.25.254.126:/westos/nfs

#掛載點        #掛載方式    #掛載設備


[root@kh226 ~]# systemctl restart autofs.service

[root@kh226 ~]# cd /westos/linux/nfs

充氣autofs服務後,文件/westos/linux/nfs會自動建立。


#4).訪問控制

權限控制:

[root@kh226 nfs]# touch file
touch: cannot touch ‘file’: Read-only file system    #服務不允許

[root@fw126 /]# vim /etc/exports

/westos/nfs     *(sync,rw)


修改爲文件後不能充氣nfs服務,否則客戶端的掛載會出現問題。

[root@fw126 /]# exportfs -rv

exporting *:/westos/nfs



[root@kh226 nfs]# touch file
touch: cannot touch ‘file’: Permission denied        #權限不夠


[root@fw126 /]# chmod 777 /westos/nfs

身份控制:

#服務端:
[root@fw126 /]# id student
uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)
[root@fw126 /]# vim /etc/exports

/westos/nfs     *(sync,rw,anonuid=1000,anongid=1004)    #匿名用戶用1000,1004的身份


[root@fw126 /]# exportfs -rv
exporting *:/westos/nfs

#客戶端:
[root@kh226 nfs]# id kiosk
uid=1004(kiosk) gid=1004(kiosk) groups=1004(kiosk)
[root@kh226 nfs]# ls -l
total 0

-rw-r--r-- 1 student kiosk 0 Dec  8 22:27 file


#服務端:
[root@fw126 nfs]# ls -l
total 0
-rw-r--r--. 1 student westos 0 Dec  8 22:27 file


客戶端和服務端存在的用戶不同,所以文件文件屬豬會以id的方式顯示。


[root@fw126 /]# vim /etc/exports

/westos/nfs     *(sync,rw,no_root_squash)          #客戶端的root用戶登陸時仍保持root權限


[root@kh226 nfs]# touch file

[root@kh226 nfs]# ls -l
total 0
-rw-r--r-- 1 root root 0 Dec  8 22:17 file


訪問控制的設置方式有很多,可以man exportfs查看。會有很多範例。可以根據不同的需求自行設定。

發佈了50 篇原創文章 · 獲贊 2 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章