• 使用curl进行s3服务操作


    最近使用curl对s3进行接口测试,本想写个总结文档,但没想到已有前辈写了,就直接搬过来做个记录吧,原文见:

    http://blog.csdn.net/ganggexiongqi/article/details/50483389

    不想使用s3cmd/s3curl等工具或者第三方库来测试RadosGW提供的s3服务。所以google了一把,已经有人做过了,详见参考链接。

    贴个shell脚本做个记录。

    1. 创建bucket

    创建名为"mygod"的bucket

    bucket="mygod"  
    dateValue=`date -R`  
    resource="/${bucket}/"  
    contentType="application/octet-stream"  
    stringToSign="PUT
    
    
    ${dateValue}
    ${resource}"  
    s3Key="6R2MJWR863EREUDD0KTZ"  
    s3Secret="74eHNNQa1oLBlvZfO2CC2hIU8cobSYxTgeRDtXtH"  
    signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`  
    curl -v -X PUT "http://${bucket}.s3.mydomain.com"   
            -H "Host: ${bucket}.s3.mydomain.com"   
            -H "Date: ${dateValue}"  
            -H "Authorization: AWS ${s3Key}:${signature}"
    

      

    2. 上传对象到bucket

     

    下面的脚本就是将@file上传到@url指定的存储服务集群中的@bucket下,对象的名字叫@objname。

    file=./c.zip  
    objname="testfile"  
    bucket=another  
    url="s3.mydomain.com"  
    resource="/${bucket}/${objname}"  
    contentType="application/x-compressed-tar"  
    dateValue=`date -R`  
    stringToSign="PUT
    
    ${contentType}
    ${dateValue}
    ${resource}"  
    s3Key="6R2MJWR863EREUDD0KTZ"  
    s3Secret="74eHNNQa1oLBlvZfO2CC2hIU8cobSYxTgeRDtXtH"  
    signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`  
    curl -X PUT -T "${file}"   
      -H "Host: ${bucket}.${url}"   
      -H "Date: ${dateValue}"   
      -H "Content-Type: ${contentType}"   
      -H "Authorization: AWS ${s3Key}:${signature}" "http://${bucket}.${url}/${objname}" 
    

      

    3. 获取object

    file="./myfile"  
    objname="testfile"  
    bucket=another  
    url="s3.mydomain.com"  
    resource="/${bucket}/${objname}"  
    contentType="application/x-compressed-tar"  
    dateValue=`date -R`  
    stringToSign="GET
    
    ${contentType}
    ${dateValue}
    ${resource}"  
    s3Key="6R2MJWR863EREUDD0KTZ"  
    s3Secret="74eHNNQa1oLBlvZfO2CC2hIU8cobSYxTgeRDtXtH"  
    signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`  
    curl -o ${file} -X GET   
      -H "Host: ${bucket}.${url}"   
      -H "Date: ${dateValue}"   
      -H "Content-Type: ${contentType}"   
      -H "Authorization: AWS ${s3Key}:${signature}" "http://${bucket}.${url}/${objname}" 
    

      

    1. bucket="mygod"  
    2. dateValue=`date -R`  
    3. resource="/${bucket}/"  
    4. contentType="application/octet-stream"  
    5. stringToSign="PUT ${dateValue} ${resource}"  
    6. s3Key="6R2MJWR863EREUDD0KTZ"  
    7. s3Secret="74eHNNQa1oLBlvZfO2CC2hIU8cobSYxTgeRDtXtH"  
    8. signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`  
    9. curl -v -X PUT "http://${bucket}.s3.mydomain.com"   
    10.         -H "Host: ${bucket}.s3.mydomain.com"   
    11.         -H "Date: ${dateValue}"  
    12.         -H "Authorization: AWS ${s3Key}:${signature}"
  • 相关阅读:
    【Hadoop离线基础总结】Hue的简单介绍和安装部署
    【Hadoop离线基础总结】Hue与Mysql集成
    【Hadoop离线基础总结】Hue与Impala集成
    【Hadoop离线基础总结】Hue与Hive集成
    【Hadoop离线基础总结】Hue与Hadoop集成
    【Hadoop离线基础总结】impala简单介绍及安装部署
    centos7启动httpd服务失败:Job for httpd.service failed because the control process exited with error code.
    【Hadoop离线基础总结】Mac版VMware Fusion虚拟机磁盘挂载
    Azkaban无法连接网页
    【Hadoop离线基础总结】流量日志分析网站整体架构模块开发
  • 原文地址:https://www.cnblogs.com/landhu/p/6482801.html
Copyright © 2020-2023  润新知