基于linux下的nfs文件系统
nfs
网络文件系统(NFS)是Unix系统和网络附加存储文件管理器常用的网络文件系统,允许多个客户端通过网络共享文件访问。它可用于提供对共享二进制目录的访问,也可用于允许用户在同一工作组中从不同客户端访问其文件。NFS协议有多个版本:Linux支持版本4、版本3和版本2, 而大多数系统管理员熟悉的是NFSv3。默认情况下,该协议并不安全,但是更新的版本(如NFSv4 )提供了对更安全的身份验证的支持,甚至可以通过kerberos进行加密
(1)服务端
[[email protected] ~]# yum install nfs-utils -y
[[email protected] ~]# systemctl start nfs
客户端:
[[email protected] mnt]# yum install nfs-utils -y
[[email protected] mnt]# showmount -e 172.25.254.200
Export list for 172.25.254.200:
(2)服务端
[[email protected] ~]# vim /etc/exports
/mnt *(sync,ro) 只读
[[email protected] ~]# exportfs -rv
exporting *:/mnt
客户端:
[[email protected] mnt]# showmount -e 172.25.254.200
Export list for 172.25.254.200:
/mnt *
(3)服务端
[[email protected] ~]# vim /etc/exports
/mnt *(sync,rw) 可读可写[[email protected] ~]# exportfs -rv
exporting *:/mnt
客户端
[[email protected] mnt]# mount 172.25.254.200:/mnt /mnt
[[email protected] ~]# cd /mnt
[[email protected] mnt]# ls
file1 file2 file3
[[email protected] mnt]# rm -fr file1
rm: cannot remove ‘file1’: Permission denied
服务端:
[[email protected] ~]# chmod 777 /mnt
客户端:
[[email protected] mnt]# touch file4
[[email protected] mnt]# ll /mnt
total 0
-rw-r--r-- 1 root root 0 Jun 2 01:55 file1
-rw-r--r-- 1 root root 0 Jun 2 01:55 file2
-rw-r--r-- 1 root root 0 Jun 2 01:55 file3
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jun 2 04:40 file4
(4)服务端:
[[email protected] ~]# vim /etc/exports
/mnt *(sync,rw,no_root_squash) 以超级用户root身份运行[[email protected] ~]# exportfs -rv
exporting *:/mnt
客户端:
[[email protected] mnt]# touch file5
[[email protected] mnt]# ll /mnt
total 0
-rw-r--r-- 1 root root 0 Jun 2 01:55 file1
-rw-r--r-- 1 root root 0 Jun 2 01:55 file2
-rw-r--r-- 1 root root 0 Jun 2 01:55 file3
-rw-r--r-- 1 nfsnobody nfsnobody 0 Jun 2 04:40 file4
-rw-r--r-- 1 root root 0 Jun 2 04:42 file5
(5)服务端:
[[email protected] ~]# vim /etc/exports
/mnt *(sync,rw,anonuid=1000,anongid=1000) 以uid为1000,pid为1000用户身份的运行[[email protected] ~]# exportfs -rv
exporting *:/mnt
客户端:
[[email protected] mnt]# rm -fr *
[[email protected] mnt]# ls
[[email protected] mnt]# touch file
[[email protected] mnt]# ll /mnt
total 0
-rw-r--r-- 1 student student 0 Jun 2 04:43 file
(6)服务端:
[[email protected] ~]# mkdir /westos
[[email protected] ~]# chmod 777 /westos
[[email protected] ~]# vim /etc/exports
/mnt *(sync,rw,anonuid=1000,anongid=1000) /mnt 以uid为1000,pid为1000用户身份的运行/westos 172.25.254.0/24(sync) 172.25.254.250(sync,rw) 172.25.254这个网段下对/westos共享,172.25.254.250可以读写
[[email protected] ~]# exportfs -rv
exporting 172.25.254.250:/westos
exporting 172.25.254.0/24:/westos
exporting *:/mnt
一、当我们挂载后不使用也依然在那挂载着浪费资源,所以使用时挂载,不用时卸载
240 yum install autofs -y
242 systemctl start autofs
243 cd /net
244 ls
245 cd 172.25.254.200
247 cd westos
248 ls
249 df
172.25.254.200:/westos 10473984 3156224 7317760 31% /net/172.25.254.200/westos
251 vim /etc/sysconfig/autofs
TIMEOUT=5
252 systemctl restart autofs.service
253 df
254 cd /net
255 cd 172.25.254.200
258 cd westos
259 df
260 ls
261 pwd
/net/172.25.254.200/westos
262 cd(等待5秒后)
263 df(发现已经卸载了)
客户端:
267 vim /etc/auto.master
/nfs /etc/auto.misc
/nfs(挂载点的上层目录) /etc/auto.westos
268 vim /etc/auto.westos
westos(挂载点目录) -rw,vers=3(设置设备的一些属性:可读可写,版本号3) 172.25.254.200:/westos(挂载设备)
269 systemctl restart autofs.service
276 cd /nfs
277 cd westos
278 df
172.25.254.200:/westos 10473984 3156096 7317888 31% /nfs/westos
279 mount
172.25.254.200:/westos on /nfs/westos type nfs (rw,relatime,vers=3,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountad
dr=172.25.254.200,mountvers=3,mountport=20048,mountproto=udp,local_lock=none,addr=172.25.254.200)