1、安装s3cmd
  1. # yum -y install s3cmd
2、创建s3用户
  1. # radosgw-admin user create --uid=admin --access-key=123456 --secret-key=123456 --display-name=admin
  2. {
  3. "user_id": "admin",
  4. "display_name": "admin",
  5. "email": "",
  6. "suspended": 0,
  7. "max_buckets": 1000,
  8. "auid": 0,
  9. "subusers": [],
  10. "keys": [
  11. {
  12. "user": "admin",
  13. "access_key": "123456",
  14. "secret_key": "123456"
  15. }
  16. ],
  17. "swift_keys": [],
  18. "caps": [],
  19. "op_mask": "read, write, delete",
  20. "default_placement": "",
  21. "placement_tags": [],
  22. "bucket_quota": {
  23. "enabled": false,
  24. "check_on_raw": false,
  25. "max_size": -1,
  26. "max_size_kb": 0,
  27. "max_objects": -1
  28. },
  29. "user_quota": {
  30. "enabled": false,
  31. "check_on_raw": false,
  32. "max_size": -1,
  33. "max_size_kb": 0,
  34. "max_objects": -1
  35. },
  36. "temp_url_keys": [],
  37. "type": "rgw"
  38. }
3、配置s3cmd
  1. root目录下创建.s3cfg文件,并写入以下内容
  2. [root@node1 ~]# vim .s3cfg
  3. [default]
  4. access_key = 123456
  5. bucket_location = US
  6. cloudfront_host = 192.168.1.10:8080
  7. cloudfront_resource = /2010-07-15/distribution
  8. default_mime_type = binary/octet-stream
  9. delete_removed = False
  10. dry_run = False
  11. encoding = UTF-8
  12. encrypt = False
  13. follow_symlinks = False
  14. force = False
  15. get_continue = False
  16. gpg_command = /usr/bin/gpg
  17. gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
  18. gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
  19. gpg_passphrase =
  20. guess_mime_type = True
  21. host_base = 192.168.1.10:8080
  22. host_bucket = 192.168.1.10:8080/%(bucket)
  23. human_readable_sizes = False
  24. list_md5 = False
  25. log_target_prefix =
  26. preserve_attrs = True
  27. progress_meter = True
  28. proxy_host =
  29. proxy_port = 0
  30. recursive = False
  31. recv_chunk = 4096
  32. reduced_redundancy = False
  33. secret_key = 123456
  34. send_chunk = 96
  35. simpledb_host = sdb.amazonaws.com
  36. skip_existing = False
  37. socket_timeout = 300
  38. urlencoding_mode = normal
  39. use_https = False
  40. verbosity = WARNING
  41. signature_v2 = True

在上面的配置中需要进行修改的配置项为

  1. cloudfront_host
  2. host_base
  3. host_bucket
  4. access_key
  5. secret_key
s3cmd 操作
1、创建bucket
  1. s3cmd mb s3://test
  2. Bucket 's3://test/' created
2、上传object
  1. # s3cmd put osd.sh s3://test
  2. upload: 'osd.sh' -> 's3://test/osd.sh' [1 of 1]
  3. 1472 of 1472 100% in 2s 628.87 B/s done
3、查看bucket
  1. # s3cmd ls
  2. 2018-07-03 08:32 s3://test
4、查看指定bucket内的object
  1. # s3cmd ls s3://test
  2. 2018-07-03 08:58 1472 s3://test/osd.sh
5、下载文件到本地
  1. # s3cmd get s3://test/osd.sh test.sh
  2. download: 's3://test/osd.sh' -> 'test.sh' [1 of 1]
  3. 1472 of 1472 100% in 0s 153.24 kB/s done
6、删除object
  1. # s3cmd rm s3://test/osd.sh
  2. delete: 's3://test/osd.sh'
7、删除bucket
  1. # s3cmd rb s3://test/
  2. Bucket 's3://test/' removed