aws(学习笔记第十一课)
- 使用AWS的
EFS和AWSStorage Gateway
学习内容:
- 使用
AWS的EFS - 使用
AWS Storage Gateway
1. 使用AWS的EFS
- 什么是
EFS
EFS是Elastic File System的缩写。前面练习的实例存储和EBS都是同时只能一个EC2实例进行挂载,不能实现多个EC2实例的文件共享,使用EFS,能够实现多个EC2能够同时进行存储共享。另外,EFS也能够在应用程序不停止的情况下进行扩展容量,特别方便。
- 创建
EFS-
设定
EFS名称
在这里选择自定义,进行详细的设定。
-
设定
安全组
其实定义个EFS和自定义一个nfs server没有任何区别。所以需要设定安全组,这里设定default安全组,默认对全部IP进行开放。

-
选择
策略
可以设定策略,进行可以mount的EC2的限定,这里不进行设定。

-
EFS创建成功

-
开启
EC2进行mount

-
首先安装必要的
amzon-efs-utils客户端shellsudo yum install amazon-efs-utils
-
作成
mount point文件夹shellmkdir -p /mount/my-efs-dir -
执行
mount命令shellmount -t efs fs-0311ebd76cab0ba56 /mount/my-efs-dir
-
mount成功之后,进行文件作成shell[root@ip-172-31-1-63 my-efs-dir]# mkdir efs-test [root@ip-172-31-1-63 my-efs-dir]# cd efs-test/ [root@ip-172-31-1-63 efs-test]# touch hello.txt [root@ip-172-31-1-63 efs-test]# vim hello.txt [root@ip-172-31-1-63 efs-test]# cat hello.txt hello,efs; [root@ip-172-31-1-63 efs-test]# cat hello.txt hello,efs; -
之后作成第二个
EC2,再次mount

可以看到,这两个EC2看到的存储同一个EFS。
-
- 创建
2. 使用AWS Storage Gateway
AWS Storage Gateway 是一种混合云存储服务,可将本地环境与 AWS 云存储连接起来。它允许您将现有的本地基础设施与无缝集成 AWS,使您能够从云中存储和检索数据,并在混合环境中运行应用程序。换句话说,就是AWS Storage Gateway能提供各种AWS的storage向方便的接口协议,DAS、SAN、NAS(nfs,cifs),Samba(cifs)。个人感觉,AWS Storage Gateway就是AWS Storage到现有各种协议的适配器。
-
AWS Storage Gateway的分类-
Amazon S3文件网关这种网关支持
Amazon S3文件系统。是现有的协议DAS、SAN、NAS(nfs,cifs),Samba(cifs)能够访问Amazon S3。

-
卷网关
这种网关支持将
Amazon的卷存储,作为本地的iSCSI设备来访问。 -
磁带网关
这种网关支持将
Amazon的虚拟磁带存储。
-
-
创建
AWS Storage Gateway-
创建
AWS Storage Gateway
其实AWS也是创建EC2实例作为AWS Storage Gateway。

-
网关设定
这里让这个AWS Storage Gateway能够通过互联网访问AWS。

-
配置缓存存储

-
创建文件共享

-
选择
AWS Storage Gateway和共享协议
这里选择NFS,这个协议同样适合linux和windows系统。
同样选择现有的S3 bucket,或者新建的一个S3 bucket。
注意,新建的S3 bucket的权限设定会正确,既存的S3 bucket可能权限有问题

-
创建之后

-
这里会提供mount命令
shell#linux sudo mount -t nfs -o nolock,hard 172.31.1.85:/my-gateway-s3-20241109 [MountPath] #windows mount -o nolock -o mtype=hard 172.31.1.85:/my-gateway-s3-20241109 [WindowsDriveLetter]: #macos sudo mount -t nfs -o vers=3,rsize=1048576,wsize=1048576,hard, nolock -v 172.31.1.85:/my-gateway-s3-20241109 [MountPath]
-
-
创建
Windows EC2实例进行mount- 作成一个
windows实例
注意,使用t2.micro的话,启动windows server 2022会特别慢,所以选择t2.medium,使用后马上关闭 - 进入Windows之后,删除
alias以及安装NFS-client-
进入
PowerShell -
删除
aliasRemove-Item -Path Alias:mount -ErrorAction Ignore -
安装
NFS-clientshellGet-WindowsFeature NFS-Client Install-WindowsFeature -Name NFS-Client -
执行
mountshellmount -o nolock -o mtype=hard 172.31.1.85:/my-gateway-s3-20241109 d:
-
- 作成一个
-
mount成功

- 创建文件夹和文件

- 查看
S3 bucket
这样,使用NFS协议,实现了从windows上mountS3 bucket,方便进行读写。

- 最后清理资源
- 创建文件夹和文件