This tutorial will guide you through the process of setting up and configuring the server functionality of the RFS command, which provides a REST API and web interface for managing flists.
Before you begin, make sure you have:
- RFS installed (see the Getting Started tutorial)
- Basic understanding of server configuration
- A machine with sufficient resources (CPU, RAM, storage)
- Network connectivity for the server
The server functionality of the RFS command provides:
- A REST API for managing flists
- User authentication and authorization
- Docker image to flist conversion
- Flist storage and retrieval
- Integration with the web frontend
First, create a configuration file for the server. Create a file named config.toml with the following content:
host = "localhost"
port = 3000
store_url = ["dir:///tmp/store0"]
flist_dir = "flists"
jwt_secret = "your-secret-key"
jwt_expire_hours = 5
[[users]]
username = "admin"
password = "admin-password"
[[users]]
username = "user1"
password = "user1-password"Customize the configuration:
host: The hostname or IP address to bind toport: The port to listen onstore_url: A list of storage backends to useflist_dir: The directory to store flists injwt_secret: A secret key for JWT token generationjwt_expire_hours: The lifetime of JWT tokens in hoursusers: A list of authorized users with usernames and passwords
Create the directory structure for storing flists:
# Create the main flists directory
mkdir -p flists
# Create subdirectories for each user
mkdir -p flists/admin flists/user1If you're using a directory store, create the directory:
mkdir -p /tmp/store0Run the server using the configuration file:
rfs server --config-path config.tomlFor debugging, you can add the --debug flag:
rfs server --config-path config.toml --debugThe server should start and listen on the configured port.
For production use, you'll typically want to use a remote storage backend:
# Using a ZDB backend
store_url = ["zdb://zdb.example.com:9900/namespace"]
# Using an S3 backend
store_url = ["s3://username:password@s3.example.com:9000/bucket"]You can configure multiple storage backends for sharding or replication:
# Sharding across two stores
store_url = [
"00-80=dir:///tmp/store1",
"81-ff=dir:///tmp/store2"
]
# Using multiple backend types
store_url = [
"dir:///tmp/store0",
"zdb://zdb.example.com:9900/namespace",
"s3://username:password@s3.example.com:9000/bucket"
]For production use, you should configure HTTPS. The RFS server doesn't directly support HTTPS, but you can use a reverse proxy like Nginx or Caddy:
Create a Caddyfile:
rfs.example.com {
reverse_proxy localhost:3000
}
Run Caddy:
caddy runCreate an Nginx configuration:
server {
listen 443 ssl;
server_name rfs.example.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}Reload Nginx:
nginx -s reloadFor production use, you'll want to run the RFS server as a service.
Create a systemd service file at /etc/systemd/system/rfs-server.service:
[Unit]
Description=RFS Server
After=network.target
[Service]
ExecStart=/usr/local/bin/rfs server --config-path /etc/rfs-server/config.toml
WorkingDirectory=/var/lib/rfs-server
User=rfs-server
Group=rfs-server
Restart=always
[Install]
WantedBy=multi-user.targetCreate the necessary directories and user:
# Create the user
sudo useradd -r -s /bin/false rfs-server
# Create the directories
sudo mkdir -p /etc/rfs-server /var/lib/rfs-server/flists
# Copy the configuration
sudo cp config.toml /etc/rfs-server/
# Set permissions
sudo chown -R rfs-server:rfs-server /etc/rfs-server /var/lib/rfs-serverEnable and start the service:
sudo systemctl enable rfs-server
sudo systemctl start rfs-serverYou can also deploy the RFS server using Docker.
The RFS repository includes a Dockerfile for the server:
# Build the Docker image
docker build -t rfs-server -f Dockerfile .
# Run the container
docker run -d \
-p 3000:3000 \
-v $(pwd)/config.toml:/app/config.toml \
-v $(pwd)/flists:/app/flists \
-v /tmp/store0:/tmp/store0 \
--name rfs-server \
rfs-serverCreate a docker-compose.yml file:
version: '3'
services:
rfs-server:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
volumes:
- ./config.toml:/app/config.toml
- ./flists:/app/flists
- /tmp/store0:/tmp/store0
restart: alwaysRun with Docker Compose:
docker-compose up -dThe RFS server serves a web interface that provides a graphical user interface for managing flists.
Once the server is running, you can access the frontend by opening a web browser and navigating to the server URL:
http://localhost:3000
- Log in using one of the configured user accounts.
- Use the interface to:
- Create flists from Docker images
- View and manage your flists
- Download flists
Open a web browser and navigate to:
http://localhost:3000
Log in using one of the configured user accounts.
Try creating a flist from a Docker image:
- Click on "Create Flist"
- Enter a Docker image name (e.g.,
alpine:latest) - Click "Create"
- Click on "My Flists"
- View the list of your flists
- Click on a flist to preview or download it
If the server won't start, check:
-
Configuration File: Ensure the configuration file is valid TOML
# Validate the TOML file cat config.toml | python3 -c "import tomli; import sys; tomli.loads(sys.stdin.read())"
-
Permissions: Ensure the server has permission to access the directories
# Check permissions ls -la flists /tmp/store0 -
Port Availability: Ensure the configured port is available
# Check if the port is in use netstat -tuln | grep 3000
If you can't log in:
- User Configuration: Ensure the user is correctly configured in
config.toml - JWT Secret: Ensure the JWT secret is set and consistent
- Server Logs: Check the server logs for authentication errors
If Docker conversion fails:
- Docker Availability: Ensure Docker is installed and running
- Image Accessibility: Ensure the Docker image is accessible
- Storage Space: Ensure there's sufficient storage space
Now that you have the RFS server set up, you might want to learn: