1. What is NFS?
Network file system 网络文件系统 nfs共享存储
2.nfs can you do?
nfs 能为 不同主机系统之间 实现 文件的共享
3. Why should I use nfs?
在集群架构中使用
4.nfs can solve any problem?
1.解决多台机器静态资源一致性问题
2.解决多态机器资源共享
3.解决磁盘空间浪费的问题
5. Note the use of nfs?
1.添加共享存储,只会带来网站的访问延时和消耗,并不会增加网站访问的速度.
2.CDN---->(了解即可)
1.购买厂商CDN ---> 用户请求img--->CDN--->负载均衡-->Web-->存储-->CDN缓存该图片
2.所有的web都是用共享存储,图片此时一致, 只需要将图片定期的推送至CDN
Principle 6.nfs achieve resolution?
本地文件操作方式:
1.当用户执行mkdir命令,BashShell无法完成该命令操作,会将其翻译给内核。
2.Kernel内核解析完成后会驱动对应的磁盘设备,完成创建目录的操作。
The principle == == NFS
1.NFS客户端执行增、删等操作,客户端会使用不同的函数对该操作进行封装。(windows linux mac)
2.NFS客户端会通过TCP/IP的方式传递给NFS服务端。(可靠)
3.NFS服务端接收到请求后,会先调用portmap进程进行端口映射。
4.nfsd进程用于判断NFS客户端是否拥有权限连接NFS服务端。
5.Rpc.mount进程判断客户端是否有对应的权限进行验证。读 写
6.idmap进程实现用户映射和压缩。
7.最后NFS服务端会将客户端的函数转换为本地能执行的命令,然后将命令传递至内核,由内核驱动硬件。
注意: rpc是一个远程过程调用,那么使用nfs必须有rpcbind服务
7. Install, configure, nfs service
1.安装
[root@nfs ~]# yum install nfs-utils -y
2.配置
1.共享什么目录?
2.共享给谁使用?
3.共享后目录,客户端拥有什么权限?
[root@nfs ~]# cat /etc/exports
/data 172.16.1.0/24(rw)
3.根据配置进行初始化环境
[root@nfs ~]# mkdir /data
[root@nfs ~]# chown -R nfsnobody.nfsnobody /data/
4.启动
[root@nfs ~]# systemctl enable nfs
[root@nfs ~]# systemctl start nfs
5.客户端测试
[root@backup ~]# yum install nfs-utils -y
[root@backup ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24
挂载远程172.16.1.31的/data至本地的/mnt目录
[root@backup ~]# mount -t nfs 172.16.1.31:/data /mnt
6.错误的示范
#访问被拒绝 (没有允许该网段访问)
[root@backup ~]# mount -t nfs 10.0.0.31:/data /media/
mount.nfs: access denied by server while mounting 10.0.0.31:/data
#能够连接,但是权限被拒绝
[root@backup mnt]# touch file
touch: cannot touch ‘file’: Permission denied
7.多个客户端共享一个存储服务器 (NFS)
8.实现开机自动挂载(因为服务器不重启) 扩展了解即可
[root@web01 ~]# cat /etc/fstab
172.16.1.31:/data /media nfs defaults 0 0
PS: 如果nfs服务端出现问题: 客户端重启则会无法启动成功
1.等待1分38s 自动进入系统
2.进入单用户模式,注释开机自启动nfs
3.将nfs恢复正常
9.nfs relevant configuration parameters
nfs share Parameters role
rw * read and write permissions (up to)
RO read-only privileges (only willing to look, do not want to write)
root_squash when the NFS client access to the root administrator, mapped to the anonymous user nfsnobody NFS server (not used)
no_root_squash when NFS clients to access when the root administrator, is mapped to the root administrator of the NFS server (not used)
no_all_squash no matter what NFS client account access, not user compression (talk behind cloud computing courses will spend)
all_squash no matter what NFS client account access, NFS servers are mapped to anonymous user (common)
Sync * simultaneously writing data to the memory and hard drive to ensure that no data is lost
async priority to save the data to memory, and then written to disk ; so that a higher efficiency, but may lose data
anonuid * configuration all_squash use NFS to specify the user UID, the system must exist
anongid * configuration all_squash use NFS to specify the user UID, the system must exist
1.rw 和 ro
[root@nfs ~]# cat /etc/exports
/data 172.16.1.0/24(ro)
[root@nfs ~]# systemctl restart nfs
#提示,该目录是一个只读文件
[root@web01 media]# touch file
touch: cannot touch ‘file’: Read-only file system
2.验证all_squash anonuid anongid
[root@nfs ~]# cat /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
1.创建系统真实用户,指定uid和gid为666
[root@nfs ~]# groupadd -g 666 www
[root@nfs ~]# useradd -u666 -g666 www
[root@nfs ~]# id www
uid=666(www) gid=666(www) groups=666(www)
2.变更属主和属组
[root@nfs ~]# chown -R www.www /data/
3.重启nfs
[root@nfs ~]# systemctl restart nfs
4.客户端使用(一定要与服务端使用的匿名用户一致)
[root@web01 ~]# groupadd -g 666 www
[root@web01 ~]# useradd -u666 -g666 www
[root@web01 ~]# mount -t nfs 172.16.1.31:/data/ /media/
10.nfs如何共享多个目录?
[root@nfs ~]# cat /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
/data_2 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
== 1.NFS storage advantages ==
** 1. NFS easy to use, easy to deploy, reliable data, services and stability, to meet the needs of SMEs.
- NFS data are on file system, all data can be visible.
In addition to NFS: (Glusterfs distributed gift) MooseFS FastDFS **
== 2.NFS storage limitations ==
** 1. Single point of failure, NFS itself does not support high availability, does not support clusters.
- NFS data are expressly does not do any checking of data, there is no password authentication (internal network use is strongly recommended). **
== == 3.NFS application recommendations
** 1. Production scene should be static data (jpg \ png \ mp4 \ avias possible to the scene CDN environment, in order to reduce the pressure of back-end storage
If there is no cache or architecture, code, etc., problems left over by history itself is too large, multi-store no meaning **
PS: NFS is used to share nothing else all static CDN are provided access.
== NFS combat: ==
环境准备:
服务器系统 角色 IP
CentOS 7.6 NfsServer(A) 172.16.1.31
CentOS 7.6 NfsClient(B) 172.16.1.41
CentOS 7.6 NfsClient(C) 172.16.1.7
准备3台虚拟机服务器,并且请按照要求搭建配置NFS服务。
NFS服务端(A)
NFS客户端(B)
NFS客户端(C)
1.在NFS服务端(A)上共享/data/w(可写) 及/data/r(只读)
2.在NFS客户端(B/C)上进行挂载
== server A: ==
1. 安装nfs-utils
[root@nfs ~]# yum install nfs-utils -y
2. 配置exports
[root@nfs ~]# cat /etc/exports
/data/r 172.16.1.0/24(ro,sync,all_squash,anonuid=666,anongid=666)
/data/w 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
3. 根据配置进行初始化环境
[root@nfs ~]# groupadd -g 666 www
[root@nfs ~]# useradd -u666 -g666 www
[root@nfs ~]# mkdir /data/{r,w} -p
[root@nfs ~]# chown -R www.www /data/
4.重启nfs服务
[root@nfs ~]# systemctl restart nfs
== Client B: ==
1. 卸载之前遗留的挂载信息
[root@web01 ~]# umount -lf 172.16.1.31:/data
[root@web01 ~]# umount -lf 172.16.1.31:/data_2
2. 挂载
[root@web01 ~]# mount -t nfs 172.16.1.31:/data/r /mnt
[root@web01 ~]# mount -t nfs 172.16.1.31:/data/w /media/
== Summary: ==
1.什么是NFS?
网络文件系统
2.NFS主要实现的功能?
让不同主机之间能共享目录
https://blog.csdn.net/wykkunkun/article/details/79638288
3.NFS到底有什么用?
日常 没用
网站架构 有用?
没有共享前有什么问题?
共享后解决了什么问题?
1.一致性
2.减少磁盘空间
4.NFS实现共享原理?
5.NFS 安装 配置 使用?
6.客户端挂载?
showmount
mount
df -h
/etc/fstab
6.多个客户端如何进行NFS的挂载?
测试多个客户端数据是否一致
7.NFS相关参数?
rw
all_squash
anonuid
anongid
sync
8.NFS服务端如何共享多个目录
9.NFS使用建议 CDN -->CNAME