Self-Hosted AI Assistant Deployment Guide for Ubuntu 24.04: OpenClaw Integration with Large Language Models

    This guide provides a step-by-step implementation for deploying a self-hosted AI assistant using OpenClaw on Ubuntu 24.04, covering system requirements, security configurations, and integration with large language models. Developers will learn to establish a stable AI service infrastructure with modular architecture and cross-platform access capabilities.

    Technical Architecture and Core Advantages

    OpenClaw serves as an open-source AI assistant platform featuring modular architecture that supports multiple large language models through standardized APIs. Key capabilities include:

    • Multi-model Support: Unified interface for different vendor APIs
    • Security Isolation: Private deployment with local data storage
    • Extensibility: Plugin system for custom functionality
    • Cross-platform Access: Secure internal service exposure via SSH tunneling

    Ubuntu 24.04 LTS provides the foundation with long-term support, combined with Node.js runtime for stable AI service deployment.

    System Preparation and Security

    Server Requirements

    • Hardware: 4-core CPU with 8GB RAM (minimum for basic models)
    • OS: Ubuntu 24.04 LTS (kernel ≥5.15 required)
    • Network: Static public IP or NAT solution with ports 22 (SSH) and 3000 (Web) open

    Security Implementation

    1. User Management:
      ```bash

      Create dedicated user with sudo privileges

      adduser aiadmin
      usermod -aG sudo aiadmin

    Disable root SSH access (/etc/ssh/sshd_config)

    PermitRootLogin no

    1. 2. **Firewall Configuration**:
    2. ```bash
    3. # Basic UFW rules
    4. apt install ufw
    5. ufw allow 22/tcp
    6. ufw allow 3000/tcp
    7. ufw enable
    1. Credential Management:
    • Store API keys in cloud KMS services
    • Use environment variables instead of hardcoding

    Node.js Environment Setup

    Version Selection

    OpenClaw recommends Node.js 22 LTS for:

    • Maintenance support until April 2027
    • V8 engine optimizations
    • npm ecosystem compatibility

    Installation via NVM

    1. # Install build dependencies
    2. apt update && apt install -y curl git build-essential
    3. # Deploy NVM
    4. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    5. source ~/.bashrc
    6. # Verify installation
    7. command -v nvm
    8. # Install Node.js 22
    9. nvm install 22
    10. nvm alias default 22
    11. # Validate versions
    12. node -v # Should show v22.x.x
    13. npm -v # Should show 10.x.x+

    Troubleshooting

    1. Permission Errors:

      1. # Fix npm global directory permissions
      2. mkdir ~/.npm-global
      3. npm config set prefix '~/.npm-global'
      4. echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
      5. source ~/.bashrc
    2. Network Issues:

      1. # Configure npm mirror
      2. npm config set registry https://registry.npmmirror.com

    OpenClaw Deployment

    Global Installation

    1. npm install -g openclaw@latest
    2. openclaw --version # Should return version like 2026.3.2
    3. mkdir -p ~/ai-assistant && cd ~/ai-assistant

    Configuration Wizard

    1. openclaw config

    Key settings:

    1. Provider Configuration:

      • Select “Add custom provider”
      • Enter name (e.g., zhipu-glm)
      • API endpoint: https://open.bigmodel.cn/api/paas/v4
      • Authentication: API Key
    2. Service Configuration:

      • Web port: 3000
      • Session timeout: 3600s
      • Log level: info for production

    Service Activation

    1. # Start in background
    2. nohup openclaw start --port 3000 > openclaw.log 2>&1 &
    3. # Verify status
    4. curl http://localhost:3000/health
    5. # Should return {"status":"ok"}

    Secure Access Implementation

    SSH Port Forwarding

    1. # Linux/macOS terminal
    2. ssh -N -L 3000:localhost:3000 aiadmin@your-server-ip
    3. # Windows PowerShell
    4. ssh -N -L 3000:localhost:3000 aiadmin@your-server-ip

    Browser Access

    1. Visit http://localhost:3000
    2. Complete initial setup:
      • Create admin account
      • Configure default model routing
      • Set session security policies

    Production Enhancements

    1. Nginx Reverse Proxy:

      1. server {
      2. listen 80;
      3. server_name ai.example.com;
      4. location / {
      5. proxy_pass http://localhost:3000;
      6. proxy_set_header Host $host;
      7. proxy_set_header X-Real-IP $remote_addr;
      8. }
      9. }
    2. HTTPS Encryption:

    • Use Let’s Encrypt certificates
    • Configure automatic renewal
    1. Access Control:
    • Integrate cloud IAM systems
    • Implement IP whitelisting

    Monitoring System Construction

    Log Management

    1. Log Rotation (/etc/logrotate.d/openclaw):

      1. /home/aiadmin/ai-assistant/openclaw.log {
      2. daily
      3. missingok
      4. rotate 7
      5. compress
      6. delaycompress
      7. notifempty
      8. create 644 aiadmin aiadmin
      9. }
    2. Centralized Logging:

    • Configure rsyslog forwarding to cloud services
    • Set up anomaly alerts

    Performance Metrics

    Key indicators:

    • Node.js CPU usage
    • Memory consumption (RSS/Heap)
    • Network throughput
    • API response latency (P99)

    Recommended tools:

    • Prometheus + Grafana (open-source)
    • Cloud-managed monitoring services

    Plugin Development Guide

    Structure Specification

    1. plugins/
    2. ├── my-plugin/
    3. │ ├── index.js # Main entry
    4. │ ├── config.json # Metadata
    5. │ └── README.md # Documentation

    Lifecycle Hooks

    1. module.exports = {
    2. async onLoad(context) {
    3. console.log('Plugin loaded');
    4. },
    5. async onMessage(message, context) {
    6. // Message processing logic
    7. return message;
    8. }
    9. };

    Model Routing Strategies

    Dynamic routing based on:

    • User context (e.g., user ID)
    • Model load status
    • Cost optimization
    • Custom scoring algorithms

    Example configuration:

    1. {
    2. "routes": [
    3. {
    4. "condition": "user.role == 'premium'",
    5. "model": "zhipu-glm-pro"
    6. },
    7. {
    8. "condition": "true",
    9. "model": "zhipu-glm-flash"
    10. }
    11. ]
    12. }

    Troubleshooting Guide

    Model Call Failures

    1. Diagnostic Process:

      • Verify API key validity
      • Check network connectivity (curl -v https://open.bigmodel.cn)
      • Review OpenClaw logs (tail -f openclaw.log)
    2. Common Errors:

      • 401 Unauthorized: Check API key
      • 429 Too Many Requests: Adjust concurrency limits
      • 500 Internal Error: Contact model provider

    Performance Optimization

    1. Node.js Tuning:
      ```bash

      Increase file descriptor limit

      ulimit -n 65536

    Adjust memory parameters

    export NODE_OPTIONS=”—max-old-space-size=4096”

    1. 2. **Connection Pooling**:
    2. ```json
    3. {
    4. "http": {
    5. "agent": {
    6. "maxSockets": 100,
    7. "maxFreeSockets": 10
    8. }
    9. }
    10. }

    This deployment framework provides a complete implementation path for self-hosted AI assistants. Adapt model configurations and access controls based on specific business requirements, and maintain system stability through regular dependency updates and security monitoring.