如何配置nfs客户端挂载?

NFS

1 前言

企业也环境中常常使用到Linux作为客户端挂载nfs存储,本章对Linux作为客户端挂载进行一次总结。

2 最佳实践

2.1 环境信息

nfs服务器端(linux)
ipaddress=10.168.0.133
hostname=nfsSer.cmdschool.org

samba客户端(linux)
ipaddress=10.168.0.8
hostname=nfsCli.cmdschool.org

NFS的挂载

2.2 NFS服务端配置

In nfsSer,

2.2.1 安装nfs所需的软件包

yum install -y nfs-utils

2.2.2 启动和设置开机启动

/etc/init.d/rpcbind start
chkconfig rpcbind on
/etc/init.d/nfs start
chkconfig nfs on

2.2.3 配置服务端

mkdir /data
chown root:root -R /data
chmod -R 775 /data

以上配置文件夹的权限,

vim /etc/exports

加入如下配置,

//data 10.168.0.8/32(rw,sync,no_root_squash)

注:以上授予IP地址“10.168.0.8/32”读写权限

2.2.4 固定服务端口

vim /etc/sysconfig/nfs

去掉注释启用如下配置,

RQUOTAD_PORT=875
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
STATD_PORT=662
STATD_OUTGOING_PORT=2020
RDMA_PORT=20049

2.2.4 重启服务使配置生效

/etc/init.d/rpcbind restart
/etc/init.d/nfs restart

2.2.5 查询服务端口

rpcinfo -p | awk '{print $3" "$4}' | sort -k2n | uniq

可见如下显示,

proto port
tcp 111
udp 111
tcp 892
udp 892
tcp 2049
udp 2049
udp 32769
tcp 32803

2.2.6 配置防火墙

vim /etc/sysconfig/iptables

加入如下配置,

-A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 892 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 892 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 2049 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 32769 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 32803 -j ACCEPT

重启服务使配置生效,

/etc/init.d/iptables restart

2.3 手动测试nfs挂载

In nfsCli,

2.3.1 安装nfs所需的软件包

yum install -y nfs-utils

2.3.2 手动测试客户端挂载

showmount -e 10.168.0.133
mount -t nfs 10.168.0.133:/data /mnt/

2.3.3 手动测试客户端权限

touch /mnt/a.txt

2.4 配置自动挂载nfs

In nfsCli,

2.4.1 安装所需的软件包

yum install -y autofs

2.4.2 启动服务并配置默认启动

/etc/init.d/autofs start
chkconfig autofs on

2.4.3 配置父挂载点

vim /etc/auto.master

加入如下配置,

/backup /etc/auto.backup

注:“/backup”将由autofs自动创建,请不要手动创建(注意后面不带”/”)

2.4.4 配置子挂载点

vim /etc/auto.backup

加入如下配置,

nfsStorage -fstype=nfs,rw 10.168.0.133:/data

2.4.5 重启服务使配置生效

/etc/init.d/autofs restart

2.4.6 测试nfs挂载

cd /backup/nfsStorage

参阅文档
======================
https://blog.51cto.com/cmdschool/1717865
http://www.jinbuguo.com/man/mount.cifs.html
https://serverfault.com/questions/377170/which-ports-do-i-need-to-open-in-the-firewall-to-use-nfs

没有评论

发表回复

NFS
如何配置NFS服务的ID映射?

1 基础知识 1.1 获取NFS映射帮助 man exports 可见如下章节, User ID M …

NFS
如何解决NFS服务透过DNAT无法挂载问题?

1 前言 一个问题,一篇文章,一出故事。 笔者最近遇到一个NFS挂载异常问题,我们客户端透过DNAT …

NFS
如何基于RHEL 8.x配置NFS4.x服务?

1 前言 一个问题,一篇文章,一出故事。 笔者需要在RHEL 8.x中配置NFS4.x服务,于是整理 …