在ubuntu下一键安装 Open WebUI


#!/bin/bash

# Exit on any error
set -e

echo "Starting Open WebUI Installation..."

# Function to generate a random secret key
generate_secret_key() {
    python3 -c 'import secrets; print(secrets.token_urlsafe(32))'
}

# Update system packages
echo "Updating system packages..."
sudo apt update
sudo apt upgrade -y

# Install dependencies
echo "Installing dependencies..."
sudo apt install -y python3 python3-pip nodejs npm git curl python3-venv

# Install Ollama
echo "Installing Ollama..."
curl -fsSL https://ollama.com/install.sh | sh
sudo systemctl enable ollama
sudo systemctl start ollama

# Create installation directory
echo "Setting up Open WebUI..."
INSTALL_DIR="$HOME/open-webui"
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"

# Clone repository
git clone https://github.com/open-webui/open-webui.git
cd open-webui

# Setup Python virtual environment
echo "Setting up Python virtual environment..."
python3 -m venv venv
source venv/bin/activate

# Install Python dependencies
echo "Installing Python dependencies..."
pip install -r backend/requirements.txt

# Install and build frontend
echo "Installing and building frontend..."
npm install
npm run build

# Setup environment file
echo "Configuring environment..."
SECRET_KEY=$(generate_secret_key)
cat > .env << EOL
OLLAMA_BASE_URL=http://localhost:11434
WEBUI_SECRET_KEY=${SECRET_KEY}
EOL

# Create systemd service
echo "Creating systemd service..."
sudo tee /etc/systemd/system/open-webui-backend.service << EOL
[Unit]
Description=Open WebUI Backend
After=network.target

[Service]
Type=simple
User=$USER
WorkingDirectory=$INSTALL_DIR/open-webui/backend
ExecStart=$INSTALL_DIR/open-webui/venv/bin/gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOL

# Start and enable the service
echo "Starting Open WebUI service..."
sudo systemctl daemon-reload
sudo systemctl enable open-webui-backend
sudo systemctl start open-webui-backend

# Configure firewall
echo "Configuring firewall..."
sudo ufw allow 8080/tcp

echo "Installation completed successfully!"
echo "You can now access Open WebUI at http://localhost:8080"
echo "Please create an admin account on your first visit."

你可能感兴趣的:(python,人工智能,ubuntu,linux,运维)