minio搭建图床

minio搭建图床

minio部署见docker脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
version: "3.5"
services:
minio:
image: minio/minio
ports:
- "14033:9000"
volumes:
- /home/dockerdata/v-minio:/data
environment:
MINIO_ACCESS_KEY: "username"
MINIO_SECRET_KEY: "password"
command: server /data
deploy:
replicas: 1
restart_policy:
condition: on-failure
placement:
constraints: [node.hostname == me]

minio设置永久分享

1
2
3
4
docker exec -it <容器id> bash
curl https://dl.minio.io/client/mc/release/linux-amd64/mc --output mc
./mc config host add minio http://ip:14033 username password
./mc policy set public minio/<桶的名字>

设置成功后该桶就可以通过url了进行拼接访问了

图床客户端工具

方案一:typora+python+minio(采用)

安装
1
2
3
4
git clone https://github.com/minio/minio-py
cd minio-py
#需要代理下载
sudo python setup.py install
脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import time
import uuid
import sys
import requests
from minio import Minio
from minio.error import ResponseError
import warnings

warnings.filterwarnings('ignore')
images = sys.argv[1:]
minioClient = Minio("ip:port",
access_key='用户名', secret_key='密码', secure=False)
result = "Upload Success:\n"
date = time.strftime("%Y%m%d%H%M%S", time.localtime())

for image in images:
file_type = os.path.splitext(image)[-1]
new_file_name = date + file_type
if image.endswith(".png") or image.endswith(".jpg") or image.endswith(".gif"):
content_type ="image/"+file_type.replace(".", "");
else:
content_type ="image/jpg"
continue
try:
minioClient.fput_object(bucket_name='blog', object_name= new_file_name, file_path=image,content_type=content_type)
if image.endswith("temp"):
os.remove(image)
result = result +"http://ip:port" + "/blog/" + new_file_name + "\n"
except ResponseError as err:
result = result + "error:" + err.message + "\n"
print(result)

参考

Minio+Nginx搭建私有图床,写博客从未这么爽

python-client-quickstart-guide

方案二:upic+typora+minio

参考:Typora搭配uPic使用minIO自建图床

注意事项

minio图片不能预览

  1. 需要设置

image-20200805182053298

  1. 以及上传图片需要设置content_type为image/jpg

minio k8s helm chart 部署

部署

1
2
helm repo add minio https://charts.min.io/
helm install --set rootUser=rootuser,rootPassword=rootpass123 --generate-name minio/minio

minio k8s 部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations: {}
labels:
k8s.kuboard.cn/name: minio
name: minio
namespace: exxk
resourceVersion: '26439668'
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s.kuboard.cn/name: minio
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
k8s.kuboard.cn/name: minio
spec:
containers:
- args:
- server
- /data
- '--console-address'
- ':30697'
env:
- name: MINIO_ACCESS_KEY
value: root
- name: MINIO_SECRET_KEY
value: miniominio
image: minio/minio
imagePullPolicy: Always
name: minio
ports:
- containerPort: 9000
protocol: TCP
- containerPort: 30697
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /data
name: volume-ckiim
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- name: volume-ckiim
persistentVolumeClaim:
claimName: minio

---
apiVersion: v1
kind: Service
metadata:
annotations: {}
labels:
k8s.kuboard.cn/name: minio
name: minio
namespace: exxk
resourceVersion: '6221073'
spec:
clusterIP: 10.233.53.94
clusterIPs:
- 10.233.53.94
externalTrafficPolicy: Cluster
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: j7ffb8
nodePort: 31175
port: 9000
protocol: TCP
targetPort: 9000
- name: wgtsfa
nodePort: 30697
port: 30697
protocol: TCP
targetPort: 30697
selector:
k8s.kuboard.cn/name: minio
sessionAffinity: None
type: NodePort

mc客户端使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
bash-5.1# mc alias set myminio http://localhost:9000 myaccesskey mysecretkey
Added `myminio` successfully.
bash-5.1#
bash-5.1# mc ls myminio
[2023-10-11 10:02:09 UTC] 0B test/
bash-5.1# echo '{
"Rules": [
{
"ID": "ExpirePrefixDir",
"Status": "Enabled",
"Filter": {
"Prefix": "recognitionLog/"
},
"Expiration": {
"Days": 1
}
}
]
}' > lifecycle.json
bash-5.1# mc ilm import myminio/test < lifecycle.json
Lifecycle configuration imported successfully to `myminio/test`.
#上述设置过期时间,和界面设置的似乎是一致的,现在需要确定删除的时间,设置为1天,但是实际删除时间应该大于1天,取决于minio定时任务执行的时间
#经验证,设置的时间会在过期时间上门加1天,才会删除