NFS应用场景是:A,B,C三台机器上需要保证被访问到的文件是一样的,A共享数据出来,B和C分别去挂载A共享的数据目录,从而B和C访问到的数据和A上的一致性

172.131.1.135  服务器端

172.131.1.137  客户端端

1.服务器安装

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

查看端口:

root@localhost]# netstat -lntp

[root@localhost ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 1783/rpc.mountd
tcp 0 0 0.0.0.0:34099 0.0.0.0:* LISTEN -
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2263/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1344/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 841/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2041/master
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:40037 0.0.0.0:* LISTEN 1216/rpc.statd
tcp6 0 0 :::60943 :::* LISTEN 1216/rpc.statd
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::20048 :::* LISTEN 1783/rpc.mountd
tcp6 0 0 :::22 :::* LISTEN 1344/sshd
tcp6 0 0 ::1:631 :::* LISTEN 841/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 2041/master
tcp6 0 0 :::40826 :::* LISTEN -
tcp6 0 0 :::2049 :::* LISTEN -

启动nfs服务

[root@localhost ]# systemctl start nfs

root@localhost ~]# systemctl status nfs

nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
Drop-In: /run/systemd/generator/nfs-server.service.d
└─order-with-mounts.conf
Active: active (exited) since 四 2017-11-16 15:22:31 CST; 18min ago

[root@localhost ~]# ps -ef|grep nfs
root 1874 2 0 15:22 ? 00:00:00 [nfsd4_callbacks]
root 1890 2 0 15:22 ? 00:00:00 [nfsd]
root 1891 2 0 15:22 ? 00:00:00 [nfsd]
root 1892 2 0 15:22 ? 00:00:00 [nfsd]
root 1893 2 0 15:22 ? 00:00:00 [nfsd]
root 1894 2 0 15:22 ? 00:00:00 [nfsd]
root 1895 2 0 15:22 ? 00:00:00 [nfsd]
root 1896 2 0 15:22 ? 00:00:00 [nfsd]
root 1897 2 0 15:22 ? 00:00:00 [nfsd]

[root@iZbp1a7wyzv7b3ujsfphj2Z nfsdir]# netstat -lntp

[root@localhost ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 1783/rpc.mountd
tcp 0 0 0.0.0.0:34099 0.0.0.0:* LISTEN -
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2263/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1344/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 841/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2041/master
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:40037 0.0.0.0:* LISTEN 1216/rpc.statd
tcp6 0 0 :::60943 :::* LISTEN 1216/rpc.statd
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::20048 :::* LISTEN 1783/rpc.mountd
tcp6 0 0 :::22 :::* LISTEN 1344/sshd
tcp6 0 0 ::1:631 :::* LISTEN 841/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 2041/master
tcp6 0 0 :::40826 :::* LISTEN -
tcp6 0 0 :::2049 :::* LISTEN -

rpc的服务也跟着带起来:

[root@localhost ~]# ps -aux|grep rpc
root 397 0.0 0.0 0 0 ? S< 15:22 0:00 [rpciod]
root 540 0.0 0.0 17148 392 ? Ss 15:22 0:00 /usr/sbin/rpc.idmapd
rpcuser 1216 0.0 0.0 44448 1824 ? Ss 15:22 0:00 /usr/sbin/rpc.statd
rpc 1695 0.0 0.0 64948 1436 ? Ss 15:22 0:00 /sbin/rpcbind -w
root 1783 0.0 0.1 42992 2124 ? Ss 15:22 0:00 /usr/sbin/rpc.mountd
root 4011 0.0 0.0 112668 972 pts/0 R+ 15:42 0:00 grep --color=auto rpc

开机自启动:

[root@localhost nfsdir]# systemctl enable rpcbind
[root@localhost  nfsdir]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.

准备共享的文件夹

root@localhost nfsdir]# chmod 777 /nfs/nfsdir

最关键的就是修改nfs的配置文件:

[root@localhost ~]# cat /etc/exports
/nfs/nfsdir 172.31.1.0/24(rw,sync,no_root_squash)

相关参数:

rw 读写
ro 只读
sync 同步模式,内存数据实时写入磁盘  速度很快但是会降低磁盘效率
async 非同步模式 能保证磁盘效率  但是如果服务器断电,会造成数据丢失
no_root_squash 客户端挂载NFS共享目录后,root用户不受约束,权限很大
root_squash 与上面选项相对,客户端上的root用户收到约束,被限定成某个普通用户
all_squash 客户端上所有用户在使用NFS共享目录时都被限定为一个普通用户
anonuid/anongid 和上面几个选项搭配使用,定义被限定用户的uid和gid

2.NFS服务器端的配置:

[root@localhost~]# yum install nfs-utils
[root@localhost~]# systemctl start rpcbind
[root@localhost~]# systemctl status rpcbind
rpcbind.service - RPC bind service
Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; indirect; vendor preset: enabled)
Active: active (running) since 四 2017-11-16 13:24:06 CST; 5s ago

[root@localhost python_practice]# showmount -e 172.31.1.135

clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
这是因为开启了防火墙
[root@localhost python_practice]# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 二 2017-09-26 21:42:06 CST; 1 months 20 days ago
root@localhost python_practice]# systemctl stop firewalld
需要关闭两边的防火墙和getenforce
[root@localhost python_practice]# getenforce
Enforcing
[root@localhost python_practice]# setenforce 0
[root@localhost python_practice]# getenforce
Permissive

[root@localhost python_practice]# showmount -e 172.131.1.135
clnt_create: RPC: Port mapper failure - Timed out
原因是2台机器都叫默认名localhost.localhost
修改2台服务器的名:
[root@localhost ~]# hostnamectl set-hostname "centos7-137"
另外一台是类似的命令

再进行查看:

oot@localhost nfsdir]# showmount -e 172.31.1.135
Export list for 172.31.1.135:
/nfs/nfsdir 172.31.1.0/24

最关键的是这一步:
[root@localhost nfsdir]# mount -t nfs 172.31.1.135:/nfs/nfsdir /pubdir/nfsdir

其中/nfs/nfsdir是135准备共享的目录,/pubdir/nfsdir是137上对应查看的目录
[root@localhost nfsdir]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 38G 5.9G 32G 16% /
devtmpfs 898M 0 898M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 9.0M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 197M 156M 41M 80% /boot
tmpfs 183M 24K 183M 1% /run/user/0
/dev/sr0 4.1G 4.1G 0 100% /run/media/root/CentOS 7 x86_64
172.31.1.135:/nfs/nfsdir 38G 13G 25G 35% /pubdir/nfsdir

测试:

在135上新建一个文件:

[root@localhost nfsdir]# touch kingleoric.txt
[root@localhost nfsdir]# pwd
/nfs/nfsdir

在137上查看该文件已生成:

[root@localhost nfsdir]# cd /pubdir/nfsdir
[root@localhost nfsdir]# ls
kingleoric.txt

NFS搭建与配置的更多相关文章

  1. Liunx下NFS服务器的搭建与配置

    一.NFS简介 NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中,本地NF ...

  2. nfs搭建;nfs监控;mount对于nfs的相应配置

    nfs搭建 https://www.cnblogs.com/lms0755/p/9211585.html https://www.jianshu.com/p/e47cccbb3ae5 https:// ...

  3. 12.NFS搭建配置

    参考博客:http://www.cnblogs.com/mchina/archive/2013/01/03/2840040.html 1.关闭防火墙和SELINUX $ service iptable ...

  4. Linux下NFS的搭建与配置

    一.简介 1.NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Sun公司开发,于1984年向外公布. 2.NFS可实现Linux系统之间的文件 ...

  5. NFS服务器搭建与配置

    原文:https://blog.csdn.net/qq_38265137/article/details/83146421 NFS服务简介什么是NFS?NFS就是Network File System ...

  6. Ubuntu 16.04下Samba服务器搭建和配置(配截图)

    一.相关介绍 Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成.SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和 ...

  7. 基于 NFS 搭建便捷远程硬盘

    基于 NFS 搭建便捷远程硬盘 知识准备: 一.NFS服务简介 NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Sun公司开发,于1984年向 ...

  8. 总结:Mac前端开发环境的搭建(配置)

    新年新气象,在2016年的第一天,我入手了人生中第一台自己的电脑(大一时好友赠送的电脑在一次无意中烧坏了主板,此后便不断借用别人的或者网站的).macbook air,身上已无分文...接下来半年的房 ...

  9. Hadoop学习笔记—22.Hadoop2.x环境搭建与配置

    自从2015年花了2个多月时间把Hadoop1.x的学习教程学习了一遍,对Hadoop这个神奇的小象有了一个初步的了解,还对每次学习的内容进行了总结,也形成了我的一个博文系列<Hadoop学习笔 ...

随机推荐

  1. 转:聊聊Greenplum的那些事

    笔者有幸从04年就开始从事大规模数据计算的相关工作,08年作为Greenplum 早期员工加入Greenplum团队(当时的工牌是“005”,哈哈),记得当时看了一眼Greenplum的架构(嗯,就是 ...

  2. FreeMarker初探--安装FreeMarker

    这里安装FreeMarker相当简单,不需要真正的安装过程.仅仅是拷贝 lib/freemarker.jar 到你 Java 应用程序的路径中,让类加载器可以发现它.比如,如果你在 Web 使用了 F ...

  3. Quartz教程一:使用quartz

    原文链接 | 译文链接 | 翻译:nkcoder | 校对:方腾飞 本系列教程由quartz-2.2.x官方文档翻译.整理而来,希望给同样对quartz感兴趣的朋友一些参考和帮助,有任何不当或错误之处 ...

  4. C/C++文件指针偏移

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  5. PHP 中使用explode()函数切割字符串为数组

    explode()函数的作用:使用一个字符串分割另一个字符串,打散为数组. 例如: 字符串 $pizza = "第1 第2 第3 第4 第5 第6"; 根据空格分割后:$piece ...

  6. OC-NSString

    ========================== 面向对象编程进阶和字符串 ========================== Δ一.类的设计模式—单例 [单例]程序允许过程中,有且仅有一块内存 ...

  7. Python基础学习----字典常用操作

    字典的常见操作: # 字典: # 格式:{键值对,键值对} dict_demo={"name":"bai-boy","age":17} # ...

  8. 20165202 week4课下补做

    1.相关知识点的总结 编程实现1!+2!+3!+... + N!的功能,N由命令行传入,比如类名为SumofRecur, java SumofRecur 8 给出1!+2!+3!+... + 8!的值 ...

  9. 2018.11 企业战略课堂笔记2 SWOT-4C战略

    1因素列表 2分析过程 :重要的是逻辑推理过程 3  4C战略

  10. CMD命令提示符下选中文字即可以复制和SecureCRT一样

    用过 SecureCRT 的都会觉得复制粘贴很方便.只要选中相应文字,会自动复制.然后点鼠标右键就可以粘贴,非常方便. 但是在windows系统下的CMD里面,每次都要点鼠标右键→标记,再选中相应文字 ...