安装
yum -y install nfs-utils rpcbind
sudo systemctl enable rpcbind
sudo systemctl start rpcbind
sudo systemctl enable nfs-server
sudo systemctl start nfs-server
常用 配置
cat /etc/exports
/data/test 10.1.1.0/24(rw,sync,no_root_squash,no_all_squash)
-
/data/test
: 共享目录位置。 -
10.1.1.0/24
: 客户端 IP 范围,*
代表所有,即没有限制。 -
rw
: 权限设置,可读可写。 -
sync
: 同步共享目录。 -
no_root_squash
: 可以使用 root 授权。 -
no_all_squash
: 可以使用普通用户授权
NFS配置固定端口
- 首先打开111和2049端口
firewall-cmd --permanent --add-port=111/tcp
firewall-cmd --permanent --add-port=111/udp
firewall-cmd --permanent --add-port=2049/tcp
firewall-cmd --permanent --add-port=2049/udp
- 编辑/etc/sysconfig/nfs文件
添加
RQUOTAD_PORT=1001
去掉下面语句前面的“#”号
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
- 打开1001,32803,32769,892端口
firewall-cmd --permanent --add-port 1001/tcp
firewall-cmd --permanent --add-port 1001/udp
firewall-cmd --permanent --add-port 32803/tcp
firewall-cmd --permanent --add-port 32769/udp
firewall-cmd --permanent --add-port 892/tcp
firewall-cmd --permanent --add-port 892/udp
- 重启服务
systemctl restart rpcbind
systemctl restart nfs-server
- 验证命令
[root@centos7 ~]# rpcinfo -p
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100005 1 udp 892 mountd
100005 1 tcp 892 mountd
100005 2 udp 892 mountd
100005 2 tcp 892 mountd
100005 3 udp 892 mountd
100005 3 tcp 892 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 3 udp 2049 nfs_acl
100021 1 udp 32769 nlockmgr
100021 3 udp 32769 nlockmgr
100021 4 udp 32769 nlockmgr
100021 1 tcp 32803 nlockmgr
100021 3 tcp 32803 nlockmgr
100021 4 tcp 32803 nlockmgr
[root@centos7 ~]# showmount -e 10.1.1.52
Export list for 10.1.1.52:
/data/wwwroot 10.1.1.4/32,10.1.1.0/24
挂载指定nfs版本号
NFS3: mount -t nfs3 -o vers=3,noatime 10.12.1.13:/data/nfsdata /data/nfsdata
NFS4:mount -t nfs 192.168.1.11:/nfs (IP后跟设备名称) /mnt/mountpoint/
NFS4:mount -t nfs4 192.168.1.11:/nfs (IP后跟设备名称) /mnt/mountpoint/
NFS4.1:mount -t nfs -o minorversion=1 192.16.1.11:/nfs(IP后跟设备名称) /mnt/mountpoint/
NFS4.1:mount -t nfs -o vers=4.1 192.16.1.11:/nfs(IP后跟设备名称) /mnt/mountpoint/
查看Nfs服务器
nfsstat -c
nfsstat -s
showmount -e 10.12.1.13 查看nfs服务共享目录
exportfs 管理/etc/exportfs文件
exportfs -r 重新挂载/etc/exportfs文件设置
exportfs -a 生效配置文件
exportfs 查看共享目录
常见问题
NFS4挂载问题
[root@c62 ~]# mount -t nfs4 10.1.1.61:/data /data
mount.nfs4: mounting 10.1.1.61:/data failed, reason given by server: No such file or directory
处理:
处理1:
原来针对NFS4,exports需要一个新的参数fsid,
如我的exports:
/home/bee *(rw,fsid=0,sync,no_root_squash)
处理2:
mount -t nfs4 <serverip>:/ /localmount/point
and not
mount -t nfs4 <serverip>:/exports /localmount/point
网友评论