Self-Hosted AI Assistant Deployment on Ubuntu 24.04 with Chinese LLM Integration: Complete Guide
This guide provides a step-by-step implementation for deploying a self-hosted AI assistant platform on Ubuntu 24.04, supporting integration with Chinese large language models while maintaining data sovereignty and security. The solution emphasizes multi-model compatibility, secure access, and enterprise-grade deployment patterns.
1. Technical Architecture & Core Value
The self-hosted AI assistant platform addresses growing enterprise needs for data privacy and model customization through three key capabilities:
- Multi-Model Support: Native compatibility with GLM, Llama, and other mainstream architectures
- Omnichannel Access: Web console, CLI tools, and IM platform integrations
- Security Isolation: SSH tunneling for private network access without public exposure
Compared to SaaS alternatives, this approach offers significant advantages in data control, latency optimization, and cost efficiency—particularly critical for financial and healthcare sectors requiring strict compliance.
2. Environment Setup & Security
2.1 System Requirements
- Server Specs: Ubuntu 24.04 LTS (4vCPU/8GB RAM minimum recommended)
- Network: Open ports 22 (SSH) and 3000 (default web)
- Security Hardening:
- SSH key authentication only
- UFW firewall configured for minimal exposure
- Regular patching (
sudo apt update && sudo apt upgrade)
2.2 Node.js Management
Recommended installation via nvm for version control:
# Install nvmcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashsource ~/.bashrc# Install LTS versionnvm install --ltsnvm alias default node# Verify installationnode -v # Should show v18.x+npm -v # Should show 9.x+
3. OpenClaw Deployment
3.1 Global Installation
# Install with permission handlingsudo npm install -g openclaw@latest --unsafe-perm# Troubleshooting installation failuresif [ $? -ne 0 ]; thenrm -rf $(npm root -g)/openclawnpm cache clean --forcemkdir -p ~/.openclawnpm install -g openclaw@latest --prefix ~/.openclawfi
3.2 Configuration Optimization
Edit ~/.openclaw/config.json:
{"port": 3000,"ssl": {"enabled": false,"cert": "/path/to/cert.pem","key": "/path/to/key.pem"},"rateLimit": {"max": 100,"windowMs": 60000}}
4. Chinese LLM Integration
4.1 API Service Registration
- Create application in provider console
- Obtain API Key and note:
- Authentication: API Key
- Endpoint:
https://api.example.com/v1 - Model: GLM-4.7-Flash
4.2 Provider Configuration
Interactive setup:
openclaw config
Follow prompts to:
- Select “Add custom provider”
- Name provider (e.g., “zhipu-glm”)
- Configure endpoint:
Base URL: https://api.example.com/v1Authorization: Bearer YOUR_API_KEY
- Test connectivity
4.3 Model Tuning
Add to models configuration:
{"name": "glm-4.7-flash","provider": "zhipu-glm","maxTokens": 2048,"temperature": 0.7,"topP": 0.9}
5. Secure Access Patterns
5.1 SSH Tunneling
Local access without public exposure:
ssh -N -L 3000:localhost:3000 username@server_ip
Access via http://localhost:3000
5.2 Nginx Production Proxy
server {listen 443 ssl;server_name ai.example.com;ssl_certificate /path/to/fullchain.pem;ssl_certificate_key /path/to/privkey.pem;location / {proxy_pass http://localhost:3000;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}}
6. Operations Framework
6.1 Log Management
Configure logrotate:
/var/log/openclaw/*.log {dailymissingokrotate 7compressdelaycompressnotifemptycreate 640 root admsharedscriptspostrotatesystemctl reload openclawendscript}
6.2 Performance Monitoring
Recommended Prometheus+Grafana stack:
- Expose
/metricsendpoint - Configure Node Exporter
- Set alerts for >500ms response times
7. Troubleshooting Guide
7.1 Port Conflicts
# Identify conflicting processsudo lsof -i :3000# Terminate processsudo kill -9 <PID>
7.2 Model Timeout
Adjust config.json:
{"providers": {"zhipu-glm": {"timeout": 60000 # 60 seconds}}}
7.3 CORS Resolution
Nginx configuration:
add_header 'Access-Control-Allow-Origin' '*';add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
8. Scalability Options
- Model Routing: Custom middleware for intelligent dispatch
- Session Persistence: Redis integration for context management
- Audit Logging: Comprehensive API call tracking
- Auto-Scaling: Kubernetes-based container orchestration
The modular design enables immediate deployment while allowing selective feature adoption. Regularly monitor provider API updates for compatibility. For high-throughput scenarios, implement horizontal scaling with load balancers distributing traffic across multiple OpenClaw instances.
