NFS服务搭建

简介:

NFS简单的工作原理图


 


 

NFS网络共享服务环境搭建:

准备两台测试机,172.16.2.10(NFS_SERVER),172.16.2.11(NFS_CLIENT)

1、        查看系统版本、内核信息

NFS服务端

[root@nfsserver ~]# ifconfig eth0|awk -F '[:]+' 'NR==2 {print $4}' 
172.16.2.10
[root@nfsserver ~]# cat /etc/redhat-release      //查看系统版本号
CentOS release 6.8 (Final)
[root@nfsserver ~]# uname –r          //查看系统内核版本号
2.6.32-642.el6.x86_64
[root@nfsserver ~]# uname –m        //查看是多少位的操作系统
x86_64


 

NFS客户端

[root@nfsclient ~]# ifconfig eth0|awk -F '[:]+' 'NR==2 {print $4}'
172.16.2.11
[root@nfsclient ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@nfsclient ~]# uname -r
2.6.32-642.el6.x86_64
[root@nfsclient ~]# uname -m
x86_64


 

2、        NFS软件

要部署NFS服务,需要安装下面的软件包

  • nfs-utils:这个是NFS服务主程序

包括rpc.nfsd、rpc,mountd两个daemons和相关文档说明及执行命令文件等

  • portmap:C5.x下面RPC的主程序(C6.x下名字为rpcbind)

NFS可以被视为一个RPC程序,在启动任何一个RPC程序之前,需要做好端口和功能的对应映射工作,这个映射工作就是由portmap(或rpcbind)服务来完成的。因此,在提供NFS服务之前必须先启动portmap(C6.x下为rpcbind)服务

 

3、        查看NFS软件包

方法一:

[root@nfsserver ~]# rpm -qa |grep -E "nfs-utils|portmap|rpcbind"
nfs-utils-1.2.3-70.el6.x86_64
rpcbind-0.2.0-12.el6.x86_64        这个包在C5.x名字为portmap
[root@nfsserver ~]# yum install -ynfs-utils rpcbind        //安装nfs、rpcbind

 

方法二:

[root@ nfsclient ~]# yum grouplist |grep"NFS*"
Failed to set locale, defaulting to C
  NFS file server
[root@nfsclient ~]# yum groupinstall –y "NFSfile server"

 

4、        启动RPC、NFS服务

[root@nfsserver ~]# /etc/init.d/rpcbind start
Starting rpcbind:                                         [    ]
[root@nfsserver ~]# ps -ef |grep rpcbind
rpc     22296     1  0 09:23 ?        00:00:00 rpcbind
[root@nfsserver ~]# /etc/init.d/rpcbindstatus
rpcbind (pid  22296) is running...

 

[root@nfsserver ~]# rpcinfo -p localhost             //查看rpc信息
  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

 

[root@nfsserver ~]# rpcinfo -p localhost    //rpc服务没启来

 

[root@nfsserver ~]# /etc/init.d/nfs start        //启动NFS服务
Starting NFS services:                                    [    ]
Starting NFS quotas:                                      [   ]
Starting NFS mountd:                                      [    ]
Starting NFS daemon:                                      [   ]
Starting RPC idmapd:                                      [    ]

 

[root@nfsserver ~]# 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
   100011    1   udp   875  rquotad
   100011    2   udp   875  rquotad
   100011    1   tcp   875  rquotad
   100011    2   tcp   875  rquotad
   100005    1   udp 58464  mountd
   100005    1   tcp 47366  mountd
   100005    2   udp 42025  mountd
   100005    2   tcp 44812  mountd
   100005    3   udp 34369  mountd
   100005    3   tcp 35447  mountd
   100003    2   tcp  2049  nfs
   100003    3   tcp  2049  nfs
   100003    4  tcp   2049  nfs
   100227    2   tcp  2049  nfs_acl
   100227    3   tcp  2049  nfs_acl
   100003    2   udp  2049  nfs
   100003    3   udp  2049  nfs
   100003    4   udp  2049  nfs
   100227    2   udp  2049  nfs_acl
   100227    3   udp  2049  nfs_acl
   100021    1   udp 41428  nlockmgr
   100021    3   udp 41428  nlockmgr
   100021    4   udp 41428  nlockmgr
   100021    1   tcp 38507  nlockmgr
   100021    3   tcp 38507  nlockmgr
   100021    4  tcp  38507  nlockmgr


 

添加开机自启动

[root@nfsserver ~]# chkconfig nfs on
[root@nfsserver ~]# chkconfig rpcbind on


 

查看rpcbind、nfs启动脚本顺序

[root@nfsserver ~]# head/etc/init.d/rpcbind
#! /bin/sh

[root@nfsserver ~]# head /etc/init.d/nfs
#!/bin/sh

 

5、        客户端

[root@nfsclient ~]# /etc/init.d/rpcbind start
Starting rpcbind:                                         [   ]
[root@nfsclient ~]# chkconfig rpcbind on
[root@nfsclient ~]# chkconfig --list rpcbind
rpcbind         0:off  1:off   2:on    3:on   4:on    5:on   6:off

 

6、        配置共享目录

[root@nfsserver ~]# mkdir /data
[root@nfsserver ~]# vim /etc/exports            //编辑nfs配置文件
#shared data for bbs by oldboy at 20170202
/data 172.16.2.0/24(rw,sync)
[root@nfsserver ~]# /etc/init.d/nfs reload           //重新加载

 

[root@nfsserver ~]# showmount -e localhost            //本机检查NFS共享
Export list for localhost:
/data 172.16.2.0/24

 

[root@nfsclient ~]# showmount -e172.16.2.10          //客户端检查NFS共享
Export list for 172.16.2.10:
/data 172.16.2.0/24

 

[root@nfsclient ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       44G  2.2G  40G   6% /
tmpfs                 939M     0 939M   0% /dev/shm
/dev/sda1             477M   40M 412M   9% /boot

[root@nfsclient ~]# mount -t nfs172.16.2.10:/data /mnt       //挂载NFS共享

[root@nfsclient ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       44G  2.2G  40G   6% /
tmpfs                 939M     0 939M   0% /dev/shm
/dev/sda1             477M   40M  412M   9% /boot
172.16.2.10:/data      44G 2.2G   40G   6% /mnt

 

[root@nfsclient ~]# ls /mnt/
a.txt
[root@nfsclient ~]# touch /mnt/b.txt

 

[root@nfsserver ~]# chmod 777 /data/
[root@nfsclient ~]# touch /mnt/b.txt
[root@nfsclient ~]# ll /mnt/
total 0
-rw-r--r--. 1 root      root     0 Feb  3 09:55 a.txt
-rw-r--r--. 1 nfsnobody nfsnobody 0Feb  3 09:58 b.txt

 

[root@nfsserver ~]# cat /var/lib/nfs/etab
/data  172.16.2.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)
[root@nfsserver ~]# grep 65534 /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFSUser:/var/lib/nfs:/sbin/nologin
[root@nfsserver ~]# chmod 755 /data
[root@nfsserver ~]# chown -Rnfsnobody.nfsnobody /data/
[root@nfsserver ~]# ls -ld /data/
drwxr-xr-x. 2 nfsnobody nfsnobody 4096Feb  3 09:58 /data/

 

[root@nfsclient mnt]# ll
total 0
-rw-r--r--. 1 nfsnobody nfsnobody 0Feb  3 09:55 a.txt
-rw-r--r--. 1 nfsnobody nfsnobody 0Feb  3 09:58 b.txt
[root@nfsclient mnt]# rm -rf a.txt
[root@nfsclient mnt]# ls
b.txt
[root@nfsclient mnt]# touch test



本文转自 小杨_Ivan 51CTO博客,原文链接:本文转自 小杨_Ivan 51CTO博客,原文链接:http://blog.51cto.com/aqiang/1894598

相关文章
|
1月前
|
Linux Shell Windows
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
|
3月前
|
存储 监控 网络协议
【Linux】文件服务NFS(Network File System)
【Linux】文件服务NFS(Network File System)
34 0
|
存储 网络协议 安全
Linux 在线/离线安装 NFS 服务及使用
-m 表示指定文件所在的文件系统或者块设备(处于 mount 状态)。所有访问该文件系统的进程都被列出。如上所示,有两个进程占用了,将其kill掉,再重新取消挂载。
2195 0
Linux 在线/离线安装 NFS 服务及使用
|
3月前
|
网络协议 Linux 测试技术
NFS - MIPS架构下构建NFS共享目录服务
NFS - MIPS架构下构建NFS共享目录服务
58 1
|
4月前
|
Ubuntu
百度搜索:蓝易云【Ubuntu 22.04上安装NFS服务教程。】
通过以上步骤,你可以在Ubuntu 22.04上安装和配置NFS服务,实现文件共享。确保在进行任何系统配置更改之前备份重要的数据,并在操作过程中小心谨慎,以免造成不必要的问题。
35 0
|
4月前
|
存储 网络协议 Linux
哇~真的是你呀!哎呀!今天是LINUX中的NFS存储服务
NFS(Network File System)是一种用于共享文件系统的协议,常用于Linux系统中。它允许在网络上共享文件和目录,使得多台计算机可以共享和访问相同的文件资源。以下是关于Linux中的NFS服务的简要介绍。
54 0
|
7月前
|
缓存 安全 网络协议
部署YUM仓库及NFS共享服务
部署YUM仓库及NFS共享服务
153 0
|
8月前
|
Kubernetes 网络协议 安全
NFS(Network File System) 服务安装部署配置
NFS(Network File System)是一种网络文件系统,主要具有以下特点: - 允许网络中的计算机之间通过TCP/IP网络共享文件。 - 可以透明地让不同操作系统的机器访问同一个文件系统。 - 用户可以像访问本地文件一样访问远程NFS服务器上的文件。 - NFS主要由两个组件构成:NFS服务器端与NFS客户端。 - 服务器端负责共享文件系统、控制权限,客户端负责访问服务器端的资源。 - 主要协议是NFSv3和NFSv4,基于RPC工作。 - 支持不同客户端并发访问、文件锁、权限控制等。 - 性能稳定,通常用于数据共享。
141 0
|
8月前
|
域名解析 运维 负载均衡
【运维知识进阶篇】Tomcat集群实战之部署zrlog博客(Tomcat服务安装+静态资源挂载NFS+Nginx负载均衡+HTTPS证书+Redis会话保持)
【运维知识进阶篇】Tomcat集群实战之部署zrlog博客(Tomcat服务安装+静态资源挂载NFS+Nginx负载均衡+HTTPS证书+Redis会话保持)
251 1
|
8月前
|
5G 内存技术
LVM逻辑卷以及配置NFS服务相关实验
LVM逻辑卷以及配置NFS服务相关实验