nfs服务器配置和autofs自动挂载

时间:2019-11-17
本文章向大家介绍nfs服务器配置和autofs自动挂载,主要包括nfs服务器配置和autofs自动挂载使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

NFS服务端:xuegod63.cn   IP:192.168.1.63

NFS客户端:xuegod64.cn   IP:192.168.1.64

NFS服务端概述:

 

NFS,是Network File System的简写,即网络文件系统。网络文件系统是FreeBSD支持的文件系统中的一种,也被称为NFS. NFS允许一个系统在网络上与他人共享目录和文件。通过使用NFS,用户和程序可以像访问本地文件一样访问远端系统上的文件。

 

模式: C/S 模式

 

端口:

RHEL6是以NFSv4作为默认版本,NFSv4使用TCP协议(端口号是2049)和NFS服务器建立连接

 

安装nfs

1、安装NFS软件包

[root@xue63 ~]#rpm -vih /mnt/Packages/nfs-utils-1.2.3-15.el6.x86_64.rpm   

 

yum -y install nfs-utils

 

安装客户端:

命令:mount  showmount 

 

配置文件位置:

[root@xue63 ~]# ls /etc/exports

 

 

启动NFS服务

先查看2049端口是否开放:

[root@xue63 ~]#netstat -anutp | grep 2049

 

[root@xue63 ~]# service nfs start

Startingntpd:                                             [  OK  ]

[root@xue63 ~]# chkconfig nfs on

再查看:

[root@xue63 ~]#netstat -anutp | grep 2049

 

查看nfs服务:

showmount  -e  NFSIP

例:

[root@xuegod64 ~]#showmount  -e 192.168.1.63

 

挂载:

mount    192.168.1.63:/tmp/a    /mnt

 

修改配置文件

[root@xue63 a]# cat /etc/exports

/media                 *(rw)

[root@xue63 a]# service nfs restart

 

客户端查看:

[root@localhost nfs]# showmount -e 192.168.1.63

[root@localhost nfs]# mount  192.168.1.63:/media   /opt/

[root@localhost nfs]# cd /opt/ 

[root@localhost mnt]# touch a.txt

[root@xuegod64 opt]# touch a.txt

touch: cannot touch `a.txt': Permission denied

启动自动挂载nfs 文件系统

[root@xuegod64 opt]#vim /etc/fstab

[root@xuegod64 ~]#umount /opt/

[root@xuegod64 ~]#mount -a

[root@xuegod64 ~]#ls /opt/

a.txt  passwd

配置NFS服务器:

[root@xuegod63tmp]# cat /etc/exports

/media   *(rw)

/tmp/a/no_root_squash      *(rw,no_root_squash)

/tmp/a/sync               192.168.1.0/24(rw,sync)

/tmp/a/ro                  192.168.1.64(ro)

/tmp/a/all_squash             192.168.1.0/24(rw,all_squash,anonuid=500,anongid=500)

/tmp/a/async                    192.168.3.0/255.255.255.0(async)

/tmp/a/rw          192.168.3.0/255.255.255.0(rw)    192.168.4.0/255.255.255.0(rw)

/tmp/a/root_squash   *(rw,root_squash)    

 

[root@xuegod63tmp]# service nfs restart  #重启

 

测试:

[root@xuegod64 ~]#umount /opt/

[root@xuegod64 ~]#mount 192.168.1.63:/tmp/a/no_root_squash /opt/

[root@xuegod64 ~]#touch /opt/no_root_squash.txt

[root@xuegod64 ~]#ll !$

ll/opt/no_root_squash.txt

-rw-r--r-- 1 root root 0 Mar  6 22:15 /opt/no_root_squash.tx

 自动挂载

实现:当在xuegod64上执行 cd  /tmp/a/nfs 命令时,自动把xuegod63上nfs共享的/tmp/a/root_squash目录,自动挂载到xuegod64的/tmp/a/nfs目录下

autofs服务要实现自动挂载涉及到两个文件,主配置文件auto.master和次配置文件auto.misc

/etc/auto.master 文件定义本地挂载点.

/etc/auto.misc 配置文件是用来设置需要挂载的文件系统类型和选项

 

 

[root@xuegod64 ~]#mkdir/tmp/a

[root@xuegod64 ~]#vim /etc/auto.master
/tmp/a  /etc/auto.nfs   --timeout=60

#-timeout=60 挂载超时时间,单位为秒。可以修改这个参数。

[root@xuegod64 ~]#vim /etc/auto.nfs

nfs   -fstype=nfs 192.168.1.63:/tmp/a/root_squash

注:nfs 这个名字可以随意起的

 

启动autofs服务:

[root@xuegod64 ~]#/etc/init.d/autofs restart

Stoppingautomount:                                        [ OK  ]

Startingautomount:                                        [  OK  ]

 

注: 只有cd  /tmp/a/nfs 进去, 触发一下,才能自动挂载。 另外 nfs目录,不能提前创建,自动挂载时,系统自动创建nfs目录。

原文地址:https://www.cnblogs.com/lc24/p/11876640.html