Prerequisites #
I use two Ubuntu 22.04 servers in this tutorial:
# SeaweedFS Server
192.168.30.90
# S3 CLI Client
192.168.30.91
SeaweedFS Docker Compose #
Folder Structure #
# Create folder structure
sudo mkdir -p /opt/seaweedfs/data/{filer,master0,volume1,volume2,volume3} && cd /opt/seaweedfs
# Set permissions
sudo chmod -R 755 /opt/seaweedfs/data
Environment File #
# Create environment file
sudo vi .env
#.env
AWS_ACCESS_KEY_ID=acces-key-123
AWS_SECRET_ACCESS_KEY=secret-key-123
Create Docker Compose file #
# Create Docker Compose file
sudo vi docker-compose.yml
Docker Compose File #
SeaweedFS Docker Compose Stack with 3 volume servers.
# docker-compose.yml
version: '3.9'
services:
# Master
master0:
image: chrislusf/seaweedfs
ports:
- 9333:9333
- 19333:19333
command: "-v=1 master -volumeSizeLimitMB 100 -resumeState=false -ip=master0 -ip.bind=0.0.0.0 -port=9333 -mdir=/var/lib/seaweedfs/master"
volumes:
- ./data/master0:/var/lib/seaweedfs/master
restart: unless-stopped
# Volume Server 1
volume1:
image: chrislusf/seaweedfs
ports:
- 8081:8081
- 18080:18080
command: 'volume -dataCenter=dc1 -rack=v1 -mserver="master0:9333" -port=8081 -preStopSeconds=1 -dir=/var/lib/seaweedfs/volume1'
volumes:
- ./data/volume1:/var/lib/seaweedfs/volume1
depends_on:
- master0
restart: unless-stopped
# Volume Server 2
volume2:
image: chrislusf/seaweedfs
ports:
- 8082:8082
- 18082:18082
command: 'volume -dataCenter=dc2 -rack=v2 -mserver="master0:9333" -port=8082 -preStopSeconds=1 -dir=/var/lib/seaweedfs/volume2'
volumes:
- ./data/volume2:/var/lib/seaweedfs/volume2
depends_on:
- master0
restart: unless-stopped
# Volume Server 3
volume3:
image: chrislusf/seaweedfs
ports:
- 8083:8083
- 18083:18083
command: 'volume -dataCenter=dc3 -rack=v3 -mserver="master0:9333" -port=8083 -preStopSeconds=1 -dir=/var/lib/seaweedfs/volume3'
volumes:
- ./data/volume3:/var/lib/seaweedfs/volume3
depends_on:
- master0
restart: unless-stopped
# Filer
filer:
image: chrislusf/seaweedfs
ports:
- 8888:8888
- 18888:18888
command: 'filer -defaultReplicaPlacement=100 -iam -master="master0:9333"'
volumes:
- ./data/filer:/data
depends_on:
- master0
- volume1
- volume2
restart: unless-stopped
# S3 API
s3:
image: chrislusf/seaweedfs
ports:
- 8333:8333
command: '-v=9 s3 -filer="filer:8888" -ip.bind=0.0.0.0'
env_file:
- .env
depends_on:
- master0
- volume1
- volume2
- filer
restart: unless-stopped
Start Container #
# Create / start Docker stack
sudo docker compose up -d
Reverse Proxy for S3 API #
Nginx Setup #
# Update package index
sudo apt update
# Install nginx
sudo apt install nginx -y
Nginx Virtual Host #
# Copy default config
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/seaweedfs.jklug.work
# Edit config
sudo vi /etc/nginx/sites-available/seaweedfs.jklug.work
# seaweedfs.jklug.work
server {
listen 443 ssl;
server_name seaweedfs.jklug.work;
ssl_certificate /etc/letsencrypt/live/seaweedfs.jklug.work/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/seaweedfs.jklug.work/privkey.pem;
# S3 API
location / {
proxy_pass http://localhost:8333;
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;
}
}
# Disable default config
sudo rm /etc/nginx/sites-enabled/default
# Enable config
sudo ln -s /etc/nginx/sites-available/seaweedfs.jklug.work /etc/nginx/sites-enabled/
# Restart Nginx
sudo systemctl restart nginx
Seaweed FS #
Webinterface #
# SeaweedFS Master Dashboard
192.168.30.90:9333
# SeaweedFS Filer: Upload & download files
192.168.30.90:8888
S3 API #
# S3 API: With reverse proxy
seaweedfs.jklug.work
# S3 API: Without reverse proxy
192.168.30.90:8333
Install AWS CLIv2 #
# Install Unzip
sudo apt install unzip -y
# Change directory
cd /tmp
# Download AWS CLIv2
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
# Unzip
unzip awscliv2.zip
# Install package
sudo ./aws/install
# Test / check version
aws --version
Add Access keys #
# Add keys
aws configure
# Shell output
AWS Access Key ID [None]: acces-key-123 # Define access key
AWS Secret Access Key [None]: secret-key-123 # Define Secret access key
Default region name [None]:
Default output format [None]: json
Create S3 Bucket #
- With Reverse Proxy
# Create new Bucket: "jkw-bucket-1"
aws s3 mb s3://jkw-bucket-1 --endpoint-url https://seaweedfs.jklug.work
- Without Reverse Proxy
# Create new Bucket: "jkw-bucket-1"
aws s3 mb s3://jkw-bucket-1 --endpoint-url http://192.168.30.90:8333
- Shell Output
# Shell output:
make_bucket: jkw-bucket-1
Copy File into Bucket #
- With Reverse Proxy
# Copy file into Bucket
aws s3 cp /home/ubuntu/file1.txt s3://jkw-bucket-1/ --endpoint-url https://seaweedfs.jklug.work
- Without Reverse Proxy
# Copy file into Bucket
aws s3 cp /home/ubuntu/file1.txt s3://jkw-bucket-1/ --endpoint-url http://192.168.30.90:8333
- Check SeaweedFS Filer: The uploaded file should be available now
- Check SeaweedFS Dashboard: Some Volumes should be available now
Copy Files from Bucket #
- With Reverse Proxy
# Copy files from Bucket into current directory
aws s3 cp --recursive s3://jkw-bucket-1/ --endpoint-url https://seaweedfs.jklug.work .
- Without Reverse Proxy
# Copy files from Bucket into current directory
aws s3 cp --recursive s3://jkw-bucket-1/ --endpoint-url http://192.168.30.90:8333 .
List Files in Bucket #
- With Reverse Proxy
# Copy file in Bucket
aws s3 ls s3://jkw-bucket-1/ --endpoint-url https://seaweedfs.jklug.work
- Without Reverse Proxy
# Copy file in Bucket
aws s3 ls s3://jkw-bucket-1/ --endpoint-url http://192.168.30.90:8333
- Shell Output
# Shell output:
2024-01-07 13:29:45 22 file1.txt