minIO部署
安装包下载:http://dl.minio.org.cn/server/minio/release/linux-amd64/minio
centos7单节点部署:
wget -q http://dl.minio.org.cn/server/minio/release/linux-amd64/minio
chmod +x minio
#启动minio server服务,指定数据存储目录/mnt/data
export MINIO_ROOT_USER=admin
export MINIO_ROOT_PASSWORD=12345678
./minio server --address ":9002" --console-address ":50000" /export/data
#访问地址:http://192.168.100.101:50000/login
centos7分布式部署:
--启动,4节点,每个节点一块磁盘
export MINIO_ROOT_USER=admin
export MINIO_ROOT_PASSWORD=123456
nohup /dfsdata/minio/minio server --address 0.0.0.0:9005 --console-address 0.0.0.0:9006 --config-dir /etc/minio \
http://worker1.hd.com.cn/dfsdata3/minio/data \
http://worker2.hd.com.cn/dfsdata3/minio/data \
http://worker3.hd.com.cn/dfsdata3/minio/data \
http://worker4.hd.com.cn/dfsdata3/minio/data > /dfsdata3/minio/logs/minio_server.log 2>&1 &
权限:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "admin:*" ] }, { "Effect": "Allow", "Action": [ "kms:*" ] }, { "Effect": "Allow", "Action": [ "s3:*" ], "Resource": [ "arn:aws:s3:::text01/*" ] } ] }
text01桶的所有权限
minIO页面操作:
创建bucket
文件名访问:http://ip:19005/sepee/2023/02/23/a4bbee427d3c42259af600b13e4db923.png
java api
<dependency> <groupId>io.minio</groupId> <artifactId>minio</artifactId> <version>8.4.2</version> </dependency> <dependency> <groupId>me.tongfei</groupId> <artifactId>progressbar</artifactId> <version>0.9.3</version> </dependency> <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>4.8.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> </dependency> public class Demoss { private static MinioClient minioClient; private static String bucketName = "text01"; private static String filePath = "D:\\123.png"; private static String endPoint = "http://192.168.100.105:9002"; private static String accessKey = "admin"; private static String secretKey = "12345678"; //上传文件大小限制5M private static long limitSize = 5242880L; private void init() { minioClient = MinioClient .builder() .endpoint(endPoint) .credentials(accessKey, secretKey) .build(); } /** * 版本控制 * * @throws Exception */ private void version() throws Exception { init(); // Enable versioning on 'my-bucketname'. minioClient.setBucketVersioning( SetBucketVersioningArgs.builder() .bucket(bucketName) .config(new VersioningConfiguration(VersioningConfiguration.Status.ENABLED, null)) .build()); System.out.println("Bucket versioning is enabled successfully"); } /** * 新建桶 * * @throws Exception */ @Test public void testCreateBucket() throws Exception { init(); boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()); if (isExist) { System.out.println(bucketName + "已经存在!"); } else { minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build()); System.out.println("创建了一个名字是" + bucketName + "的bucket"); } } /** * 查询桶列表 * * @throws Exception */ @Test public void testListBuckets() throws Exception { init(); List<Bucket> bucketList = minioClient.listBuckets(); bucketList.forEach(p -> { System.out.println(p.name()); }); } /** * 上传 * * @throws Exception */ @Test public void testUploadFile() throws Exception { init(); version(); for (int i = 0; i < 10; i++) { minioClient.uploadObject( UploadObjectArgs .builder() .bucket(bucketName) .object("123.png")//上传的名 .filename(filePath)//本地磁盘地址 .build()); } System.out.println("上传完毕,请刷新minio的web页面,查看上传文件"); } /** * 下载 * * @throws Exception */ @Test public void testDownloadFile() throws Exception { init(); minioClient.downloadObject( DownloadObjectArgs .builder() .bucket(bucketName) .object("123.png")//minio上的文件名 .filename("D:\\1234.png")//下载的文件名 .build() ); System.out.println("下载完毕"); } /** * 删除Bucket下所有文件 * * @throws Exception */ @Test public void testRemoveBucket() throws Exception { init(); boolean isExist = minioClient.bucketExists( BucketExistsArgs .builder() .bucket(bucketName) .build() ); if (isExist) { //桶不空,删不掉,所以清桶的objects Iterable<Result<Item>> iterable = minioClient.listObjects( ListObjectsArgs .builder() .bucket(bucketName) .build() ); for (Result<Item> o : iterable) { System.out.println("当前objectname---->>>>>>>" + o.get().objectName()); minioClient.removeObject( RemoveObjectArgs.builder() .bucket(bucketName) .object(o.get().objectName()) .versionId(o.get().versionId()) .build()); System.out.println("清理---->>>>>>>" + o.get().objectName()); } System.out.println("清理" + bucketName + "下的object完毕"); /* minioClient.removeBucket( RemoveBucketArgs .builder() .bucket(bucketName) .build() );*/ /* if (!minioClient.bucketExists( BucketExistsArgs. builder() .bucket(bucketName) .build() )) { System.out.println("删除" + bucketName + "完毕,刷新minio的web页面"); }*/ } else { System.out.println("没有这个bucket,无需操作"); } } }