yum install -y nfs-utils rpcbind 上述命令将安装rpcbind服务和nfs服务。 |
vi /etc/sysconfig/nfs 搜索和设置如下所示的端口配置: RQUOTAD_PORT=30001 LOCKD_TCPPORT=30002 LOCKD_UDPPORT=30002 MOUNTD_PORT=30003 STATD_PORT=30004 |
iptables -I INPUT -p tcp --dport 111 -j ACCEPT
iptables -I INPUT -p udp --dport 111 -j ACCEPT
iptables -I INPUT -p tcp --dport 2049 -j ACCEPT
iptables -I INPUT -p udp --dport 2049 -j ACCEPT
iptables -I INPUT -p tcp --dport 30001:30004 -j ACCEPT
iptables -I INPUT -p udp --dport 30001:30004 -j ACCEPT
service iptables save
service iptables restart
|
vi /etc/selinux/config 将上述文件中的 SELINUX=enforcing 替换为 SELINUX=permissive 保存上述文件之后,运行以下命令: setenforce 0 |
mkdir -p /data/nfs_share 上述命令将建立共享目录/data/nfs_share。 |
vi /etc/exports 在上述文件的末尾新增一行,如下所示: /data/nfs_share 192.168.4.212(rw,sync,no_root_squash) /data/nfs_share *(ro) 这一行表示只有192.168.4.212客户端能够以读写权限挂载共享目录,其他客户端只能以只读权限挂载。 |
chkconfig nfs on chkconfig rpcbind on service nfs start service rpcbind start |
service iptables status rpcinfo -p localhost |
yum install -y nfs-utils |
showmount -e 192.168.4.211 -e选项显示NFS服务端的导出列表。 |
mkdir -p /root/remote_dir 其中,/root/remote_dir为共享目录的挂载点目录。 |
mount -t nfs 192.168.4.211:/data/nfs_share /root/remote_dir 其中,-t选项用于指定文件系统的类型为nfs。 |
umount /root/remote_dir |
mkdir -p /root/remote_dir vi /etc/fstab 在上述文件末尾加入共享目录的挂载条目,如下所示: 192.168.4.211:/data/nfs_share /root/remote_dir nfs defaults 0 0 其中,第5个字段设置为0表示共享目录的文件系统不需要使用dump命令进行转储,第6个字段设置为0表示共享目录的文件系统不需要使用fsck命令进行检查。 |
vi /etc/sysconfig/autofs 将上述文件中的 TIMEOUT=300 替换为 TIMEOUT=600 也就是将不活动状态的超时时间由5分钟修改为10分钟。 配置完成之后,重启autofs服务: service autofs restart |
cd /net/192.168.4.211/data/nfs_share 运行上述命令时,autofs会自动挂载NFS服务端中的网络共享目录。 |
在/net/192.168.4.211/data/nfs_share之下的所有文件和目录停止使用且超时期满之后(10分钟),autofs将卸载共享目录。 |
vi /etc/sysconfig/autofs
将上述文件中的 TIMEOUT=300 替换为 TIMEOUT=600 也就是将不活动状态的超时时间由5分钟修改为10分钟。 |
mkdir -p /root/demo |
vi /etc/auto.master 上述文件的内容如下所示: /root/demo /etc/auto.demo 其中,/root/demo是挂载点的父目录,这个目录在系统中始终可见,并由autofs服务监控,以确定是否“需要”挂载/创建子目录挂载点。/etc/auto.demo为单个配置文件,包含由autofs服务在此父目录下管理的子目录挂载点的列表。 |
vi /etc/auto.demo 上述文件的内容如下所示: remote_dir -rw 192.168.4.211:/data/nfs_share 其中,remote_dir为子目录挂载点,此目录通常不可见,只有当autofs服务创建此目录和挂载共享之后对其进行直接命名/访问时,它才会变为可见。-rw为挂载网络共享时要使用的挂载选项。192.168.4.211:/data/nfs_share为需要挂载的NFS服务端和共享目录。 |
service autofs restart |
cd /root/demo/remote_dir 运行上述命令之后,autofs将自动创建挂载点目录,并且挂载共享目录。 |
在/root/demo/remote_dir之下的所有文件和目录停止使用且超时期满之后(10分钟),autofs将卸载共享目录。
|
--------------------------------------分割线 --------------------------------------
Ubuntu 12.04安装NFS server http://www.linuxidc.com/Linux/2012-09/70728.htm
NFS服务器安装配置实现Ubuntu 12.04与ARM文件共享 http://www.linuxidc.com/Linux/2012-10/73159.htm
Ubuntu搭建nfs服务器 http://www.linuxidc.com/Linux/2012-10/71930.htm
文件服务器NFS配置详解 http://www.linuxidc.com/Linux/2013-06/86542.htm
Ubuntu下搭建NFS网络文件系统服务器 http://www.linuxidc.com/Linux/2013-07/87367.htm
Heartbeat_ldirector+LB+NFS实现HA及LB、文件共享 http://www.linuxidc.com/Linux/2013-06/85292.htm
CentOS 5.5配置NFS服务器教程 http://www.linuxidc.com/Linux/2013-03/81737.htm
Ubuntu 12.10下NFS的安装使用 http://www.linuxidc.com/Linux/2013-03/80478.htm
--------------------------------------分割线 --------------------------------------
更多CentOS相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-01/112051.htm