Trong bài trước, mình đã giới thiệu về OxiCloud - alternative nhẹ cho Nextcloud viết bằng Rust. Bài này sẽ hướng dẫn chi tiết từng bước cài đặt và sử dụng.
Yêu cầu hệ thống
Trước khi bắt đầu, đảm bảo bạn có:
| Yêu cầu | Version |
|---|---|
| Rust & Cargo | 1.70+ |
| PostgreSQL | 13+ |
| RAM | 512MB minimum (1GB+ recommended) |
| OS | Linux, macOS, hoặc Windows với WSL |
Bước 1: Cài đặt Prerequisites
Cài Rust
# Cài Rust qua rustup (official installer)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Reload shell
source $HOME/.cargo/env
# Verify
rustc --version
cargo --version
Cài PostgreSQL
Ubuntu/Debian:
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
sudo systemctl enable postgresql
macOS (Homebrew):
brew install postgresql@15
brew services start postgresql@15
Arch Linux:
sudo pacman -S postgresql
sudo systemctl start postgresql
sudo systemctl enable postgresql
Bước 2: Tạo Database
# Login vào PostgreSQL
sudo -u postgres psql
# Tạo user và database
CREATE USER oxicloud WITH PASSWORD 'your_secure_password';
CREATE DATABASE oxicloud OWNER oxicloud;
GRANT ALL PRIVILEGES ON DATABASE oxicloud TO oxicloud;
# Thoát
\q
Bước 3: Clone và Build OxiCloud
# Clone repository
git clone https://github.com/DioCrafts/oxicloud.git
cd oxicloud
# Tạo file .env với database connection
echo "DATABASE_URL=postgres://oxicloud:your_secure_password@localhost/oxicloud" > .env
# Build project (release mode cho performance tối ưu)
cargo build --release
Note: Build lần đầu sẽ mất 5-10 phút tùy máy vì Rust compile từ source.
Bước 4: Chạy Database Migrations
# Chạy migrations để tạo tables
cargo run --bin migrate --features migrations
Nếu thành công, bạn sẽ thấy output như:
Running migrations...
Migration 001_initial complete
Migration 002_users complete
All migrations completed successfully!
Bước 5: Khởi động Server
# Chạy server (release mode)
cargo run --release
Server sẽ chạy tại: http://localhost:8085
Mở browser và truy cập để thấy giao diện OxiCloud.
Cấu hình nâng cao
Thay đổi Port
Tạo hoặc sửa file config.toml:
[server]
host = "0.0.0.0"
port = 8085
[database]
url = "postgres://oxicloud:password@localhost/oxicloud"
[storage]
path = "./data"
Chạy với Debug Logs
RUST_LOG=debug cargo run --release
Hữu ích khi troubleshooting.
Chạy như Background Service
Sử dụng systemd (Linux):
Tạo file /etc/systemd/system/oxicloud.service:
[Unit]
Description=OxiCloud Server
After=network.target postgresql.service
[Service]
Type=simple
User=oxicloud
WorkingDirectory=/opt/oxicloud
ExecStart=/opt/oxicloud/target/release/oxicloud
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Sau đó:
sudo systemctl daemon-reload
sudo systemctl enable oxicloud
sudo systemctl start oxicloud
Sử dụng cơ bản
Upload Files
- Truy cập http://localhost:8085
- Click nút Upload hoặc kéo thả files
- Files được lưu trong thư mục
./data
Tạo Folders
- Click nút New Folder
- Đặt tên và confirm
Di chuyển/Xóa Files
- Di chuyển: Kéo thả hoặc right-click → Move
- Xóa: Right-click → Delete (files vào Trash nếu có)
Troubleshooting
Lỗi "Connection refused" khi kết nối PostgreSQL
# Kiểm tra PostgreSQL đang chạy
sudo systemctl status postgresql
# Kiểm tra pg_hba.conf cho phép local connections
sudo nano /etc/postgresql/15/main/pg_hba.conf
# Đảm bảo có dòng: local all all md5
Lỗi "Permission denied" khi build
# Đảm bảo có quyền write
sudo chown -R $USER:$USER ./oxicloud
Build quá chậm
Sử dụng cargo build (debug mode) thay vì --release khi develop. Release build slow hơn nhưng binary nhanh hơn.
Kết luận
OxiCloud setup khá straightforward nếu bạn đã quen với Rust ecosystem. Key takeaways:
- PostgreSQL là required - không có SQLite option
- Build time lâu lần đầu vì compile từ source
- Port 8085 là default
- 512MB RAM là đủ cho personal use
Chúc bạn cài đặt thành công! 🦀
Links:
Discussion