linux 下 安装 nfs 服务

linux 下 安装 nfs 服务

一、debian 配置nfs服务器

1、 安装 nfs 服务

apt-get install nfs-common nfs-kernel-server

2、创建需要共享的目录

mkdir /mnt/nfs
chmod a+w /mnt/nfs

3、修改/etc/exports文件,将需要共享的目录和客户添加进来

/mnt/nfs  *(rw,sync) *(ro,rw)

4、启动服务

/etc/init.d/nfs-kernel-server start

5、挂在nfs

mkdir /mnt/nfs
mount 192.168.1.99:/mnt/nfs /mnt/nfs

6、自动挂载

要在客户端每次启动时自动挂载NFS,可以编辑/etc/fstab,添加一行:

192.168.1.99:/mnt/nfs /mnt/nfs nfs rsize=8192,wsize=8192,timeo=14,intr

二、centos 安装nfs

1、创建共享目录

mkdir -p /mnt/share

2、安装nfs所需软件包

yum install -y nfs-utils

3、编辑export文件,添加从机,只让指定服务器访问共享目录

vi /etc/exports
/mnt/share/ *(rw,no_root_squash,sync)

rw表示可读写;sync表示同步写,no_root_squash 客户机用root访问该共享文件夹时,不映射root用户

4、启动nfs服务,先为rpcbind和nfs做开机启动

systemctl start rpcbind
systemctl start nfs
# 查看状态
systemctl status nfs

5、配置开机自启

systemctl enable rpcbind
systemctl enable nfs

Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.

6、启动完成后,让配置生效

exportfs –r

7、查看

exportfs

/mnt/share    	<world>

8、查看nfs启动后端口

rpcinfo –p localhost

9、设置nfs固定端口

vim /etc/sysconfig/nfs  ##最后面添加如下
# 设置nfs固定端口
RQUOTAD_PORT=4001
LOCKD_TCPPORT=4002
LOCKD_UDPPORT=4002
MOUNTD_PORT=4003
STATD_PORT=4004

10、重启服务

systemctl restart rpcbind
systemctl restart nfs

11、添加iptables firewall 放行端口 见文档 防火墙设置

vim /etc/sysconfig/iptables
需放行 111 2049 4001-4004

12、重启防火墙

systemctl restart iptables

三、centos 安装nfs客户端

1、安装nfs

yum install -y nfs-utils

2、启动rpcbind,设置开机自启、客户端不需要启动nfs

systemctl start rpcbind
systemctl enable rpcbind

3、检查nfs服务端是否开启了共享目录

showmount -e 192.168.1.101

4、客户端创建目录挂载

mkdir -p /mnt/share
mount -t nfs 192.168.1.101:/mnt/share /mnt/share

5、查看挂载情况

df -h

6、永久挂载

vi /etc/fstab
192.168.1.101:/mnt/share /mnt/share nfs default    0 0

7、取消挂载

umount /mnt/share
原文地址:https://www.cnblogs.com/zt19994/p/13299674.html