对象存储客户端配置


在Linux客户端连接OSS对象存储,对于支持S3协议的对象存储,可以使用S3cmd命令行工具进行连接,该工具是免费的命令行客户端,也有Windows版本的命令行工具S3Express,支持Amazon S3及其他S3存储。

S3cmd官网

1、Linux安装S3命令行工具
[root@localhost ~]# yum install -y s3cmd

或者

[root@localhost ~]# yum install python-pip
[root@localhost ~]# pip install s3cmd
2、连接对象存储

执行s3cmd --configure ,按照提示输入Access Key、Secret Key、S3 Endpoint、DNS-style bucket+hostname、Use HTTPS protocol 等关键信息,设置完成后生成 .s3cfg 配置文件,测试连接是否成功

其中,Access Key、Secret Key、S3 Endpoint由存储管理员提供

示例:

[root@localhost ~]# 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: WPYUIcAELVCWNB7sWWG1
Secret Key: 9l5S0WLiC37nujNCMsWAe8494OXOPRJ1JtRqWn1n
Default Region [US]: CN

Use "s3.amazonaws.com" for S3 Endpoint and not modify it to the target Amazon S3.
S3 Endpoint [s3.amazonaws.com]: 192.168.1.1:8060

Use "%(bucket)s.s3.amazonaws.com" to the target Amazon S3. "%(bucket)s" and "%(location)s" vars can be used
if the target S3 system supports dns based buckets.
DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.s3.amazonaws.com]: %(*)s.s3.192.168.1.1:8060

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]: No

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: WPYUIDAELVCWNB7BTWG1
  Secret Key: 9l5u0WLiC37nujNCMfYAe8494OXvuRJ1JtRqWn1n
  Default Region: CN
  S3 Endpoint: 192.168.1.1:8060
  DNS-style bucket+hostname:port template for accessing a bucket: %(*)s.s3.192.168.1.1:8060
  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] Y
Please wait, attempting to list all buckets...
Success. Your access key and secret key worked fine :-)

Now verifying that encryption works...
Not configured. Never mind.

Save settings? [y/N] y
Configuration saved to '/root/.s3cfg'

.s3cfg配置文件关键字段,需要根据自己的OSS具体信息进行修改:

[default] 
access_key = xxx
secret_key = xxx 
host_base = <server-hostname>:<server_port>
host_bucket = %(bucket)s.<server-hostname>:< server_port >
use_https=False

上述配置完成后,就可以通过s3cmd命令进行操作了

3、对象存储常用操作
#列出桶
[root@localhost ~]# s3cmd ls  
#创建桶
[root@localhost ~]# s3cmd mb s3://ossdata
#列出所有对象文件
[root@localhost ~]# s3cmd la
#上传对象文件
[root@localhost ~]# s3cmd put ./file1 s3://ossdata
#下载对象文件
[root@localhost ~]# s3cmd get s3://ossdata/file1
#更多操作命令参考
[root@localhost ~]# s3cmd -h

详细使用方法,参考s3tools官网


文章作者: Netcat-fan
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Netcat-fan !
  目录