nfs服务
网络文件系统,英文Network File System(NFS),是由SUN公司研制的UNIX表示层协议(presentation layerprotocol),能使使用者访问网络上别处的文件就像在使用自己的计算机一样。
不同的机器之间通过网络实现文件共享
NFS自己并没有对外监听的端口号,而是外包给RPC服务
为什么需要nfs服务器?
保障网站数据的一致性–》不管负载均衡器将请求分配到那台后端的服务器,客户机看到的内容是一样。
nfs是比较廉价的解决方法,一般的公司不会采用,性能不是特别棒,建议使用专用的存储服务器。
nfs解决了什么问题?
数据同源: 到同一个地方去拿数据,保障数据的一致性
nfs的优点和缺点
优点: 随便一台linux服务器都可以搭建,成本非常低,构建非常容易
缺点: 读取速度有限,跟网络质量,磁盘IO,cpu,内存等因素有关,在传统的tcp/ip网络上传输的
SAN
存储区域网络(Storage Area Network,简称SAN)采用网状通道(Fibre Channel ,简称FC,区别与Fiber Channel光纤通道)技术,通过FC交换机连接存储阵列和服务器主机,建立专用于数据存储的区域网络。
设备:
1、专业的存储服务器 --》有很多块磁盘,总容量非常大
2、专业的光纤交换机
3、专业服务器:例如web服务器或者数据库服务器等,业务服务器通过HBA卡设备与光纤连接到光纤交换机
搭建过程
1、安装nfs
[root@localhost ~]# yum install nfs-utils -y
2、启动nfs服务
[root@localhost ~]# service nfs restart
Redirecting to /bin/systemctl restart nfs.service
[root@localhost ~]#
[root@localhost ~]# ps aux|grep nfs
root 27045 0.0 0.0 0 0 ? S< 10:24 0:00 [nfsd4_callbacks]
root 27053 0.0 0.0 0 0 ? S 10:24 0:00 [nfsd]
root 27054 0.0 0.0 0 0 ? S 10:24 0:00 [nfsd]
root 27055 0.0 0.0 0 0 ? S 10:24 0:00 [nfsd]
root 27056 0.0 0.0 0 0 ? S 10:24 0:00 [nfsd]
root 27057 0.0 0.0 0 0 ? S 10:24 0:00 [nfsd]
root 27058 0.0 0.0 0 0 ? S 10:24 0:00 [nfsd]
root 27059 0.0 0.0 0 0 ? S 10:24 0:00 [nfsd]
root 27060 0.0 0.0 0 0 ? S 10:24 0:00 [nfsd]
root 27076 0.0 0.0 112824 988 pts/0 S+ 10:25 0:00 grep --color=auto nfs
您在 /var/spool/mail/root 中有新邮件
[root@localhost ~]#
3、编辑共享文件的配置文件
[root@localhost ~]# vim /etc/exports
/web 192.168.152.0/24(rw,all_squash,sync)
/web 是我们共享的文件夹的路径–》使用绝对路径 --》需要自己新建
权限:
共享权限 --》看/etc/eports里的 ro还是rw
Linux里的文件夹权限192.168.152.0/24 允许过来访问的客户机的ip地址网段
(rw,all_squash,sync) 表示权限的限制
rw 表示可读可写 read and write
ro 表示只能读 read-only
all_squash :任何客户机上的用户过来访问的时候,都把它认为是普通的用户
root_squash 当NFS客户端以root管理员访问时,映射为NFS服务器匿名用户
no_root_squash 当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员
sync 同时将数据写入到内存与硬盘中,保证不丢失数据
async 优先将数据保存到内存,然后再写入硬盘,效率更高,但可能丢失数据
4、创建共享文件夹
[root@localhost ~]# mkdir /web
[root@localhost ~]# cd /web/
[root@localhost web]# ls
[root@localhost web]# vim /etc/exports
[root@localhost web]# mkdir sanchuang
[root@localhost web]# ls
sanchuang
[root@localhost web]#
[root@localhost web]# vim index.html
[root@localhost web]# ls
index.html sanchuang
[root@localhost web]#
5、刷新服务
[root@localhost web]# service nfs restart
Redirecting to /bin/systemctl restart nfs.service
[root@localhost web]#
[root@localhost web]# exportfs -rv
exporting 192.168.152.0/24:/web
6、关闭防火墙
[root@localhost web]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
7、在其它web服务器上挂在使用共享目录
[root@web1 ~]# yum install nfs-utils -y
[root@web1 ~]# cd /usr/local/nginx99/html/
[root@web1 html]# ls
50x.html index.html
[root@web1 html]# mount 192.168.152.142:/web /usr/local/nginx99/html/
[root@web1 html]# ls
50x.html index.html
[root@web1 html]# df
文件系统 1K-块 已用 可用 已用% 挂载点
devtmpfs 919576 0 919576 0% /dev
tmpfs 931496 0 931496 0% /dev/shm
tmpfs 931496 58960 872536 7% /run
tmpfs 931496 0 931496 0% /sys/fs/cgroup
/dev/mapper/centos-root 17811456 12565196 5246260 71% /
/dev/sda1 1038336 186496 851840 18% /boot
tmpfs 186300 0 186300 0% /run/user/0
192.168.152.142:/web 17811456 5294336 12517120 30% /usr/local/nginx99/html
[root@web1 html]#
[root@web1 /]# cd /usr/local/nginx99/html/
[root@web1 html]# ls
index.html sanchuang
[root@web1 html]#