Appearance
云部署
本指南详细介绍如何在各大云平台上部署 AnythingLLM,包括 AWS、Google Cloud Platform、Microsoft Azure、DigitalOcean 等主流云服务提供商。
云平台选择
平台对比
平台 | 优势 | 适用场景 | 成本 |
---|---|---|---|
AWS | 服务丰富、生态完善 | 企业级应用 | 中等 |
Google Cloud | AI/ML 服务强大 | AI 密集型应用 | 中等 |
Azure | 与微软生态集成 | 企业 Office 环境 | 中等 |
DigitalOcean | 简单易用、价格透明 | 中小型项目 | 较低 |
Vercel | 前端优化、部署简单 | 快速原型 | 较低 |
Railway | 开发者友好 | 个人项目 | 较低 |
AWS 部署
使用 EC2 实例
1. 创建 EC2 实例
bash
# 使用 AWS CLI 创建实例
aws ec2 run-instances \
--image-id ami-0c02fb55956c7d316 \
--count 1 \
--instance-type t3.medium \
--key-name your-key-pair \
--security-group-ids sg-xxxxxxxxx \
--subnet-id subnet-xxxxxxxxx \
--user-data file://user-data.sh
2. 用户数据脚本
bash
#!/bin/bash
# user-data.sh
# 更新系统
yum update -y
# 安装 Docker
amazon-linux-extras install docker
systemctl start docker
systemctl enable docker
usermod -a -G docker ec2-user
# 安装 Docker Compose
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# 创建应用目录
mkdir -p /opt/anythingllm
cd /opt/anythingllm
# 创建 Docker Compose 文件
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
anythingllm:
image: mintplexlabs/anythingllm:latest
container_name: anythingllm
ports:
- "80:3001"
volumes:
- anythingllm_storage:/app/storage
environment:
- NODE_ENV=production
- JWT_SECRET=${JWT_SECRET}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- DATABASE_TYPE=postgres
- DB_HOST=postgres
- DB_USERNAME=anythingllm
- DB_PASSWORD=${DB_PASSWORD}
- DB_NAME=anythingllm
depends_on:
- postgres
restart: unless-stopped
postgres:
image: postgres:15-alpine
container_name: postgres
environment:
- POSTGRES_DB=anythingllm
- POSTGRES_USER=anythingllm
- POSTGRES_PASSWORD=${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
restart: unless-stopped
volumes:
anythingllm_storage:
postgres_data:
EOF
# 创建环境文件
cat > .env << 'EOF'
JWT_SECRET=your-super-secret-jwt-key-change-this
OPENAI_API_KEY=your-openai-api-key
DB_PASSWORD=your-secure-database-password
EOF
# 启动服务
docker-compose up -d
3. CloudFormation 模板
yaml
# cloudformation-template.yml
AWSTemplateFormatVersion: '2010-09-09'
Description: 'AnythingLLM deployment on AWS'
Parameters:
InstanceType:
Type: String
Default: t3.medium
AllowedValues: [t3.small, t3.medium, t3.large, t3.xlarge]
Description: EC2 instance type
KeyName:
Type: AWS::EC2::KeyPair::KeyName
Description: EC2 Key Pair for SSH access
OpenAIAPIKey:
Type: String
NoEcho: true
Description: OpenAI API Key
JWTSecret:
Type: String
NoEcho: true
Description: JWT Secret Key
Resources:
# VPC 配置
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsHostnames: true
EnableDnsSupport: true
Tags:
- Key: Name
Value: AnythingLLM-VPC
# 公共子网
PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.1.0/24
AvailabilityZone: !Select [0, !GetAZs '']
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: AnythingLLM-PublicSubnet
# 私有子网
PrivateSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.2.0/24
AvailabilityZone: !Select [1, !GetAZs '']
Tags:
- Key: Name
Value: AnythingLLM-PrivateSubnet
# 互联网网关
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: AnythingLLM-IGW
AttachGateway:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref InternetGateway
# 路由表
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: AnythingLLM-PublicRouteTable
PublicRoute:
Type: AWS::EC2::Route
DependsOn: AttachGateway
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicSubnet
RouteTableId: !Ref PublicRouteTable
# 安全组
WebSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security group for AnythingLLM web server
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: AnythingLLM-WebSG
# RDS 子网组
DBSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: Subnet group for RDS database
SubnetIds:
- !Ref PublicSubnet
- !Ref PrivateSubnet
Tags:
- Key: Name
Value: AnythingLLM-DBSubnetGroup
# RDS 实例
Database:
Type: AWS::RDS::DBInstance
Properties:
DBInstanceIdentifier: anythingllm-db
DBInstanceClass: db.t3.micro
Engine: postgres
EngineVersion: '15.4'
MasterUsername: anythingllm
MasterUserPassword: !Ref JWTSecret
AllocatedStorage: 20
StorageType: gp2
DBSubnetGroupName: !Ref DBSubnetGroup
VPCSecurityGroups:
- !Ref DatabaseSecurityGroup
BackupRetentionPeriod: 7
MultiAZ: false
PubliclyAccessible: false
Tags:
- Key: Name
Value: AnythingLLM-Database
DatabaseSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security group for RDS database
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 5432
ToPort: 5432
SourceSecurityGroupId: !Ref WebSecurityGroup
Tags:
- Key: Name
Value: AnythingLLM-DatabaseSG
# EC2 实例
WebServer:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0c02fb55956c7d316 # Amazon Linux 2
InstanceType: !Ref InstanceType
KeyName: !Ref KeyName
SecurityGroupIds:
- !Ref WebSecurityGroup
SubnetId: !Ref PublicSubnet
IamInstanceProfile: !Ref InstanceProfile
UserData:
Fn::Base64: !Sub |
#!/bin/bash
yum update -y
amazon-linux-extras install docker
systemctl start docker
systemctl enable docker
usermod -a -G docker ec2-user
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
mkdir -p /opt/anythingllm
cd /opt/anythingllm
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
anythingllm:
image: mintplexlabs/anythingllm:latest
ports:
- "80:3001"
environment:
- NODE_ENV=production
- JWT_SECRET=${JWTSecret}
- OPENAI_API_KEY=${OpenAIAPIKey}
- DATABASE_TYPE=postgres
- DB_HOST=${Database.Endpoint.Address}
- DB_USERNAME=anythingllm
- DB_PASSWORD=${JWTSecret}
- DB_NAME=anythingllm
volumes:
- anythingllm_storage:/app/storage
restart: unless-stopped
volumes:
anythingllm_storage:
EOF
docker-compose up -d
Tags:
- Key: Name
Value: AnythingLLM-WebServer
# IAM 角色
InstanceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: ec2.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- !Ref InstanceRole
Outputs:
WebsiteURL:
Description: URL of the AnythingLLM application
Value: !Sub 'http://${WebServer.PublicDnsName}'
DatabaseEndpoint:
Description: RDS instance endpoint
Value: !GetAtt Database.Endpoint.Address
使用 ECS (Elastic Container Service)
1. ECS 任务定义
json
{
"family": "anythingllm",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "1024",
"memory": "2048",
"executionRoleArn": "arn:aws:iam::ACCOUNT:role/ecsTaskExecutionRole",
"taskRoleArn": "arn:aws:iam::ACCOUNT:role/ecsTaskRole",
"containerDefinitions": [
{
"name": "anythingllm",
"image": "mintplexlabs/anythingllm:latest",
"portMappings": [
{
"containerPort": 3001,
"protocol": "tcp"
}
],
"environment": [
{
"name": "NODE_ENV",
"value": "production"
},
{
"name": "DATABASE_TYPE",
"value": "postgres"
}
],
"secrets": [
{
"name": "JWT_SECRET",
"valueFrom": "arn:aws:secretsmanager:region:account:secret:anythingllm/jwt-secret"
},
{
"name": "OPENAI_API_KEY",
"valueFrom": "arn:aws:secretsmanager:region:account:secret:anythingllm/openai-key"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/anythingllm",
"awslogs-region": "us-west-2",
"awslogs-stream-prefix": "ecs"
}
},
"mountPoints": [
{
"sourceVolume": "anythingllm-storage",
"containerPath": "/app/storage"
}
]
}
],
"volumes": [
{
"name": "anythingllm-storage",
"efsVolumeConfiguration": {
"fileSystemId": "fs-xxxxxxxxx",
"transitEncryption": "ENABLED"
}
}
]
}
2. ECS 服务配置
bash
# 创建 ECS 集群
aws ecs create-cluster --cluster-name anythingllm-cluster
# 注册任务定义
aws ecs register-task-definition --cli-input-json file://task-definition.json
# 创建服务
aws ecs create-service \
--cluster anythingllm-cluster \
--service-name anythingllm-service \
--task-definition anythingllm:1 \
--desired-count 2 \
--launch-type FARGATE \
--network-configuration "awsvpcConfiguration={subnets=[subnet-xxxxxxxxx],securityGroups=[sg-xxxxxxxxx],assignPublicIp=ENABLED}"
使用 AWS App Runner
yaml
# apprunner.yaml
version: 1.0
runtime: docker
build:
commands:
build:
- echo "No build commands"
run:
runtime-version: latest
command: npm start
network:
port: 3001
env: PORT
env:
- name: NODE_ENV
value: production
- name: JWT_SECRET
value: your-jwt-secret
- name: OPENAI_API_KEY
value: your-openai-key
Google Cloud Platform 部署
使用 Cloud Run
1. 构建和部署
bash
# 设置项目
gcloud config set project your-project-id
# 构建镜像
gcloud builds submit --tag gcr.io/your-project-id/anythingllm
# 部署到 Cloud Run
gcloud run deploy anythingllm \
--image gcr.io/your-project-id/anythingllm \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars NODE_ENV=production \
--set-env-vars JWT_SECRET=your-jwt-secret \
--set-env-vars OPENAI_API_KEY=your-openai-key \
--memory 2Gi \
--cpu 2 \
--max-instances 10
2. Cloud Build 配置
yaml
# cloudbuild.yaml
steps:
# 构建镜像
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/anythingllm', '.']
# 推送镜像
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/anythingllm']
# 部署到 Cloud Run
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args:
- 'run'
- 'deploy'
- 'anythingllm'
- '--image'
- 'gcr.io/$PROJECT_ID/anythingllm'
- '--region'
- 'us-central1'
- '--platform'
- 'managed'
- '--allow-unauthenticated'
images:
- 'gcr.io/$PROJECT_ID/anythingllm'
使用 GKE (Google Kubernetes Engine)
1. 创建集群
bash
# 创建 GKE 集群
gcloud container clusters create anythingllm-cluster \
--zone us-central1-a \
--num-nodes 3 \
--enable-autoscaling \
--min-nodes 1 \
--max-nodes 10 \
--machine-type e2-standard-2
# 获取凭据
gcloud container clusters get-credentials anythingllm-cluster --zone us-central1-a
2. Kubernetes 配置
yaml
# k8s/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: anythingllm
spec:
replicas: 3
selector:
matchLabels:
app: anythingllm
template:
metadata:
labels:
app: anythingllm
spec:
containers:
- name: anythingllm
image: gcr.io/your-project-id/anythingllm:latest
ports:
- containerPort: 3001
env:
- name: NODE_ENV
value: "production"
- name: JWT_SECRET
valueFrom:
secretKeyRef:
name: anythingllm-secrets
key: jwt-secret
- name: OPENAI_API_KEY
valueFrom:
secretKeyRef:
name: anythingllm-secrets
key: openai-key
resources:
requests:
memory: "1Gi"
cpu: "500m"
limits:
memory: "2Gi"
cpu: "1000m"
---
apiVersion: v1
kind: Service
metadata:
name: anythingllm-service
spec:
selector:
app: anythingllm
ports:
- protocol: TCP
port: 80
targetPort: 3001
type: LoadBalancer
---
apiVersion: v1
kind: Secret
metadata:
name: anythingllm-secrets
type: Opaque
stringData:
jwt-secret: your-jwt-secret
openai-key: your-openai-key
Microsoft Azure 部署
使用 Azure Container Instances
1. 创建资源组
bash
# 创建资源组
az group create --name anythingllm-rg --location eastus
# 创建容器实例
az container create \
--resource-group anythingllm-rg \
--name anythingllm \
--image mintplexlabs/anythingllm:latest \
--dns-name-label anythingllm-unique \
--ports 3001 \
--environment-variables \
NODE_ENV=production \
JWT_SECRET=your-jwt-secret \
OPENAI_API_KEY=your-openai-key \
--cpu 2 \
--memory 4
2. ARM 模板
json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"containerName": {
"type": "string",
"defaultValue": "anythingllm"
},
"jwtSecret": {
"type": "securestring"
},
"openaiApiKey": {
"type": "securestring"
}
},
"resources": [
{
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2021-03-01",
"name": "[parameters('containerName')]",
"location": "[resourceGroup().location]",
"properties": {
"containers": [
{
"name": "anythingllm",
"properties": {
"image": "mintplexlabs/anythingllm:latest",
"ports": [
{
"port": 3001,
"protocol": "TCP"
}
],
"environmentVariables": [
{
"name": "NODE_ENV",
"value": "production"
},
{
"name": "JWT_SECRET",
"secureValue": "[parameters('jwtSecret')]"
},
{
"name": "OPENAI_API_KEY",
"secureValue": "[parameters('openaiApiKey')]"
}
],
"resources": {
"requests": {
"cpu": 2,
"memoryInGB": 4
}
}
}
}
],
"osType": "Linux",
"ipAddress": {
"type": "Public",
"ports": [
{
"port": 3001,
"protocol": "TCP"
}
],
"dnsNameLabel": "[parameters('containerName')]"
}
}
}
],
"outputs": {
"fqdn": {
"type": "string",
"value": "[reference(resourceId('Microsoft.ContainerInstance/containerGroups', parameters('containerName'))).ipAddress.fqdn]"
}
}
}
使用 Azure App Service
1. 创建 App Service
bash
# 创建 App Service 计划
az appservice plan create \
--name anythingllm-plan \
--resource-group anythingllm-rg \
--sku B1 \
--is-linux
# 创建 Web App
az webapp create \
--resource-group anythingllm-rg \
--plan anythingllm-plan \
--name anythingllm-app \
--deployment-container-image-name mintplexlabs/anythingllm:latest
# 配置环境变量
az webapp config appsettings set \
--resource-group anythingllm-rg \
--name anythingllm-app \
--settings \
NODE_ENV=production \
JWT_SECRET=your-jwt-secret \
OPENAI_API_KEY=your-openai-key \
WEBSITES_PORT=3001
DigitalOcean 部署
使用 App Platform
1. App Spec 配置
yaml
# .do/app.yaml
name: anythingllm
services:
- name: web
source_dir: /
github:
repo: your-username/anythingllm
branch: main
run_command: npm start
environment_slug: node-js
instance_count: 1
instance_size_slug: basic-xxs
http_port: 3001
env:
- key: NODE_ENV
value: production
- key: JWT_SECRET
value: your-jwt-secret
type: SECRET
- key: OPENAI_API_KEY
value: your-openai-key
type: SECRET
databases:
- name: anythingllm-db
engine: PG
version: "13"
size: db-s-1vcpu-1gb
2. 使用 doctl 部署
bash
# 安装 doctl
curl -sL https://github.com/digitalocean/doctl/releases/download/v1.94.0/doctl-1.94.0-linux-amd64.tar.gz | tar -xzv
sudo mv doctl /usr/local/bin
# 认证
doctl auth init
# 创建应用
doctl apps create .do/app.yaml
# 查看应用状态
doctl apps list
使用 Droplet
1. 创建 Droplet
bash
# 创建 Droplet
doctl compute droplet create anythingllm \
--size s-2vcpu-4gb \
--image ubuntu-20-04-x64 \
--region nyc1 \
--ssh-keys your-ssh-key-id \
--user-data-file user-data.sh
# 获取 IP 地址
doctl compute droplet list
2. 用户数据脚本
bash
#!/bin/bash
# user-data.sh
# 更新系统
apt-get update
apt-get upgrade -y
# 安装 Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
usermod -aG docker ubuntu
# 安装 Docker Compose
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# 创建应用目录
mkdir -p /opt/anythingllm
cd /opt/anythingllm
# 创建 Docker Compose 文件
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
anythingllm:
image: mintplexlabs/anythingllm:latest
container_name: anythingllm
ports:
- "80:3001"
volumes:
- anythingllm_storage:/app/storage
environment:
- NODE_ENV=production
- JWT_SECRET=your-jwt-secret
- OPENAI_API_KEY=your-openai-key
restart: unless-stopped
volumes:
anythingllm_storage:
EOF
# 启动服务
docker-compose up -d
# 设置防火墙
ufw allow 22
ufw allow 80
ufw allow 443
ufw --force enable
Vercel 部署
1. Vercel 配置
json
{
"version": 2,
"builds": [
{
"src": "server/package.json",
"use": "@vercel/node"
},
{
"src": "frontend/package.json",
"use": "@vercel/static-build",
"config": {
"distDir": "build"
}
}
],
"routes": [
{
"src": "/api/(.*)",
"dest": "/server/index.js"
},
{
"src": "/(.*)",
"dest": "/frontend/$1"
}
],
"env": {
"NODE_ENV": "production",
"JWT_SECRET": "@jwt-secret",
"OPENAI_API_KEY": "@openai-api-key"
}
}
2. 部署脚本
bash
# 安装 Vercel CLI
npm install -g vercel
# 登录
vercel login
# 部署
vercel --prod
# 设置环境变量
vercel env add JWT_SECRET
vercel env add OPENAI_API_KEY
Railway 部署
1. Railway 配置
toml
# railway.toml
[build]
builder = "NIXPACKS"
[deploy]
startCommand = "npm start"
restartPolicyType = "ON_FAILURE"
restartPolicyMaxRetries = 10
[env]
NODE_ENV = "production"
2. 使用 Railway CLI
bash
# 安装 Railway CLI
npm install -g @railway/cli
# 登录
railway login
# 初始化项目
railway init
# 部署
railway up
# 设置环境变量
railway variables set JWT_SECRET=your-jwt-secret
railway variables set OPENAI_API_KEY=your-openai-key
监控和维护
CloudWatch 监控 (AWS)
yaml
# cloudwatch-config.yml
Resources:
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: /aws/ec2/anythingllm
RetentionInDays: 14
CPUAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High CPU utilization
MetricName: CPUUtilization
Namespace: AWS/EC2
Statistic: Average
Period: 300
EvaluationPeriods: 2
Threshold: 80
ComparisonOperator: GreaterThanThreshold
AlarmActions:
- !Ref SNSTopic
MemoryAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High memory utilization
MetricName: MemoryUtilization
Namespace: CWAgent
Statistic: Average
Period: 300
EvaluationPeriods: 2
Threshold: 80
ComparisonOperator: GreaterThanThreshold
自动扩展配置
yaml
# autoscaling.yml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: anythingllm-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: anythingllm
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
备份策略
bash
#!/bin/bash
# backup-cloud.sh
# AWS S3 备份
aws s3 sync /app/storage s3://anythingllm-backup/$(date +%Y%m%d)/
# Google Cloud Storage 备份
gsutil -m rsync -r -d /app/storage gs://anythingllm-backup/$(date +%Y%m%d)/
# Azure Blob Storage 备份
az storage blob upload-batch \
--destination anythingllm-backup \
--source /app/storage \
--destination-path $(date +%Y%m%d)/
云部署提供了高可用性、可扩展性和专业的运维支持。选择合适的云平台和部署方式可以大大简化 AnythingLLM 的运维工作。