minio部署与使用
一、部署minio容器拉取镜像docker pull minio/minio编写启动容器脚本(/data/minio)sudo vim mino.shdocker run -d \-p 80:9000 \--name=minio \--restart=on-failure:3 \-e "MINIO_ACCESS_KEY=admin" \-e "MINIO_SECRET_KEY=password"
·
一、部署minio容器
拉取镜像
docker pull minio/minio
编写启动容器脚本(/data/minio)
sudo vim mino.sh
docker run -d \
-p 80:9000 \
--name=minio \
--restart=on-failure:3 \
-e "MINIO_ACCESS_KEY=admin" \
-e "MINIO_SECRET_KEY=password" \
-v /etc/localtime:/etc/localtime
-v /data/minio/data:/data \
-v /data/minio/config:/root/.minio \
minio/minio server /data
启动后访问:http://127.0.0.1:9000
二、配置minio角色和策略等 (这一步操作的目的是为了服务端生成临时密钥获取的角色策略权限)
编辑策略 (/data/minio)
sudo vim ploy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::*"
]
}
]
}
使用管理命令工具配置
#拉镜像
docker pull minio/mc
##启动sudo vim minio-mc.sh
docker run -it --entrypoint=/bin/sh -v /etc/localtime:/etc/localtime -v /data/minio/ploy.json:/home/ploy.json --net=host minio/mc=/bin/sh -v /etc/localtime:/etc/localtime minio/mc
注意:启动之后会进入容器进行操作
配置设置
mc config host add minio 地址 账号 密码 --api s3v4
设置新的别名
mc alias set minio 地址 账号 密码
创建策略
mc admin policy add minio /home/ploy.json
创建用户
mc admin user add minio 账号 密码
角色添加策略
mc admin policy set minio 策略名称 user=创建的用户
mc相关命令
mc admin console minio//打印日志
mc policy set public minio/yz-payment //设置访问权限
mc config host list //获取节点list
mc admin --json info minio //获取minio节点信息
mc admin config get minio //获取节点配置信息
三、服务端生成临时密钥代码
## node.js版
/**
* @summary获取awsminio临时token
*/
async getMinioToken(){
const { config, logger, ctx } = this;
const sts = new AWS.STS({
accessKeyId: 'admin',
secretAccessKey: 'password',
endpoint:'http://127.0.0.1:9000',
region:'us-east-1'
});
console.log("sts=====>",sts)
const policy = {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": ["arn:aws:s3:::*"]
}
]
}
const params = {
ExternalId: "123ABC",
Policy: JSON.stringify(policy),
RoleArn: "arn:aws:iam::123456789012:role/demo", //
RoleSessionName: "testAssumeRoleSession",
TransitiveTagKeys: [
"Project",
"Cost-Center"
]
};
sts.assumeRole(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
四、minio出现跨域问题
目前解决方案是配置nginx请求头
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS,PUT';
add_header 'Access-Control-Allow-Headers' 'Date, Etag, Server, Connection, Accept-Ranges, Content-Range, Content-Encoding, Content-Length, Content-Type, Content-Disposition, Last-Modified, Content-Language, Cache-Control, Retry-After, X-Amz-Bucket-Region, Expires, X-Amz*, X-Amz*, *';
五、参考链接
更多推荐
已为社区贡献1条内容
所有评论(0)