网络文件共享服务主流---NFS

网络文件共享服务主流—NFS

NFS的定义

nfs(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源
适用于linux与unix之间文件共享,不能实现linux与windows间的文件共享功能
只能基于IP进行认证
运行在应用层的协议,监听于2049/tcp和2049/udp套接字

NFS配置详细步骤

环境准备
服务端:192.168.228.20/24
客户端:192.168.228.23/24

服务端配置:

关闭防火墙和selinux
[root@yaoxiaorong ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@yaoxiaorong ~]# systemctl stop firewalld

[root@yaoxiaorong ~]# setenforce 0

安装NFS-server

安装nfs服务主程序
[root@yaoxiaorong ~]# yum -y install nfs-utils rpcbind
启动nfs-server服务,并查看rpc注册信息
[root@yaoxiaorong ~]# systemctl start rpcbind
[root@yaoxiaorong ~]# systemctl enable rpcbind
[root@yaoxiaorong ~]# systemctl start nfs-server
[root@yaoxiaorong ~]# systemctl enable nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@yaoxiaorong ~]# 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
    100024    1   udp  39671  status
    100024    1   tcp  34344  status
    100005    1   udp  20048  mountd
    100005    1   tcp  20048  mountd
    100005    2   udp  20048  mountd
    100005    2   tcp  20048  mountd
    100005    3   udp  20048  mountd
    100005    3   tcp  20048  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  37059  nlockmgr
    100021    3   udp  37059  nlockmgr
    100021    4   udp  37059  nlockmgr
    100021    1   tcp  40045  nlockmgr
    100021    3   tcp  40045  nlockmgr
    100021    4   tcp  40045  nlockmgr

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

[root@yaoxiaorong ~]# ps -ef |egrep "rpc|nfs"
rpc        3423      1  0 20:10 ?        00:00:00 /sbin/rpcbind -w
rpcuser    3467      1  0 20:10 ?        00:00:00 /usr/sbin/rpc.statd
root       3468      2  0 20:10 ?        00:00:00 [rpciod]
root       3478      1  0 20:10 ?        00:00:00 /usr/sbin/rpc.idmapd
root       3480      1  0 20:10 ?        00:00:00 /usr/sbin/rpc.mountd
root       3490      2  0 20:10 ?        00:00:00 [nfsd4_callbacks]
root       3496      2  0 20:10 ?        00:00:00 [nfsd]
root       3497      2  0 20:10 ?        00:00:00 [nfsd]
root       3498      2  0 20:10 ?        00:00:00 [nfsd]
root       3499      2  0 20:10 ?        00:00:00 [nfsd]
root       3500      2  0 20:10 ?        00:00:00 [nfsd]
root       3501      2  0 20:10 ?        00:00:00 [nfsd]
root       3502      2  0 20:10 ?        00:00:00 [nfsd]
root       3503      2  0 20:10 ?        00:00:00 [nfsd]
root       3530   2416  0 20:12 pts/1    00:00:00 grep -E --color=auto rpc|nfs

nfs服务端配置共享目录

编辑nfs主配置文件,共享目录data至192.168.228.23/24,可读写,统一用户
[root@yaoxiaorong ~]# vim /etc/exports
/data 192.168.228.23/24(rw,sync,all_squash

创建需要共享的目录
[root@yaoxiaorong ~]# mkdir /data

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

[root@yaoxiaorong ~]# systemctl restart nfs-server
[root@yaoxiaorong ~]# cat /var/lib/nfs/etab
/data   192.168.228.23/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

[root@yaoxiaorong ~]# grep "65534" /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
[root@yaoxiaorong ~]# chown -R nfsnobody.nfsnobody /data/
[root@yaoxiaorong ~]# ls /data/ -dl
drwxr-xr-x. 2 nfsnobody nfsnobody 6 Sep  2 20:16 /data/

重启nfs-server服务生效

[root@yaoxiaorong ~]# systemctl restart nfs-server

客户端配置

关闭防火墙和selinux
[root@yxr ~]# systemctl stop firewalld
[root@yxr ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@yxr ~]# setenforce 0

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

[root@yxr ~]# yum -y install nfs-utils rpcbind

[root@yxr ~]# systemctl enable rpcbind
[root@yxr ~]# systemctl start rpcbind

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

[root@yxr ~]# showmount -e 192.168.228.20
Export list for 192.168.228.20:
/data 192.168.228.23/24

客户端挂载共享data

[root@yxr ~]# showmount -e 192.168.228.20
Export list for 192.168.228.20:
/data 192.168.228.23/24
[root@yxr ~]# mount -t nfs 192.168.228.20:/data /mnt
[root@yxr ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/centos_yxr-root   17G  1.7G   16G  10% /
devtmpfs                     478M     0  478M   0% /dev
tmpfs                        489M     0  489M   0% /dev/shm
tmpfs                        489M  6.8M  482M   2% /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.228.20:/data         5.0G  1.6G  3.5G  31% /mnt

测试nfs是否成功,在客户端/mnt下创建一个文件z

[root@yxr ~]# cd /mnt/
[root@yxr mnt]# touch z
[root@yxr mnt]# ls
z

服务端操作,查看data下是否存在文件z

[root@yaoxiaorong ~]# ls /data/
z

猜你喜欢

转载自blog.csdn.net/zzs183yxr_zzs/article/details/82318852
今日推荐