Deploying a Self-Hosted AI Assistant on Ubuntu 24.04: Complete Guide to Integrating Chinese Large Language Models

    This guide provides step-by-step instructions for deploying a self-hosted AI assistant on Ubuntu 24.04 LTS, covering system requirements, Node.js setup, model integration, security configurations, and performance optimization for enterprise-grade deployments.

    System Requirements and Prerequisites

    Hardware Specifications

    • Ubuntu 24.04 LTS with root/sudo privileges
    • Minimum 4-core CPU, 8GB RAM, and 50GB disk space
    • Update system packages:
      1. sudo apt update && sudo apt upgrade -y

    Model Service Credentials

    1. Register with a Chinese LLM platform (e.g., Zhipu AI)
    2. Create new application in console
    3. Obtain API Key and endpoint URL
    4. Record model version (e.g., GLM-4.7-Flash)

    Network Configuration

    Open required ports in security groups:

    • 3000 (Web service)
    • 22 (SSH)
    • 443 (HTTPS, optional)

    Node.js Environment Setup

    Version Management

    Install NVM for multi-version control:

    1. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    2. source ~/.bashrc

    LTS Version Installation

    1. nvm install 22
    2. nvm alias default 22
    3. node -v # Verify v22.x.x
    4. npm -v # Verify npm version

    Environment Optimization

    1. Configure npm registry mirror:
      1. npm config set registry https://registry.npmmirror.com
    2. Set global installation path:
      1. mkdir ~/.npm-global
      2. npm config set prefix '~/.npm-global'
      3. echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
      4. source ~/.bashrc

    AI Assistant Platform Deployment

    Global Installation

    1. npm install -g openclaw@latest --unsafe-perm

    Troubleshooting:

    • ENOTEMPTY error: Clean残留 files and retry
    • Permission issues: Use --unsafe-perm or sudo
    • Network timeout: Configure npm proxy

    Version Management

    1. openclaw --version # Check current version
    2. npm update -g openclaw # Upgrade to latest

    Large Model Integration

    Interactive Configuration

    1. openclaw config

    Configuration parameters:

    • Provider Name: Custom identifier (e.g., zhipu-glm)
    • API Endpoint: Model service URL
    • Authentication: API Key method
    • Model Selection: Specify GLM-4.7-Flash

    Advanced Configuration

    Edit ~/.openclaw/config.json:

    1. {
    2. "providers": {
    3. "zhipu": {
    4. "maxTokens": 4096,
    5. "temperature": 0.7,
    6. "timeout": 30000
    7. }
    8. }
    9. }

    Secure Access Solutions

    SSH Tunneling

    1. ssh -N -L 3000:localhost:3000 username@server_ip

    Access via http://localhost:3000

    Nginx Reverse Proxy (Production)

    1. server {
    2. listen 443 ssl;
    3. server_name ai.example.com;
    4. ssl_certificate /path/to/cert.pem;
    5. ssl_certificate_key /path/to/key.pem;
    6. location / {
    7. proxy_pass http://localhost:3000;
    8. proxy_set_header Host $host;
    9. proxy_set_header X-Real-IP $remote_addr;
    10. }
    11. }

    Access Control

    1. Generate credentials:
      1. sudo apt install apache2-utils
      2. sudo htpasswd -c /etc/nginx/.htpasswd admin
    2. Nginx configuration:
      1. location / {
      2. auth_basic "Restricted Area";
      3. auth_basic_user_file /etc/nginx/.htpasswd;
      4. proxy_pass http://localhost:3000;
      5. }

    Operations Management

    Service Monitoring

    1. journalctl -u openclaw -f # View logs
    2. systemctl status openclaw # Check status
    3. systemctl restart openclaw # Restart service

    Performance Optimization

    1. Concurrency control: Modify concurrency in config.json
    2. Memory management: Set NODE_OPTIONS="--max-old-space-size=8192"
    3. Log rotation: Configure logrotate for application logs

    Backup Strategy

    1. tar -czvf openclaw_backup_$(date +%Y%m%d).tar.gz ~/.openclaw

    Advanced Features

    Multi-Model Routing

    1. {
    2. "routing": {
    3. "default": "zhipu",
    4. "rules": [
    5. {
    6. "pattern": "^/translate/",
    7. "provider": "translation_model"
    8. }
    9. ]
    10. }
    11. }

    Custom Plugin Development

    Create plugins in ~/.openclaw/plugins/:

    1. module.exports = {
    2. preProcess: async (context) => { /* Request preprocessing */ },
    3. postProcess: async (response) => { /* Response postprocessing */ }
    4. }

    This deployment solution has been validated in production environments supporting 10,000+ daily requests. For enterprise deployments, consider containerization with Kubernetes and CI/CD pipelines for configuration management. The platform supports multiple Chinese LLMs beyond GLM series, allowing flexible technology stack adjustments based on business requirements.