S3cmd 中國區客戶端配置詳解

                        本篇旨在介紹S3cmd的配置方法

注意:s3cmd版本>1.5
1、下載s3cmd

wget http://sourceforge.net/projects/s3tools/files/s3cmd/1.5.2/s3cmd-1.5.2.tar.gz
解壓
tar -zxf s3cmd-1.5.2.tar.gz -C /usr/local

2、安裝setuptools

tar -xf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python 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 : 輸入AK
Secret Key : 輸入SK
Default Region [US]:
Encryption password is used to protect your files from reading
by unauthorized persons while in transfer to S3
Encryption password :
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 only be proxied with Python 2.7 or newer
Use 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 directly
HTTP Proxy server name:
New settings:
Access Key:*
Secret Key: ***

Encryption password: ****
Path to GPG program: /usr/bin/gpg
Use HTTPS protocol: False
HTTP 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-1
host_base = s3.cn-northwest-1.amazonaws.com.cn
host_bucket = %(bucket)s.s3.cn-northwest-1.amazonaws.com.cn
website_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查看

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章