RustFS 简介 RustFS是使用目前全球最流行的、内存安全的Rust语言开发的 高性能 , 分布式对象存储软件。RustFS 同时具备简单、高效的特点,也是一种高效、开源、自由、可以进行本地私有云部署的对象存储解决方案。RustFS 100% 兼容 S3 协议,使用 Apache2 许可证发行的开源软件。RustFS 使用目前全世界最受欢迎的、内存安全的语言 Rust 语言编写。 它是由全世界优秀的工程师参与并贡献的一款对于商用友好的分布式对象存储产品,RustFS 可以平替非常多非友好开源协议的对象存储产品。
官方网站:
https://rustfs.com.cn/
官方文档:
https://docs.rustfs.com.cn/
一、前置准备 主机要求
已安装 Docker(≥ 20.10)并能正常拉取镜像与运行容器
本地路径 /mnt/rustfs/data(或自定义路径)用于挂载对象数据
网络与防火墙
确保宿主机 9000\9001 端口对外开放(或自定义端口一致)
运行 RustFS 容器 RustFS SNSD Docker 运行方式,结合上述镜像与配置,执行:
1 2 3 4 5 6 7 8 9 mkdir -p /mnt/rustfs && cd /mnt/rustfsmkdir -p data logs chown -R 10001:10001 data logs docker run -d -p 9000:9000 -p 9001:9001 -v /mnt/rustfs/data:/data -v /mnt/rustfs/logs:/logs rustfs/rustfs:latest
各参数说明:
-p 9000:9000:映射宿主机 9000 Endpoint端口到容器
-p 9001:9001:映射宿主机 9001 Console端口到容器
-v /mnt/rustfs/data:/data:挂载数据卷
--name rustfs_local:容器自定义名称
-d:后台运行
完整参数配置示例 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 docker run -d \ --name rustfs_container \ -p 9000 :9000 \ -p 9001 :9001 \ -v /mnt/rustfs/data:/data \ -e RUSTFS_ACCESS_KEY=admin \ -e RUSTFS_SECRET_KEY=修改成你的密码 \ -e RUSTFS_CONSOLE_ENABLE=true \ -e RUSTFS_SERVER_DOMAINS=s3.example.com \ rustfs/rustfs:latest \ --address :9000 \ --console-enable \ --server-domains s3.example.com \ --access-key admin \ --secret-key 修改成你的密码 \ /data
Docker Compose 配置 创建 docker-compose.yml 文件:
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 version : "3.8" services : rustfs : image : rustfs/rustfs:latest container_name : rustfs-server security_opt : - "no-new-privileges:true" ports : - "9000:9000" # S3 API 对外端口 - "9001:9001" # 控制台对外端口 environment : - RUSTFS_VOLUMES=/data/rustfs0 - RUSTFS_ADDRESS=0.0.0.0:9000 - RUSTFS_CONSOLE_ADDRESS=0.0.0.0:9001 - RUSTFS_CONSOLE_ENABLE=true - RUSTFS_CORS_ALLOWED_ORIGINS=* - RUSTFS_CONSOLE_CORS_ALLOWED_ORIGINS=* - RUSTFS_ACCESS_KEY=admin - RUSTFS_SECRET_KEY=改为你的密码 - RUSTFS_OBS_LOGGER_LEVEL=info volumes : - ./deploy/data/pro:/data - ./deploy/logs:/app/logs networks : - rustfs-network restart : unless-stopped healthcheck : test : ["CMD", "sh", "-c", "curl -f http://localhost:9000/health && curl -f http://localhost:9001/health"] interval : 30s timeout : 10s retries : 3 start_period : 40s networks : rustfs-network : driver : bridge ipam : config : - subnet: 172.20.0.0/16
启动服务:
通过 http://localhost:9000 访问,默认用户名和密码均为 rustfsadmin。
反向代理
访问方式 :
S3 API 端:https://s3.example.com (端口 9000)
控制台端:https://console.example.com (端口 9001)
特性 :支持 HTTPS、CORS、健康检查
Nginx 反向代理配置 S3 API 端配置 为 S3 API 创建 Nginx 配置文件(如 /www/server/panel/vhost/nginx/s3.example.com.conf):
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 upstream rustfs { least_conn; server 127.0 .0.1 :9000 ; } server { listen 80 ; listen [::]:80 ; server_name s3.example.com; return 301 https:// $host $request_uri ; } server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name s3.example.com; ssl_certificate /www/ server/panel/ vhost/cert/ s3.example.com/fullchain.pem; ssl_certificate_key /www/ server/panel/ vhost/cert/ s3.example.com/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3 ; ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3 DES:RSA+3 DES:!MD5; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10 m; ssl_session_timeout 10 m; add_header Strict-Transport-Security "max-age=31536000" ; location / { proxy_set_header Host $host ; proxy_set_header X-Real-IP $remote_addr ; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ; proxy_set_header X-Forwarded-Proto $scheme ; proxy_set_header X-Forwarded-Port $server_port ; proxy_set_header X-Forwarded-Host $host ; proxy_cache_convert_head off; proxy_connect_timeout 300 ; proxy_http_version 1.1 ; proxy_set_header Connection "" ; proxy_pass http:// rustfs; } access_log /www/ wwwlogs/s3.example.com.log; error_log /www/ wwwlogs/s3.example.com.error.log; }
控制台端配置 为控制台创建 Nginx 配置文件(如 /www/server/panel/vhost/nginx/console.example.com.conf):
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 upstream rustfs-console { least_conn; server 127.0 .0.1 :9001 ; } server { listen 80 ; listen [::]:80 ; server_name console.example.com; return 301 https:// $host $request_uri ; } server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name console.example.com; ssl_certificate /www/ server/panel/ vhost/cert/ console.example.com/fullchain.pem; ssl_certificate_key /www/ server/panel/ vhost/cert/ console.example.com/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3 ; ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3 DES:RSA+3 DES:!MD5; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10 m; ssl_session_timeout 10 m; add_header Strict-Transport-Security "max-age=31536000" ; location / { proxy_set_header Host $host ; proxy_set_header X-Real-IP $remote_addr ; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ; proxy_set_header X-Forwarded-Proto $scheme ; proxy_set_header X-Forwarded-Port $server_port ; proxy_set_header X-Forwarded-Host $host ; proxy_cache_convert_head off; proxy_connect_timeout 300 ; proxy_http_version 1.1 ; proxy_set_header Connection "" ; proxy_pass http:// rustfs-console; } access_log /www/ wwwlogs/console.example.com.log; error_log /www/ wwwlogs/console.example.com.error.log; }
重载 Nginx 配置:
1 nginx - t && nginx -s reload
测试S3 这里使用S3cmd
S3cmd 是一个用于操作 Amazon S3 和其他兼容 S3 的云存储服务的命令行工具。它提供了广泛的命令,允许用户上传、下载、同步和管理存储在 S3 上的文件。
使用包管理器安装 在大多数 Linux 发行版中,您可以使用包管理器来安装 S3cmd。以下是在几种常见 Linux 发行版上安装 S3cmd 的命令。
对于基于 Debian 的系统(如 Ubuntu),您可以使用 apt-get:
1 2 sudo apt-get updatesudo apt-get install s3cmd
对于基于 Red Hat 的系统(如 CentOS),您可以使用 yum:
对于基于 Arch Linux 的系统,您可以使用 pacman:
配置 S3cmd 在安装完 S3cmd 之后,您需要对其进行配置,以便连接到您的 S3 存储服务。配置 S3cmd 涉及设置您的 AWS 访问密钥 ID 和秘密访问密钥,这些是您在 AWS 账户中创建的访问权限凭证。
运行配置向导 最简单的方法是运行 S3cmd 的配置向导。在命令行中输入以下命令:
该命令将启动一个交互式配置程序,提示您输入所需的配置信息,包括:
S3 服务端点(写入s3.example.com)
访问密钥 ID
秘密访问密钥
默认存储桶名称
是否使用 HTTPS
是否启用服务端加密等
参考
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 root@iv-ydya2ilgcgqc6ilqbabf:~# s3cmd Enter new values or accept defaults in brackets with Enter. Refer to user manual for detailed description of all options.Access key and Secret key are your identifiers for Amazon S3. Leave them empty for using the env variables.Access Key: admin Secret Key: passwdDefault Region [US]:Use "s3.amazonaws.com" for S3 Endpoint and not modify it to the target Amazon S3. S3 Endpoint [s3.amazonaws.com]: s3.xxx.cnUse "%(bucket)s.s3.amazonaws.com" to the target Amazon S3. "%(bucket)s" and "%(location)s" vars can be usedif the target S3 system supports dns based buckets. DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.s3.amazonaws.com]: Encryption password is used to protect your files from reading by unauthorized persons while in transfer to S3 Encryption password: passwd Path to GPG program [/usr/bin/gpg]:When using secure HTTPS protocol all communication with Amazon S3 servers is protected from 3 rd party eavesdropping. This method is slower than plain HTTP, and can only be proxied with Python 2.7 or newerUse HTTPS protocol [Yes]:On some networks all internet access must go through a HTTP proxy. Try setting it here if you can't connect to S3 directly HTTP Proxy server name:New settings: Access Key: admin Secret Key: passwd Default Region: US S3 Endpoint: s3.quickso.cn DNS-style bucket+hostname:port template for accessing a bucket: %(bucket)s.s3.amazonaws.com Encryption password: passwd Path to GPG program: /usr/bin/gpg Use HTTPS protocol: True HTTP Proxy server name: HTTP Proxy server port : 0 Test access with supplied credentials? [Y/n] y Please wait , attempting to list all buckets... Success. Your access key and secret key worked fine :-) Now verifying that encryption works... Success. Encryption and decryption worked fine :-) Save settings? [y/N] yConfiguration saved to '/root/.s3cfg' root@iv-ydya2ilgcgqc6ilqbabf:~# s3cmd ls2025 -12 -27 01 :19 s3://test
出于安全考虑,您的配置文件应该只有您自己能够读写。设置适当的文件权限可以使用以下命令:
这样,您就完成了 S3cmd 的基本配置,可以开始使用它来管理您的 S3 存储桶了
基本命令与操作 S3cmd 提供了一系列命令,用于执行与 Amazon S3 存储桶相关的各种操作。以下是一些常用的 S3cmd 命令及其基本用法。
1 列出存储桶 要列出所有可用的存储桶,可以使用以下命令:
这将显示您有权访问的所有存储桶的列表。
2 上传文件 要将文件上传到存储桶,使用以下命令:
1 s3cmd put /path/to/your/file s3://bucket-name/file-name
请将 /path/to/your/file 替换为您要上传的文件的本地路径,将 bucket-name 替换为您的 S3 存储桶名称,将 file-name 替换为您希望文件在 S3 上保存的名称。
3 下载文件 要从存储桶下载文件,使用以下命令:
1 s3cmd get s3://bucket-name/file-name /path/to/your/local/directory
请将 bucket-name 和 file-name 替换为存储桶名称和文件名称,将 /path/to/your/local/directory 替换为您希望保存下载文件的本地路径。
4 删除文件 要删除存储桶中的文件,使用以下命令:
1 s3cmd rm s3://bucket-name/file-name
请确保在执行此操作之前正确地确认了文件名称,因为此操作是不可逆的。
5 同步文件 S3cmd 的同步功能允许您同步本地目录与 S3 存储桶中的内容。以下是如何使用该命令的示例:
1 s3cmd sync /path/to/your/local/directory s3://bucket-name/
这个命令会检查本地目录和 S3 存储桶中的文件,并根据需要上传或下载文件以保持同步。
6 查看文件信息 要查看存储在 S3 上的文件的元数据,可以使用以下命令:
1 s3cmd info s3://bucket-name/file-name
这将显示关于指定文件的信息,包括其大小、存储类、ETag 等。
通过掌握这些基本命令,您可以开始有效地管理您的 S3 存储桶中的文件。S3cmd 还有更多高级功能,如批量删除、复制对象、设置权限等,可以通过查阅官方文档来了解这些高级用法。