1. 安装s3cmd工具
[root@testserver01 ~]# yum install s3cmd
2. 配置s3cmd, 按提示输入相应的ak,sk,endpoint等信息
[root@testserver01 ~]# s3cmd --configure
3. s3cmd使用
[root@testserver01 ~]# s3cmd mb s3://abc (创建一个桶)
Bucket 's3://abc/' created
[root@testserver01 ~]# vi policy.txt
[root@testserver01 ~]# cat policy.txt
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::abc/*"
]
}
]
}
[root@testserver01 ~]# s3cmd setpolicy ./policy.txt s3://abc (为指定桶设置policy)
s3://abc/: Policy updated
[root@testserver01 ~]# s3cmd ls s3://abc (ls 列出abc bucket下面的文件)
2024-03-02 12:38 42272 s3://abc/xxx.sql
2024-03-02 12:38 12566 s3://abc/pro_update.txt
[root@testserver01 ~]# s3cmd del s3://abc/xxx.sql (删除桶里面某个文件)
delete: 's3://abc/microcloud.sql'
[root@testserver01 ~]# s3cmd ls s3://abc
2024-03-02 12:38 12566 s3://abc/pro_update.txt
[root@testserver01 ~]# ls
anaconda-ks.cfg policy.txt
[root@testserver01 ~]# s3cmd put anaconda-ks.cfg s3://abc/ (往指定桶里面上传文件)
upload: 'anaconda-ks.cfg' -> 's3://abc/anaconda-ks.cfg' [1 of 1]
1515 of 1515 100% in 0s 27.43 KB/s done
[root@testserver01 ~]# s3cmd ls s3://abc
2024-03-02 12:45 1515 s3://abc/anaconda-ks.cfg
2024-03-02 12:38 12566 s3://abc/pro_update.txt
[root@testserver01 ~]# s3cmd get s3://abc/pro_update.txt (从桶里面下载文件)
download: 's3://abc/pro_update.txt' -> './pro_update.txt' [1 of 1]
12566 of 12566 100% in 0s 1446.60 KB/s done
[root@testserver01 ~]# ls
anaconda-ks.cfg policy.txt pro_update.txt
[root@testserver01 ~]#