Linux服务NFS配置详细步骤

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux服务NFS配置详细步骤相关的知识,希望对你有一定的参考价值。

1.环境准备

以用户名[[email protected] ~] ip:192.168.24.181/24为服务端
以用户名[[email protected] ~] ip:192.168.24.132/24为客户端

服务端配置

2.基础环境配置

关闭firewalld防火墙

[[email protected] ~]# systemctl disable firewalld
[[email protected] ~]# systemctl stop firewalld

关闭selinux

[[email protected] ~]# sed -ri ‘#^SELINUX=#cDELINUX=Disabled‘ /etc/selinux/config
[[email protected] ~]# setenforce 0

安装NFS-Server

//安装nfs服务主程序

[[email protected] ~]# yum -y install nfs-utils rpcbind

3.启动NFS-server

//启动rpcbind服务,并查看rpc注册信息

[[email protected] ~]# systemctl start rpcbind
[[email protected] ~]# systemctl enable rpcbind

[[email protected] ~]# systemctl start nfs-server
[[email protected] ~]# systemctl enable nfs-server

[[email protected] ~]# rpcinfo -p localhost
   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

4.查看系统中运行的NFS相关进程

[[email protected] ~]# ps -ef | egrep "rpc|nfs"

5.NFS服务端配置共享目录

编辑nfs主配置文件,共享目录linfan至192.168.24.132/24,可读写,统一用户

[[email protected] ~]# vi /etc/exports
/data 192.168.24.132/24(rw,sync,all_squash)

创建需要共享的目录

[[email protected] ~]# mkdir /data

重启NFS-server服务,查看共享文件是否存在

[[email protected] ~]# systemctl restart nfs-server
[[email protected] ~]# cat /var/lib/nfs/etab
/data   192.168.24.132/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,secure,root_squash,all_squash)

nfs统一给客户端为65534用户权限,查看65534属于哪个用户,递归赋予data目录nfsnobody

[[email protected] ~]# grep "65534" /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
[[email protected] ~]# chown -R nfsnobody.nfsnobody /data/
[[email protected] ~]# ls /data/ -dl
drwxr-xr-x. 2 nfsnobody nfsnobody 6 Aug  2 16:12 /data/

重启nfs-server服务生效

[[email protected] ~]# systemctl restart nfs-server

客户端

1.关闭防火墙,关闭selinux

[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# systemctl disable firewalld

[[email protected] ~]# sed -ri ‘#^SELINUX=#cDELINUX=Disabled‘ /etc/selinux/config
[[email protected] ~]# setenforce 0

2.安装相关服务,仅启动rpcbind服务即可

[[email protected] ~]# yum -y install nfs-utils rpcbind
[[email protected] ~]# systemctl enable rpcbind
[[email protected] ~]# systemctl start rpcbind

3.客户端查看远程服务器提供可挂载信息

[[email protected] ~]# showmount -e 192.168.24.181
Export list for 192.168.24.181:
/data 192.168.24.132/24

4.客户端挂载共享data

[[email protected] ~]# mount -t nfs 192.168.24.181:/data /mnt
[[email protected] ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   17G  6.0G   12G  35% /
devtmpfs                 478M     0  478M   0% /dev
tmpfs                    489M     0  489M   0% /dev/shm
tmpfs                    489M   26M  464M   6% /run
tmpfs                    489M     0  489M   0% /sys/fs/cgroup
/dev/sda1               1014M  125M  890M  13% /boot
tmpfs                     98M     0   98M   0% /run/user/0
192.168.24.181:/data      17G  1.8G   16G  11% /mnt

5.测试nfs是否成功

客户端操作

在客户端mnt下创建一个文件hello

## [[email protected] ~]# ls /mnt/
[[email protected] ~]# cd /mnt/
[[email protected] mnt]# touch hello
[[email protected] mnt]# ls
hello

服务端操作

在服务端查看data下是否存在文件hello

[[email protected] ~]# ls /data
hello

以上是关于Linux服务NFS配置详细步骤的主要内容,如果未能解决你的问题,请参考以下文章

linux配置nfs步骤

Linux的nfs技术

linux配置nfs步骤及心得

Linux6/Centos6 NFS详细配置

简述安装nfs网络共享服务的步骤

Centos 6.* 下搭建pxe+dhcp+nfs+kickstart