zoukankan      html  css  js  c++  java
  • S3 Client 的安装与使用

    原文:https://www.howtoing.com/install-s3cmd-manage-amazon-s3-buckets

    摘要:

    安装s3cmd包

    s3cmd是默认的RPM库针对CentOS,RHEL和Ubuntu系统上可用,您可以简单的在系统上执行以下命令进行安装。

    在CentOS / RHEL:
    # yum install s3cmd
    在Ubuntu / Debian:
    $ sudo apt-get install s3cmd
    在SUSE Linux Enterprise Server 11:
    # zypper addrepo http://s3tools.org/repo/SLE_11/s3tools.repo
    # zypper install s3cmd
    使用Source安装最新s3cmd

    如果使用上述软件包管理器s3cmd,你没有得到最新的版本,可以使用源代码,在系统上安装最新的s3cmd版本。访问此网址或者使用下面的命令来下载最新版本的s3cmd。

    $ wget http://ufpr.dl.sourceforge.net/project/s3tools/s3cmd/1.6.1/s3cmd-1.6.1.tar.gz
    $ tar xzf s3cmd-1.6.1.tar.gz

    现在,使用下面的命令与源文件进行安装。

    $ cd s3cmd-1.6.1
    $ sudo python setup.py install
    配置s3cmd环境

    为了配置s3cmd我们将要求有您S3 Amazon帐户访问key和钥匙。获取安全密钥AWS securityCredentials 。将提示登录到您的Amazon帐户。 获取密钥文件后,请使用以下命令来配置s3cmd。

    # s3cmd --configure
    Enter new values or accept defaults in brackets with Enter.
    Refer to user manual for detailed description of all options.
    
    Access key and Secret key are your identifiers for Amazon S3
    Access Key: xxxxxxxxxxxxxxxxxxxxxx
    Secret Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    
    Encryption password is used to protect your files from reading
    by unauthorized persons while in transfer to S3
    Encryption password: xxxxxxxxxx
    Path to GPG program [/usr/bin/gpg]:
    
    When using secure HTTPS protocol all communication with Amazon S3
    servers is protected from 3rd party eavesdropping. This method is
    slower than plain HTTP and can't be used if you're behind a proxy
    Use HTTPS protocol [No]: Yes
    
    New settings:
      Access Key: xxxxxxxxxxxxxxxxxxxxxx
      Secret Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      Encryption password: xxxxxxxxxx
      Path to GPG program: /usr/bin/gpg
      Use HTTPS protocol: True
      HTTP Proxy server name:
      HTTP Proxy server port: 0
    
    Test access with supplied credentials? [Y/n] Y
    Please wait, attempting to list all buckets...
    Success. Your access key and secret key worked fine :-)
    
    Now verifying that encryption works...
    Success. Encryption and decryption worked fine :-)
    
    Save settings? [y/N] y
    Configuration saved to '/root/.s3cfg'
    s3cmd命令行的使用

    一旦配置成功完成。现在找到下面的命令细节,如何使用命令管理S3桶。

    1.列出全部S3桶

    使用以下命令列出在您的AWS账户中的所有S3桶。

    # s3cmd ls
    
    2.创建新桶

    要在下面的命令Amazon S3上使用的新桶。这将创建S3帐户名为howtoing桶。

    # s3cmd mb s3://howtoing
    
    Bucket 's3://howtoing/' created
    3. 上传文件到S3桶

    以下命令将使用s3cmd命令上传文件file.txt的到S3桶。

    # s3cmd put file.txt s3://howtoing/
    
    file.txt -> s3://howtoing/file.txt  [1 of 1]
     190216 of 190216   100% in    0s  1668.35 kB/s  done
    4.上传文件夹到s3桶

    如果我们需要上传整个目录使用-r递归上传,像下面这样。

    # s3cmd put -r backup s3://howtoing/
    
    backup/file1.txt -> s3://howtoing/backup/file1.txt  [1 of 2]
     9984 of 9984   100% in    0s    18.78 kB/s  done
    backup/file2.txt -> s3://howtoing/backup/file2.txt  [2 of 2]
     0 of 0     0% in    0s     0.00 B/s  done

    请确保您上传目录的结尾没有斜杠 / (如:backup/),否则将只上传备份目录中的内容。

    # s3cmd put -r backup/ s3://howtoing/
    
    backup/file1.txt -> s3://howtoing/file1.txt  [1 of 2]
     9984 of 9984   100% in    0s    21.78 kB/s  done
    backup/file2.txt -> s3://howtoing/file2.txt  [2 of 2]
     0 of 0     0% in    0s     0.00 B/s  done
    5.列出S3存储数据

    使用 ls 与 s3cmd 切换目录S3桶的对象。

    # s3cmd ls s3://howtoing/
    
                           DIR   s3://howtoing/backup/
    2013-09-03 10:58    190216   s3://howtoing/file.txt
    6.从s3下载文件

    有些时候,如果我们需要从S3下载文件,使用下面的命令来下载。

    # s3cmd get s3://howtoing/file.txt
    
    s3://howtoing/file.txt -> ./file.txt  [1 of 1]
     4 of 4   100% in    0s    10.84 B/s  done
    7.删除S3桶的数据

    要删除的文件夹都是从S3桶使用下面的命令。

     Removing file from s3 bucket 
    # s3cmd del s3://howtoing/file.txt
    
    File s3://howtoing/file.txt deleted
    
     Removing directory from s3 bucket 
    # s3cmd del s3://howtoing/backup
    
    File s3://howtoing/backup deleted
    8.卸下S3桶

    如果我们不需要S3存储,我们可以用下面的命令直接删除它。取出桶之前,请确保它是空的。

    # s3cmd rb s3://howtoing
    
    ERROR: S3 error: 409 (BucketNotEmpty): The bucket you tried to delete is not empty

    上面的命令失败,因为S3桶不为空 要删除s3 桶先删除里面所有对象,然后再次使用命令。

    # s3cmd rb s3://howtoing
    
    Bucket 's3://howtoing/' removed

    感谢您使用这篇文章。 如果你想在你的系统安装s3bucket,可以查看文章登录S3bucket在Linux中使用s3fs 。 你也可以在S3桶和本地之间使用目录s3cmd同步数据 。

  • 相关阅读:
    杭州办理招行香港一卡通(两地一卡通)攻略
    Android高手进阶教程(二十)之Android与JavaScript方法相互调用!
    Android应用的自动升级、更新模块的实现
    18个最好的jQuery表格插件
    系统的本地策略不允许你采用交互式登录
    android中判断横屏或者竖屏并改变背景
    记录几个东东
    jsAnim学习
    win7下安装oracle10g出现未知错误,程序异常终止
    oracle创建用户并授权
  • 原文地址:https://www.cnblogs.com/lshan/p/13588863.html
Copyright © 2011-2022 走看看