NFS

NFS服务配置文件参数说明

参数
作用

ro

只读

rw

读写

root_squash

当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户

no_root_squash

当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员

all_squash

无论NFS客户端使用什么账户访问,均映射为NFS服务器的匿名用户

sync

同时将数据写入到内存与硬盘中,保证不丢失数据

async

优先将数据保存到内存,然后再写入硬盘;这样效率更高,但可能会丢失数据

配置文件
说明

/etc/exports

用户配置

/var/lib/nfs/etab

系统处理用户配置后的真实配置

install

yum install nfs-utils rpcbind -y

# rpm -qa nfs-utils rpcbind
# 添加此处配置后将不使用随机端口
vim /etc/sysconfig/nfs

RQUOTAD_PORT=30001
LOCKD_TCPPORT=30002
LOCKD_UDPPORT=30002
MOUNTD_PORT=30003
STATD_PORT=30004
systemctl start rpcbind

systemctl start nfs

# 先启动rpcbind,顺序不能反


systemctl enable rpcbind

systemctl enable nfs


rpcinfo -p 127.0.0.1

netstat -ntlpu | egrep "rpc|nfs"

configure

vim /etc/exports

/data 172.16.1.0/24(rw,sync)


# rw 可读写
# ro 只读
# sync 写到磁盘才算完成,安全 慢
# async 异步写到远程缓冲区,快 不安全
mkdir -p /data

grep nfs /etc/passwd

chown -R nfsnobody.nfsnobody /data

ls -ld /data
systemctl reload nfs


exportfs -r

# 两条等价二选一


showmount -e 172.16.1.31

mount

mount -t nfs 172.16.1.31:/data /mnt

df -hT

install

yum install nfs-utils rpcbind -y

# rpm -qa nfs-utils rpcbind
systemctl start rpcbind

systemctl enable rpcbind


rpcinfo -p 127.0.0.1


netstat -ntlpu | grep rpc

ps -ef | grep rpc
showmount -e 172.16.1.31

mount

mount -t nfs 172.16.1.31:/data /mnt


df -hT

问题解析

NFS服务器出问题时候,要求客户端重启依然能够启动,可以用如下列两个方法:

defaults,soft

defaults,hard,intr

参数写在 /etc/fstab 中

安全加优化的挂载方式如下:

nosuid,noexec,nodev,noatime,nodiratime,intr,rsize=131072,wsize=131072

具体可查看 mount -o 参数对应选项

对 NFS 服务进行内核优化

cat >> /etc/sysctl.conf << EOF
net.core.wmem_defaults = 8388608
net.core.rmem_defaults = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
EOF


sysctl -p

Last updated