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
如果用戶端有網路分隔,您會看到 資料 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

步驟:

  1. 前往目錄 /usr/share/s3curl ,然後檢查下列檔案。
provo:/usr/share/s3curl #
provo:/usr/share/s3curl # ls -lrt .s3curl
-rw------- 1 root root 2095 Mar  6 16:14 .s3curl
  1. 如果檔案不存在,請使用以下內容創建該檔。["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>',)
); 
  1. 您可以像下面這樣向此檔添加多個使用者。
%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>',)
);
  1. 更改文件的許可權。
# sudo chmod 755 s3curl.pl

# sudo chmod 600 .s3curl


使用 s3curl.pl 組態後

  1. 測試使用者身份驗證並列出該用戶擁有的存儲桶。」bucket_1」是儲存器的名稱。
  • --id = 前面設定的 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>
  1. 列出特定儲存桶的內容。
  • 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>
  1. 在儲存桶中搜尋特定金鑰或檔案。
  • 知道檔案名稱的開頭後,使用首碼搜尋方法搜尋特定檔案。
  • 在儲存桶名稱後插入方法”?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>
  1. 讀取儲存桶中的特定金鑰或檔案。
注意:如果鍵或存儲桶的名稱中包含空格,請使用字串”%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
  1. 將特定金鑰或檔案寫入儲存器。
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
  1. 讀取儲存桶中特定金鑰或檔的元數據。
  • HTTP/1.1 200 OK --> 要求的特定 HTTP 回應
  • x-amz-request-id --> request_id 可在 ECS 記錄中追蹤
  • ETag --> 檔案的 MD5SUM
  • Content-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
  1. 要為使用者建立新儲存桶,請執行以下操作:
# 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>
  1. 將儲存桶中的特定金鑰或檔案下載至 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
  1. 刪除儲存桶中屬於使用者的特定金鑰或檔案。
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"
  1. 刪除桶屬於使用者。
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>
  1. 使用「byte: range」標頭讀取部分檔案 (讀取前七個字元以下)
  • 範圍:位元組值包括:
前 500 個位元組:「bytes 0-499/1234」第二個 500 位元組:“bytes 500-999/1234”除前 500 個字節之外的所有位元組:「bytes 500-1233/1234」最後 500 個位元組:「位元組 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
  1. 將一批檔或金鑰上傳到特定存儲桶。
  • 創建範例檔。
# vi /usr/share/s3curl/test

# cat /usr/share/s3curl/test

此檔案會上傳 1,000 次至 ECS。

  • 創建以下腳本。
# 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
  1. 寫入包含空白或特殊字元的檔案
  • 編寫名為「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 Storage

Products

Elastic Cloud Storage
Article 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.