NFS 网络存储
NFS简介
1 2 3 4 5 6 7 8 9 10 11
| NFS : 共享存储,文件服务器
基本概述: 1.NFS是Network File System的缩写及网络文件系统。NFS主要功能是通过局域网络让不同的主机系统之间可以共享文件或目录。
2.NFS系统和Windows网络共享、网络驱动器类似, 只不过windows用于局域网, NFS用于企业集群架构中, 如果是大型网站, 会用到更复杂的分布式文件系统FastDFS,glusterfs,HDFS,ceph
为何使用NFS: 1.实现多台服务器之间数据共享 2.实现多台服务器之间数据一致
|

NFS应用
1 2 3 4 5 6
| 1.用户访问NFS客户端,将请求转化为函数 2.NFS通过TCP/IP连接服务端 3.NFS服务端接收请求,会先调用portmap进程进行端口映射 4.Rpc.nfsd进程用于判断NFS客户端能否连接服务端; 5.Rpc.mount进程用于判断客户端对服务端的操作权限 6.如果通过权限验证,可以对服务端进行操作,修改或读取
|
nfs运行原理

NFS实践
nfs原理

1、服务端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| 1、安装NFS和rpcbind [root@nfs ~]
2、创建挂载点 [root@nfs ~]
3、配置挂载点 [root@nfs ~] 格式: [挂载点] [可以访问的IP]([权限]) /web/nfs1 172.16.1.0/20(rw,sync,all_squash)
4、关闭selinux和防火墙 [root@nfs ~] [root@nfs ~]
5、启动nfs和rpcbind服务 [root@nfs ~] [root@nfs ~]
6、检查服务端是否正常 [root@nfs ~]
[root@nfs ~] Export list for nfs: /web/nfsv1 172.16.1.0/20 [root@nfs ~] Export list for 172.16.1.31: /web/nfsv1 172.16.1.0/20
[root@nfs ~]
7、给挂载点授权 [root@nfs ~]
|
2、客户端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| 1、安装NFS [root@web01 opt]
2、创建目录 [root@web01 opt]
3、挂载NFS [root@web01 opt]
4、测试NFS文件同步功能 [root@web opt] [root@web opt] 总用量 0 -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 2021 1.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 2021 2.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 2021 3.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 2021 4.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 2021 5.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 2021 6.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 2021 7.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 2021 8.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 2021 9.txt
[root@nfs ~] 总用量 0 -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 22:02 1.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 22:02 2.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 22:02 3.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 22:02 4.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 22:02 5.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 22:02 6.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 22:02 7.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 22:02 8.txt -rw-r--r-- 1 nfsnobody nfsnobody 0 12月 30 22:02 9.txt
|
NFS配置详解
nfs共享参数 |
参数作用 |
rw |
读写权限 (常用) |
ro |
只读权限 (不常用) |
root_squash |
当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户 (不常用) |
no_root_squash |
当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员 (不常用) |
all_squash |
无论NFS客户端使用什么账户访问,均映射为NFS服务器的匿名用户 (常用) |
no_all_squash |
无论NFS客户端使用什么账户访问,都不进行压缩 (不常用) |
sync |
同时将数据写入到内存与硬盘中,保证不丢失数据 (常用) |
async |
优先将数据保存到内存,然后再写入硬盘;这样效率更高,但可能会丢失数据 (不常用) |
anonuid |
配置all_squash使用,指定NFS的用户UID,必须存在系统 (常用) |
anongid |
配置all_squash使用,指定NFS的用户GID,必须存在系统 (常用) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| 1、控制读写 rw ro
2、控制文件权限 root_squash no_root_squash all_squash no_all_squash
3、控制写模式 sync async
4、控制用户 anonuid anongid
统一用户:
1、创建用户 [root@nfs nfs1] [root@nfs nfs1]
2、修改配置挂载点 [root@nfs nfs1] /web/nfs1 172.16.1.0/20(rw,sync,all_squash,anonuid=666,anongid=666)
[root@nfs nfs1] 3、修改挂载点权限 [root@nfs nfs1]
3、使用
[root@nfs nfs1] [root@nfs nfs1]
[root@nfs nfs1]
[root@nfs nfs1]
|
搭建考试系统
1、搭建WEB服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| 1、安装web软件 [root@web01 opt]
2、将代码放置于网站的根目录 [root@web01 opt]
3、授权 [root@web01 html]
4、关闭selinux和防火墙 [root@nfs ~] [root@nfs ~]
5、修改web软件的用户 [root@web01 html] User www Group www
6、启动web软件 [root@web01 html]
7、测试
1、上传 2、访问 http://172.16.1.7/upload/1_linux.jpg
|
2、配合NFS实现文件共享
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| 1、修改NFS配置文件 [root@nfs nfs1] /web/upload 172.16.1.0/20(rw,sync,all_squash,anonuid=666,anongid=666)
2、创建挂载点 [root@nfs nfs1] [root@nfs nfs1]
3、重启NFS [root@nfs nfs1]
4、客户端安装NFS软件 [root@web01 html] [root@web02 html] [root@web03 html]
5、挂载 [root@web01 html] [root@web02 html] [root@web03 html]
6、测试
sed -i 's/.100/$1/g' /etc/sysconfig/network-scripts/ifcfg-eth[10] hostnamectl set-hostname $2 systemctl restart network
|