Skip to main content

NFS Share + RustFS Docker Deployment

In this tutorial we will explain how you setup your own RustsFS S3 Storage. This will allow you to use S3 storage for self hosted applications that allow or require it. It is yet another way of storing photos and videos but instead of using an NFS share or local storage. Now, ideally you setup a dedicated box with hard drives to run your RustFS instance. However, in a HomeLab that is not always feasible nor necessary. The beauty of RustFS is that it just needs a folder to store all the objects in. Therefor, if you already have an NAS or NAS VM you could create an NFS share and attach it to that folder. This is what we will do in this tutorial 

Setup the NFS Share 

1. The first thing we need to do on your TrueNas instance is create a new user: 1001 and group 1001. The reason for this is because RustFS runs on this user and group and hence the objects folder /mnt/rustfs needs to be owned by that user and group. For instructions check out our TrueNas Book 

2. Then create a new dataset and attach the user 1001 and group 1001 to it

3. Then setup the NFS share on your TrueNas instance.

4. Sweet, now you setup on TrueNas is set and done. Now, you will enter either your DockerVM or a new dedicated VM to run your RustFS instance on. Regardless we first make a new folder

mkdir rustfs

5. We then make the data directory that will store all the objects with. You can choose any location and name but for this example we will use

mkdir /mnt/rustfs

6. Next make sure that an NFS-Client is installed and if not it is easy to install with

sudo apt install nfs-common

7. Perfect, now attach the NFS share to the /mnt/rustfs folder by adding a new entry in the /etc/fstab section

sudo nano /etc/fstab

8. Then add the following line

IP-Address-TrueNasVM:/mnt/tank/rustfs /mnt/rustfs  nfs  defaults 0 0

9. Alrightieee!!! NFS and Storage folder is all setup, then now we can move to the Docker compose file

Docker Compose File

Below the simple docker compose file of RustFS is provided. Where simple means that it is only rustfs and not all extra add-ons to measure the performance and maintain the instance e.g Prometheus etcetera. This file can be obtained at their repository page. Do note that the Github version sets 4 folders whereas we only use one folder called rustfs. This is because we have the redundancy already embedded in the NFS share. 

compose.yml
services:
  rustfs:
    image: rustfs/rustfs:latest
    container_name: rustfs
    volumes:
      - /mnt/rustfs:/data
      - ./logs:/app/logs
    environment:
      - RUSTFS_VOLUMES=/data
      - RUSTFS_ADDRESS=0.0.0.0:9000
      - RUSTFS_CONSOLE_ADDRESS=0.0.0.0:9001
      - RUSTFS_CONSOLE_ENABLE=true
      # Without this, logs go to stdout and ./logs stays empty
      - RUSTFS_OBS_LOG_DIRECTORY=/app/logs
      - RUSTFS_ACCESS_KEY=${RUSTFS_ACCESS_KEY:?set_a_non_default_access_key}
      - RUSTFS_SECRET_KEY=${RUSTFS_SECRET_KEY:?set_a_non_default_secret_key}
    ports:
      - "9000:9000"
      - "9001:9001"
    healthcheck:
      test: ["CMD", "sh", "-c", "curl -f http://10.69.4.90:9000/health && curl -f http://10.69.4.90:9001/rustfs/console/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: "2.0"
          memory: 4GB

Things to Note in this compose file

1. The location of your data folder. In this example it is located at /mnt/rustfs which is again mounted to the NFS share. Change this if your object storage folder is located somewhere else

2. You can choose the port you want to host your RustFS instance on, by default this is 9001

3. The second things is to have localhost in he healthcheck test changed to your VM's IP address e.g 10.50.20.20

That's all for the compose file

Environment Variables File

Then the compose file is pretty simple as it only requires two entries

.env
RUSTFS_ACCESS_KEY=A37045B70F04225A2EC24718
RUSTFS_SECRET_KEY=wIc1icWwzBoUoJlO752fW/13/aq3EHUfXj5trcR9QUE=

Access Key can be generated with: openssl rand -hex 12 | tr 'a-f' 'A-F' 

SECRET_KEY can be generated with: openssl rand -base64 32

Domain Name

If you have an application that needs to be accessible over the internet or want other people make use of your S3 instance then you need to add a public domain name to your instance. In the case of Caddy on your OPNSense router that is simply adding the domain name and point it to your VM where RustFS is running on and the port your have set, which by default is 9001

Deploy

Then you can simply deploy the compose stack with 

docker compose up -d

After you have deployed it and your services are healthy then you should be able to access it via the domain name you have set for your RustFS instance. 

First Time Login

The first time you enter the RustFS Dashboard you need to login with the ACCESS and SECRET keys you have set in your .env file 

Account: ACCESS_KEY

\

Key: SECRET_KEY

 

dpasn@sandbox:~$ sudo chown dpasn:dpasn -R /mnt
dpasn@sandbox:~$ sudo chmod 775 -R /mnt
dpasn@sandbox:~$ mkdir /mnt/rustfs

Make sure NFS Client is installed with