ECS:如何使用“s3curl.pl”脚本执行基本 S3作
Summary: 如何使用“s3curl”脚本在 ECS 3.x 上执行基本 s3作。
This article applies to
This article does not apply to
This article is not tied to any specific product.
Not all product versions are identified in this article.
Instructions
配置步骤
收集以下信息以便配置
s3curl.pl:
- 您正在调查的存储区的对象用户:
- 登录 UI>管理>存储区> **选择命名空间**> 记下存储区的所有者列。
- 对象用户的共享密码:
- 登录 UI>管理>用户>**编辑 ** 上面 > 的用户 记下用户的共享密码。
- ECS 节点数据 IP 地址或公用 IP 地址:
- 登录到 ECS CLI 并运行
getrackinfo -n
- 登录到 ECS CLI 并运行
如果客户端具有网络分离,则在上述命令中会看到 数据 的 IP 和 repl 。记下节点的数据 IP。
示例:
Node ID Network Ip Address Netmask Gateway VLAN 5 repl 10.###.##.##4 255.255.252.0 - - 5 data 10.###.##.##2 255.255.252.0 -
如果没有网络分离,请从以下位置获取节点的公共 IP 地址
getrackinfo:
示例:
provo:/usr/share/s3curl # getrackinfo Node private Node Public RMM Ip Address Id Status Mac Ip Address Mac Ip Address Node Name =============== ====== ====== ================= ================= ================= ================= ========= 192.###.###.1 1 MA 00:1e:67:f1:85:10 10.##.##.##7 00:1e:67:bc:c5:53 10.##.##.##3 provo-red 192.###.###.2 2 SA 00:1e:67:ab:e6:d8 10.##.##.##8 00:1e:67:6a:08:8c 10.##.##.##4 sandy-red
步骤:
- 转至目录
/usr/share/s3curl,然后检查以下文件。
provo:/usr/share/s3curl # provo:/usr/share/s3curl # ls -lrt .s3curl -rw------- 1 root root 2095 Mar 6 16:14 .s3curl
- 如果文件不存在,请使用以下内容创建该文件。["
sample_user“。
@endpoints = ECS data / public ip address gotten above.
%awsSecretAccessKeys = (
sample_user => {
id => '<Object User>',
key => '<Shared Secret>',
},
@endpoints = ('<node1_ip>','<node2_ip>','<node3_ip>','<node4_ip>',)
);
- 您可以将多个用户添加到此文件,如下所示。
%awsSecretAccessKeys = (
<sample_user> => {
id => '<object user>',
key => '<Shared Secret>',
},
<sample_user2> => {
id => '<object user>',
key => '<Shared Secret>',
},
@endpoints = ('<node1_ip>','<node2_ip>','<node3_ip>','<node4_ip>',)
);
- 更改文件的权限。
# sudo chmod 755 s3curl.pl # sudo chmod 600 .s3curl
使用 s3curl.pl 配置后
- 测试用户身份验证并列出该用户拥有的存储区。”
bucket_1“是存储区的名称。
--id= 前面在.s3curl文件”sample_user”9020= 用于连接到 S3 的 TCP 端口
# provo:/usr/share/s3curl # perl s3curl.pl --id <user ID> -- http://<hostname or IP>:9020 | xmllint --format -
provo:/usr/share/s3curl # perl s3curl.pl --id sample_user -- http://10.##.##.##7:9020 | xmllint --format -
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 421 100 421 0 0 21803 0 --:--:-- --:--:-- --:--:-- 22157
<?xml version="1.0" encloding="UTF-8" standalone="yes"?>
<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01">
<Owner>
<ID>sample_user</ID>
<DisplayName>sample_user</DisplayName>
</Owner>
<Buckets>
<Bucket>
<Name>bucket_1</Name>
<CreationDate>2017-02-21T08:32:05.651Z</CreationDate>
<ServerSideEncryptionEnabled>false</ServerSideEncryptionEnabled>
</Bucket>
</Buckets>
<IsTruncated>false</IsTruncated>
</ListAllMyBucketsResult>
- 列出特定存储区的内容。
- S3 中的键是指文件。
提醒:S3 具有扁平的文件结构,目录不存在。
s3curl.pl仅显示目录中的前 1000 个文件。
# perl s3curl.pl --id <user id> -- http://<hostname or IP>:9020/<bucket> | xmllint --format - | grep Key
provo:/usr/share/s3curl # perl s3curl.pl --id sample_user -- http://10.##.##.##7:9020/bucket_1 | xmllint --format - | grep Key
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1128 100 1128 0 0 29386 0 --:--:-- --:--:-- --:--:-- 29684
<MaxKeys>1000</MaxKeys>
<Key>2017 - emea schedule obj storage.xlsx</Key>
<Key>_$folder$</Key>
<Key>dir1/dir2/dir3/test_new_name.txt</Key>
- 在存储区中搜索特定密钥或文件。
- 知道文件名的开头后,使用前缀搜索方法搜索特定文件。
- 在存储区名称后插入方法”
?prefix=<search_string>”
# perl s3curl.pl --id <user id> -- http://<hostname or IP>:9020/<bucket>?prefix=dir1/dir2/ | xmllint --format - | grep Key
provo:/usr/share/s3curl # perl s3curl.pl --id smaple_user -- http://10.##.##.##7:9020/bucket_1?prefix=dir1/dir2/ | xmllint --format - | grep Key
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 599 100 599 0 0 20309 0 --:--:-- --:--:-- --:--:-- 19966
<MaxKeys>1000</MaxKeys>
<Key>dir1/dir2/dir3/test_new_name.txt</Key>
- 读取存储区中的特定密钥或文件。
提醒:如果键或存储区的名称中包含空格,请使用字符串”
%20“,同时在 URL 中查询。
provo:/usr/share/s3curl # cat test1.txt Goodbye World provo:/usr/share/s3curl # perl s3curl.pl --id smaple_user -- http://10.##.##.##7:9020/bucket_1/dir1/dir2/dir3/test_new_name.txt Goodbye World
- 将特定密钥或文件写入存储桶。
provo:/usr/share/s3curl # cat test1.txt Goodbye World provo:/usr/share/s3curl # perl s3curl.pl --id smaple_user --put=test1.txt http://10.##.##.##7:9020/bucket_1/dir1/dir2/dir3/test_new_name.txt
- 读取存储区中特定密钥或文件的元数据。
HTTP/1.1 200 OK--> 请求的特定 HTTP 响应x-amz-request-id-->request_id可以在 ECS 日志中跟踪ETag--> 文件的 MD5SUMContent-Length--> 对象的大小或字节数
# perl s3curl.pl --id <user ID> --head http://<hostname or IP>:9020/<bucket>/<path1>/<path2>/<object>
provo:/usr/share/s3curl # perl s3curl.pl --id sample_user --head http://10.##.##.##7:9020/bucket_1/dir1/dir2/dir3/test_new_name.txt HTTP/1.1 200 OK Date: Wed, 08 Mar 2017 16:25:52 GMT Server: ViPR/1.0 x-amz-request-id: 0a3c23ed:15aa813368d:10e1:1 x-amz-id-2: 83769c2fcf5f8907b60b588a251bcc492d86d5829dfc2c8bee2504f0c527f256 ETag: "54aea9f06281a5df11d06f105c6fb039" Last-Modified: Wed, 08 Mar 2017 16:08:02 GMT x-emc-mtime: 1488989282859 Content-Encoding: identity Content-Type: application/octet-stream Content-Length: 14
- 要为用户创建新存储区,请执行以下作:
# perl s3curl.pl --id <user ID> --createBucket -- http://<hostname or IP>:9020/<new bucket name>
provo:/usr/share/s3curl # perl s3curl.pl --id sample_user --createBucket -- http://10.##.##.##7:9020/new_bucket_name New Bucket can be seen below. # provo:/usr/share/s3curl # perl s3curl.pl --id <user> -- http:/<hostname or IP>:9020 | xmllint --format - | grep -A1 '<Bucket>'
provo:/usr/share/s3curl # perl s3curl.pl --id sample_user -- http://10.##.##.##7:9020 | xmllint --format - | grep -A1 '<Bucket>'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 583 100 583 0 0 31712 0 --:--:-- --:--:-- --:--:-- 32388
<Bucket>
<Name>new_bucket_name</Name>
--
<Bucket>
<Name>some_old_bucket</Name>
- 将存储区中的特定密钥或文件下载到 ECS 节点。
# perl s3curl.pl --id <user ID> -- http://<hostname or IP>:9020/<bucket>/<path1>/<object> -o download2.txt
provo:/usr/share/s3curl # perl s3curl.pl --id sample_user -- http://10.##.##.##7:9020/bucket_1/dir1/dir2/dir3/test_new_name.txt -o download2.txt
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 14 100 14 0 0 1360 0 --:--:-- --:--:-- --:--:-- 1400
provo:/usr/share/s3curl #
provo:/usr/share/s3curl # cat download2.txt
Goodbye World
- 删除属于该用户的存储区中的特定密钥或文件。
provo:/usr/share/s3curl # perl s3curl.pl --id <user ID> --delete -- http://<hostname or IP>:9020/<bucket>/<path1>/<path2>/<object>
提醒:如果对象名称中间有空格,则必须在整个路径中加引号并添加”
对象名称示例:
+ “在空间中。
对象名称示例:
test_new_name test - test.txt
perl s3curl.pl --id sample_user --delete -- "http://10.##.##.##7:9020/bucket/dir1/dir2/test_new_name+test+-+test.txt"
- 删除属于该用户的存储区。
provo:/usr/share/s3curl # perl s3curl.pl --id smaple_user --delete -- http://10.##.##.##7:9020/new_bucket_name
列出属于该用户的存储区后,存储区不存在:
provo:/usr/share/s3curl # perl s3curl.pl --id smaple_user -- http://10.##.##.##7:9020 | xmllint --format - | grep -A1 '<Bucket>'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 421 100 421 0 0 19928 0 --:--:-- --:--:-- --:--:-- 21050
<Bucket>
<Name>bucket_1</Name>
- 使用“byte: range”标头部分读取文件(读取前七个字符下方)
- 范围:字节值包括:
前 500 字节:“bytes 0-499/1234” 第二个 500 字节:“bytes 500-999/1234” 除前 500 字节之外的所有字节:“bytes 500-1233/1234” The last 500 bytes:“bytes 734-1233/1234”
provo:/usr/share/s3curl # cat test1.txt Goodbye World provo:/usr/share/s3curl # perl s3curl.pl --id sample_user -- http://10.##.##.##7:9020/bucket_1/dir1/dir2/dir3/test_new_name.txt -H "Range: bytes=0-6" Goodbye Using the "--debug" option for more detailed responses.
提醒:调试选项可用于
s3curl.pl 命令从阵列检索较旧的数据。
# perl s3curl.pl --debug --id <user ID> -- http://<hostname>:9020/<bucket>/<object> -H "Range: bytes=0-6"
provo:/usr/share/s3curl # perl s3curl.pl --debug --id sample_user -- http://10.##.##.##7:9020/bucket_1/dir1/dir2/dir3/test_new_name.txt -H "Range: bytes=0-6" s3curl: Found the url: host=10.##.##.237; port=9020; uri=/thomas/dir1/dir2/dir3/test_new_name.txt; query=; s3curl: ordinary endpoint signing case s3curl: StringToSign='GET\n\n\nWed, 08 Mar 2017 17:10:59 +0000\n/bucket_1/dir1/dir2/dir3/test_new_name.txt' s3curl: exec curl -v -H 'Date: Wed, 08 Mar 2017 17:10:59 +0000' -H 'Authorization: AWS hegars5:+YrMhohkQ2HqRNkYURJMbddIwrA=' -L -H 'content-type: ' http://10.##.##.##7:9020/bucket_1/dir1/dir2/dir3/test_new_name.txt -H 'Range: bytes=0-6' * Hostname was NOT found in DNS cache * Trying 10.##.##.##7... * Connected to 10.##.##.##7 (10.##.##.##7) port 9020 (#0) > GET /bucket_1/dir1/dir2/dir3/test_new_name.txt HTTP/1.1 > User-Agent: curl/7.37.0 > Host: 10.##.##.##7:9020 > Accept: */* > Date: Wed, 08 Mar 2017 17:10:59 +0000 > Authorization: AWS hegars5:+YrMhohkQ2HqRNkYURJMbddIwrA= > Range: bytes=0-6 > < HTTP/1.1 206 Partial Content < Date: Wed, 08 Mar 2017 17:10:59 GMT < Content-Range: bytes 0-6/14 < Accept-Ranges: bytes * Server ViPR/1.0 is not blacklisted < Server: ViPR/1.0 < x-amz-request-id: 0a3c23ed:15aa813368d:10fc:1 < x-amz-id-2: 83769c2fcf5f8907b60b588a251bcc492d86d5829dfc2c8bee2504f0c527f256 < ETag: "54aea9f06281a5df11d06f105c6fb039" < Last-Modified: Wed, 08 Mar 2017 17:02:13 GMT < x-emc-mtime: 1488992533141 < Content-Encoding: identity < Content-Type: application/octet-stream < Content-Length: 7 < * Connection #0 to host 10.##.##.##7 left intact Goodbye
- 将一批文件或密钥上传到特定存储区。
- 创建示例文件。
# vi /usr/share/s3curl/test # cat /usr/share/s3curl/test
此文件上传到 ECS 1000 次。
- 创建以下脚本。
# vi /usr/share/s3curl/script.sh
#!/bin/bash
# script.sh
for i in {1..1000}
do
./s3curl.pl --id=sample_user --put="test" -- "http://10.##.##.##7:9020/bucket_1/File$(printf "%04d" "$i").txt"
echo "File$(printf "%04d" "$i").txt"
done
- 更改脚本的权限。
# cd /usr/share/s3curl # sudo chmod +755
- 运行脚本。
# sh script.s
- 写入包含空格或特殊字符的文件
- 写入包含空格字符的文件,名为”
test file.txt“(需要 ASCII 值 %20)
provo:/usr/share/s3curl # perl s3curl.pl --id upload_test --put="test file.txt" -- http://10.##.##.##:9020/bucket_name/test%20file.txt
- 写入带有特殊字符括号的文件,称为”
testfile (1).txt“(需要斜杠)\“忽略特殊字符)
provo:/usr/share/s3curl # perl s3curl.pl --id upload_test --put="testfile (1).txt" -- http://10.##.##.##:9020/bucket_name/testfile%20\(1\).txt
Affected Products
Elastic Cloud StorageProducts
Elastic Cloud StorageArticle Properties
Article Number: 000014704
Article Type: How To
Last Modified: 20 Oct 2025
Version: 5
Find answers to your questions from other Dell users
Support Services
Check if your device is covered by Support Services.