MinIO 是一個基於 Apache License v2.0 開源協議的對象存儲服務。它兼容亞馬遜 S3 雲存儲服務接口,很是適合於存儲大容量非結構化的數據,例如圖片、視頻、日誌文件、備份數據和容器/虛擬機鏡像等,而一個對象文件能夠是任意大小,從幾 kb 到最大 5T 不等。linux
MinIO 是一個很是輕量的服務,能夠很簡單的和其餘應用的結合,相似 NodeJS, Redis 或者 MySQL。git
官方對 Minio 的定義是一個高性能的對象存儲。github
Build high performance data infrastructure
for machine learning, analytics and
application data workloads with MinIO 。docker
Minio 的官方網站是 https://min.io ,
Minio 的官方文檔是 https://docs.min.io/cn/ ,
GitHub 倉庫地址是:https://github.com/minio/minio ,目前有 18.8k Stars (2019.11.9)安全
Minio 的 benchmark 說明:服務器
https://min.io/resources/docs/MinIO-vs-HDFS-MapReduce-performance-comparison.pdf
https://min.io/resources/docs/MinIO-throughput-benchmarks-on-NVMe-SSD.pdf
https://min.io/resources/docs/Performance-comparison-Starburst-Presto-SQL.pdf
https://min.io/resources/docs/MinIO-throughput-benchmarks-on-HDD.pdf
https://min.io/resources/docs/Performance-comparison-Apache-Spark.pdfapp
MinIO 分爲服務端和客戶端,服務端提供一個對象存儲,也提供一個 Web 的管理頁面。客戶端是用來管理、查看服務端的一個工具。服務端的二進制文件是 minio
,客戶端的二進制文件是 mc
。dom
首先先下載服務端的二進制文件,其次準備一個用來存儲的磁盤或者目錄,工具
下載好之後賦予執行權限,可使用以下命令快速啓動。性能
chmod +x minio ./minio server /erdong/data
啓動後能夠經過訪問 http://localhost:9000 來訪問你的對象存儲。
MinIO 須要一個持久捲來存儲配置和應用數據。不過, 若是隻是爲了測試一下, 您能夠經過簡單地傳遞一個目錄(在下面的示例中爲 /erdong/data
)啓動 MinIO 。這個目錄會在容器啓動時在容器的文件系統中建立,不過全部的數據都會在容器退出時丟失。
要建立具備永久存儲的 MinIO 容器,您須要將本地持久目錄從主機操做系統映射到虛擬配置 ~/.minio 並導出 /data 目錄。 爲此,請運行如下命令
docker run -p 9000:9000 --name minio \ -e "MINIO_ACCESS_KEY=minioadmin" \ -e "MINIO_SECRET_KEY=minioadminpassword" \ -v /erdong/minio/data:/data \ -v /erdong/minio/config:/root/.minio \ minio/minio server /data
啓動後,便可訪問 http://localhost:9000 來訪問你的對象存儲。
上述命令中設置了以下參數:
若是須要指定端口可使用以下參數
--address ":9000"
接下來咱們看看如何在 linux 上配置 MinIO 服務使用 TLS 。
使用 TLS 的前提是先下載好 MinIO Server 。
若是你已經有私鑰和公鑰證書,你須要將他們拷貝到 MinIO 的 $HOME/.minio/certs
文件夾,私鑰的名字必須是 private.key
,公鑰證書的名字必須是 public.crt
。 MinIO 在 Linux 只支持使用 PEM 格式的祕鑰和證書,在 Windows 上只支持 PEM 格式的祕鑰和證書,目前不支持 PFX 證書。
若是這個證書是被證書機構簽發的,public.crt
應該是服務器的證書。
Linux 可使用以下工具來生成證書
Windows 可使用以下工具來生成證書
Minio 也能夠配置成鏈接其它服務,無論是 Minio 節點仍是像 NATs、Redis 這些。若是這些服務用的不是在已知證書機構註冊的證書,你可讓 Minio 服務信任這些 CA ,怎麼作呢,將這些證書放到Minio配置路徑下(~/.minio/certs/CAs/ Linux 或者 C:\Users<Username>.minio\certs\CAs Windows).
使用以下命令生成私鑰,私鑰會生成在執行命令的目錄下
openssl genrsa -out private.key 2048
生成自簽名的證書,證書會生成在執行命令的目錄下
openssl req -new -x509 -days 3650 -key private.key -out public.crt -subj "/C=US/ST=state/L=location/O=organization/CN=domain"
其中相關內容能夠按照實際狀況修改,好比 /C
是國家,中國是 CN ,/ST
是州或者省, /L
是市或者區, /CN
是域名。
祕鑰和證書生成好之後,按照上邊的要求放置在對應的目錄便可。
Thanos 在鏈接 MinIO 的時候遇到了一些問題,日誌裏有不少錯誤提示,列在下邊供參考。
日誌報錯以下所示:
level=info ts=2019-11-08T02:43:40.981858805Z caller=main.go:170 msg="Tracing will be disabled" level=info ts=2019-11-08T02:43:40.982326667Z caller=factory.go:39 msg="loading bucket configuration" level=error ts=2019-11-08T02:43:40.982682262Z caller=main.go:200 err="store command failed: create bucket client: create S3 client: initialize s3 client: address http://127.0.0.1:9000: too many colons in address"
日誌描述直譯過來就是冒號太多了,緣由是在配置文件中,填寫了 MinIO 提供的 S3 協議的 endpoint 的時候,多填寫了 http://
,致使提示該錯誤。本意是在內網使用, HTTP 協議就能夠了,不須要要開啓 HTTPS ,可是 Thanos 在鏈接 S3 存儲的時候默認是使用 HTTPS 的,不能經過這種方式來使用 HTTP 。
錯誤的配置以下:
type: S3 config: bucket: "disk1" endpoint: "http://127.0.0.1:9000"
正確的配置以下:
type: S3 config: bucket: "disk1" endpoint: "127.0.0.1:9000"
日誌報錯以下
level=info ts=2019-11-08T02:42:04.366000876Z caller=main.go:170 msg="Tracing will be disabled" level=info ts=2019-11-08T02:42:04.366417674Z caller=factory.go:39 msg="loading bucket configuration" level=info ts=2019-11-08T02:42:04.384413714Z caller=cache.go:172 msg="created index cache" maxItemSizeBytes=131072000 maxSizeBytes=262144000 maxItems=math.MaxInt64 level=error ts=2019-11-08T02:42:04.385632149Z caller=main.go:200 err="store command failed: bucket store initial sync: sync block: iter: Get https://127.0.0.1:9000/prometheus-store/?delimiter=%2F&max-keys=1000&prefix=: http: server gave HTTP response to HTTPS client"
這是 Thanos 鏈接的對象存儲只提供了 HTTP ,沒有提供 HTTPS,這個時候須要讓對象存儲添加證書,啓用 HTTPS 。
日誌報錯以下:
level=info ts=2019-11-08T03:06:57.90508837Z caller=main.go:170 msg="Tracing will be disabled" level=info ts=2019-11-08T03:06:57.905445182Z caller=factory.go:39 msg="loading bucket configuration" level=info ts=2019-11-08T03:06:57.923283984Z caller=cache.go:172 msg="created index cache" maxItemSizeBytes=131072000 maxSizeBytes=262144000 maxItems=math.MaxInt64 level=error ts=2019-11-08T03:06:57.927125234Z caller=main.go:200 err="store command failed: bucket store initial sync: sync block: iter: Get https://10.23.80.18:9000/prometheus-store/?delimiter=%2F&max-keys=1000&prefix=: x509: cannot validate certificate for minio-erdong.site because it doesn't contain any IP SANs"
由於 Thanos 鏈接 Minio 的 HTTP 配置裏,有一個 insecure_skip_verify
選項,該選項默認爲 false ,須要對域名的證書進行驗證,因爲使用了自簽證書,沒有在權威的 CA 機構作認證,因此在鏈接過程當中會提示不安全,將值改成 true,跳過這個驗證就能夠了。
http_config: idle_conn_timeout: 90s response_header_timeout: 2m insecure_skip_verify: true