本文共 2026 字,大约阅读时间需要 6 分钟。
本篇旨在介绍S3cmd的配置方法
注意:s3cmd版本>1.5
1、下载s3cmdwget
解压tar -zxf s3cmd-1.5.2.tar.gz -C /usr/local
2、安装setuptools
tar -xf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11python setup.py install
3、安装s3cmd
cd /usr/local/s3cmd-1.5.2
python setup.py install
4、配置AK
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. Leave them empty for using the env variables.Access Key : 输入AKSecret Key : 输入SKDefault Region [US]: Encryption password is used to protect your files from readingby unauthorized persons while in transfer to S3Encryption password : Path to GPG program [/usr/bin/gpg]: When using secure HTTPS protocol all communication with Amazon S3servers is protected from 3rd party eavesdropping. This method isslower than plain HTTP, and can only be proxied with Python 2.7 or newerUse HTTPS protocol [Yes]: On some networks all internet access must go through a HTTP proxy.Try setting it here if you can't connect to S3 directlyHTTP Proxy server name: New settings:Access Key:*Secret Key: ***Encryption password: ****Path to GPG program: /usr/bin/gpgUse HTTPS protocol: FalseHTTP Proxy server name: HTTP Proxy server port: 0...Test access with supplied credentials? [Y/n] test access.... ? 这块选择no,选用yes会测试失败save the changes? yes
以上必须填写的是AK和SK,其他信息直接回车即可。
5、修改配置文件:(如下以中国宁夏为例,修改如下四行内容)
vi /root/.s3cfg
bucket_location = cn-northwest-1host_base = s3.cn-northwest-1.amazonaws.com.cnhost_bucket = %(bucket)s.s3.cn-northwest-1.amazonaws.com.cnwebsite_endpoint =http://%(bucket)s.s3-website-%(location)s.amazonaws.com.cn
默认的S3配置文件是AWS美国地域的,所以不修改的话会出现:Your Access key is not in our record类似这种错误。
修改完成后即可使用s3cmd 去测试了。一般在linux系统上使用s3cmd也是为了便于写异地备份脚本,常用命令如下:
查看存储桶内容s3cmd ls s3://bucket_name上传存储桶内容 (如递归上传,需要加上参数-r)s3cmd put filename s3://bucket_name/filename删除存储桶内容s3cmd del s3://bucket_name/filename更多命令可通过s3cmd --help查看
转载于:https://blog.51cto.com/9867744/2356318