Linux安装ragflow(含一键安装脚本)
前文:Linux安装docker+ollama+deepseek:https://blog.csdn.net/YXWik/article/details/149497501
总结:服务器需要安装docker
+ollama
+deepseek
,然后再docker-compose-linux-x86_64
+RagFlow
项目 +install_ragflow.sh
脚本 进行安装
github代理站:https://g.cachecdn.ggff.net/
下载docker-compose-linux-x86_64:https://github.com/docker/compose/releases/download/v2.29.2/docker-compose-Linux-x86_64
下载RagFlow项目:https://github.com/infiniflow/ragflow/archive/refs/heads/main.zip
上传到服务器进行解压
进入项目的docker目录下
cd /ragflow-main/docker
将以下两个文件放到docker目录下
install_ragflow.sh
脚本+docker-compose-linux-x86_64
(Docker Compose)
install_ragflow.sh
脚本记得赋权
为避免ragflow的端口冲突,我在脚本中设置了端口为8880开始检测,如果没占用采用8880进行web端访问端口
#!/bin/bash# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'# 基础配置
BASE_ES_PORT=1201
BASE_MYSQL_PORT=5456
BASE_REDIS_PORT=6380
BASE_MINIO_PORT=9002
BASE_MINIO_CONSOLE_PORT=9003
BASE_SVR_HTTP_PORT=9300
BASE_WEB_HTTP_PORT=8880# 容器名称(必须与docker-compose中一致)
CONTAINER_PREFIX="ragflow"
SERVER_CONTAINER="${CONTAINER_PREFIX}-server"
MYSQL_CONTAINER="${CONTAINER_PREFIX}-mysql"
REDIS_CONTAINER="${CONTAINER_PREFIX}-redis"
ES_CONTAINER="${CONTAINER_PREFIX}-es-01"
MINIO_CONTAINER="${CONTAINER_PREFIX}-minio"
CONTAINERS=("$SERVER_CONTAINER" "$MYSQL_CONTAINER" "$REDIS_CONTAINER" "$ES_CONTAINER" "$MINIO_CONTAINER")# 核心路径与密码
RAGFLOW_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
MYSQL_PASSWORD="infini_rag_flow"
COMPOSE_VERSION="v2.29.2"# 1. 检测可用端口
get_available_port() {local base_port=$1local port=$base_portwhile netstat -tulpn | awk '{print $4}' | grep -q ":$port$"; doport=$((port + 1))doneecho $port
}# 2. 环境检查
check_env() {echo -e "${YELLOW}检查环境...${NC}"if [ "$EUID" -ne 0 ]; thenecho -e "${RED}错误:请使用root权限运行${NC}" && exit 1fiif ! command -v docker &> /dev/null; thenecho -e "${RED}错误:未检测到Docker${NC}" && exit 1fiif ! command -v docker-compose &> /dev/null; thenecho -e "${YELLOW}Docker Compose未安装,将自动安装${NC}"fiif ! command -v netstat &> /dev/null; thenecho -e "${YELLOW}安装端口检测工具...${NC}"yum install -y net-tools &> /dev/null || { echo -e "${RED}安装net-tools失败${NC}"; exit 1; }fiecho -e "${GREEN}环境检查通过${NC}"
}# 3. 获取所有端口
get_ports() {ES_PORT=$(get_available_port $BASE_ES_PORT)MYSQL_PORT=$(get_available_port $BASE_MYSQL_PORT)REDIS_PORT=$(get_available_port $BASE_REDIS_PORT)MINIO_PORT=$(get_available_port $BASE_MINIO_PORT)# 确保MinIO控制台端口不冲突MINIO_CONSOLE_PORT=$(get_available_port $BASE_MINIO_CONSOLE_PORT)while [ "$MINIO_CONSOLE_PORT" -eq "$MINIO_PORT" ]; doMINIO_CONSOLE_PORT=$((MINIO_CONSOLE_PORT + 1))doneSVR_HTTP_PORT=$(get_available_port $BASE_SVR_HTTP_PORT)WEB_HTTP_PORT=$(get_available_port $BASE_WEB_HTTP_PORT)
}# 4. 打印端口信息
print_ports() {echo -e "${YELLOW}检测到可用端口:${NC}"echo -e "Elasticsearch: $ES_PORT"echo -e "MySQL: $MYSQL_PORT"echo -e "Redis: $REDIS_PORT"echo -e "MinIO(主端口): $MINIO_PORT"echo -e "MinIO(控制台): $MINIO_CONSOLE_PORT"echo -e "RAGFlow服务(API): $SVR_HTTP_PORT"echo -e "RAGFlow服务(Web): $WEB_HTTP_PORT"
}# 5. 安装Docker Compose
install_compose() {echo -e "${YELLOW}安装Docker Compose...${NC}"COMPOSE_BIN="/usr/local/bin/docker-compose"if ! command -v docker-compose &> /dev/null; thenif [ -f "$RAGFLOW_DIR/docker-compose-linux-x86_64" ]; thencp "$RAGFLOW_DIR/docker-compose-linux-x86_64" "$COMPOSE_BIN"elseif ! curl -L "https://github.com/docker/compose/releases/download/$COMPOSE_VERSION/docker-compose-Linux-x86_64" -o "$COMPOSE_BIN"; thenecho -e "${RED}错误:Docker Compose下载失败${NC}" && exit 1fifichmod +x "$COMPOSE_BIN"fiif ! command -v docker-compose &> /dev/null; thenecho -e "${RED}错误:Docker Compose安装失败${NC}" && exit 1fiecho -e "${GREEN}Docker Compose安装成功${NC}"
}# 6. 生成所有配置文件(含mapping.json)
generate_configs() {echo -e "${YELLOW}生成所有配置文件(含缺失文件)...${NC}"mkdir -p "$RAGFLOW_DIR/conf" "$RAGFLOW_DIR/nginx" && cd "$RAGFLOW_DIR" || exit 1# 清理旧配置rm -rf init.sql docker-compose.yml .env# 生成.env文件cat > .env <<EOF
SERVER_CONTAINER=${SERVER_CONTAINER}
MYSQL_CONTAINER=${MYSQL_CONTAINER}
REDIS_CONTAINER=${REDIS_CONTAINER}
ES_CONTAINER=${ES_CONTAINER}
MINIO_CONTAINER=${MINIO_CONTAINER}
DOC_ENGINE=elasticsearch
COMPOSE_PROFILES=${DOC_ENGINE}
STACK_VERSION=8.11.3
ES_HOST=es01
ES_PORT=1200
ES_USER=elastic
ELASTIC_PASSWORD=infini_rag_flow
KIBANA_PORT=6601
KIBANA_USER=rag_flow
KIBANA_PASSWORD=infini_rag_flow
MEM_LIMIT=8073741824
INFINITY_HOST=infinity
INFINITY_THRIFT_PORT=23817
INFINITY_HTTP_PORT=23820
INFINITY_PSQL_PORT=5432
MYSQL_PASSWORD=infini_rag_flow
MYSQL_HOST=mysql
MYSQL_DBNAME=rag_flow
MYSQL_PORT=$MYSQL_PORT
MINIO_HOST=minio
MINIO_CONSOLE_PORT=$MINIO_CONSOLE_PORT
MINIO_PORT=$MINIO_PORT
MINIO_USER=rag_flow
MINIO_PASSWORD=infini_rag_flow
REDIS_HOST=redis
REDIS_PORT=$REDIS_PORT
REDIS_PASSWORD=infini_rag_flow
SVR_HTTP_PORT=$SVR_HTTP_PORT
RAGFLOW_IMAGE=swr.cn-north-4.myhuaweicloud.com/infiniflow/ragflow:nightly
TIMEZONE="Asia/Shanghai"
HF_ENDPOINT=https://hf-mirror.com
REGISTER_ENABLED=1
WEB_HTTP_PORT=$WEB_HTTP_PORT
EOF# 生成docker-compose.yml(确保容器名称正确)cat > docker-compose.yml <<EOF
services:ragflow:image: '\${RAGFLOW_IMAGE}'container_name: ragflow-serverports:- '\${SVR_HTTP_PORT}:9380'- '\${WEB_HTTP_PORT}:80'- 443:443- 5678:5678- 5679:5679depends_on:mysql:condition: service_healthyenvironment:- MYSQL_HOST='\$MYSQL_CONTAINER'- REDIS_HOST='\$REDIS_CONTAINER'- ES_HOST='\$ES_CONTAINER'- MINIO_HOST='\$MINIO_CONTAINER'- MYSQL_PASSWORD=infini_rag_flow- TZ="Asia/Shanghai"- HF_ENDPOINT='\${HF_ENDPOINT}'- MACOS='\${MACOS}'volumes:- ./ragflow-logs:/ragflow/logs- ./nginx/ragflow.conf:/etc/nginx/conf.d/ragflow.conf- ./nginx/proxy.conf:/etc/nginx/proxy.conf- ./nginx/nginx.conf:/etc/nginx/nginx.conf- ../history_data_agent:/ragflow/history_data_agent - ./service_conf.yaml.template:/ragflow/conf/service_conf.yaml.templateenv_file: .env networks:- ragflowrestart: on-failureextra_hosts:- "host.docker.internal:host-gateway"es01:container_name: ragflow-es-01profiles:- elasticsearchimage: 'elasticsearch:\${STACK_VERSION}'volumes:- esdata01:/usr/share/elasticsearch/dataports:- '\${ES_PORT}:9200'env_file: .envenvironment:- node.name=es01- ELASTIC_PASSWORD=infini_rag_flow- bootstrap.memory_lock=false- discovery.type=single-node- xpack.security.enabled=true- xpack.security.http.ssl.enabled=false- xpack.security.transport.ssl.enabled=false- cluster.routing.allocation.disk.watermark.low=5gb- cluster.routing.allocation.disk.watermark.high=3gb- cluster.routing.allocation.disk.watermark.flood_stage=2gb- TZ="Asia/Shanghai"mem_limit: 8073741824ulimits:memlock:soft: -1hard: -1healthcheck:test: ["CMD-SHELL", "curl http://localhost:9200"]interval: 10stimeout: 10sretries: 120networks:- ragflowrestart: on-failureinfinity:container_name: ragflow-infinityprofiles:- infinityimage: infiniflow/infinity:v0.6.0-dev3volumes:- infinity_data:/var/infinity- ./infinity_conf.toml:/infinity_conf.tomlcommand: ["-f", "/infinity_conf.toml"]ports:- '\${INFINITY_THRIFT_PORT}:23817'- '\${INFINITY_HTTP_PORT}:23820'- '\${INFINITY_PSQL_PORT}:5432'env_file: .envenvironment:- TZ="Asia/Shanghai"mem_limit: 8073741824ulimits:nofile:soft: 500000hard: 500000networks:- ragflowhealthcheck:test: ["CMD", "curl", "http://localhost:23820/admin/node/current"]interval: 10stimeout: 10sretries: 120restart: on-failuremysql:# mysql:5.7 linux/arm64 image is unavailable.image: mysql:8.0.39container_name: ragflow-mysqlenv_file: .envenvironment:- "MYSQL_ROOT_PASSWORD=infini_rag_flow"- '\TZ=${TIMEZONE}'command:--max_connections=1000--character-set-server=utf8mb4--collation-server=utf8mb4_unicode_ci--default-authentication-plugin=mysql_native_password--tls_version="TLSv1.2,TLSv1.3"--init-file /data/application/init.sql--binlog_expire_logs_seconds=604800ports:- '\${MYSQL_PORT}:3306'volumes:- mysql_data:/var/lib/mysql- ./init.sql:/data/application/init.sqlnetworks:- ragflowhealthcheck:test: ["CMD", "mysqladmin" ,"ping", "-uroot", "-pinfini_rag_flow"]interval: 10stimeout: 10sretries: 3restart: on-failureminio:image: quay.io/minio/minio:RELEASE.2023-12-20T01-00-02Zcontainer_name: ragflow-miniocommand: server --console-address ":9001" /dataports:- '\${MINIO_PORT}:9000'- '\${MINIO_CONSOLE_PORT}:9001'env_file: .envenvironment:- MINIO_ROOT_USER=rag_flow- MINIO_ROOT_PASSWORD=infini_rag_flow- TZ="Asia/Shanghai"volumes:- minio_data:/datanetworks:- ragflowrestart: on-failureredis:image: valkey/valkey:8container_name: ragflow-redisentrypoint: ["redis-server", "--requirepass", "infini_rag_flow", "--maxmemory", "128mb", "--maxmemory-policy", "allkeys-lru"]env_file: .envports:- '\${REDIS_PORT}:6379'volumes:- redis_data:/datanetworks:- ragflowrestart: on-failurevolumes:esdata01:driver: localinfinity_data:driver: localmysql_data:driver: localminio_data:driver: localredis_data:driver: localnetworks:ragflow:driver: bridge
EOF# 生成MySQL初始化脚本cat > init.sql <<EOF
CREATE DATABASE IF NOT EXISTS rag_flow CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
EOFcat > service_conf.yaml.template <<EOF
ragflow:host: ${RAGFLOW_HOST:-0.0.0.0} # 去掉单引号,变量直接引用http_port: 9380
mysql:name: ${MYSQL_DBNAME:-rag_flow}user: ${MYSQL_USER:-root}password: ${MYSQL_PASSWORD:-infini_rag_flow}host: ${MYSQL_HOST:-mysql}port: 3306max_connections: 900stale_timeout: 300
minio:user: ${MINIO_USER:-rag_flow}password: ${MINIO_PASSWORD:-infini_rag_flow}host: ${MINIO_HOST:-minio}:9000
es:hosts: http://${ES_HOST:-es01}:9200username: ${ES_USER:-elastic}password: ${ELASTIC_PASSWORD:-infini_rag_flow}
os:hosts: http://${OS_HOST:-opensearch01}:9201username: ${OS_USER:-admin}password: ${OPENSEARCH_PASSWORD:-infini_rag_flow_OS_01}
infinity:uri: ${INFINITY_HOST:-infinity}:23817db_name: default_db
redis:db: 1password: ${REDIS_PASSWORD:-infini_rag_flow}host: ${REDIS_HOST:-redis}:6379EOFecho -e "${GREEN}所有配置文件生成完成(含mapping.json)${NC}"
}# 7. 启动服务
start_services() {echo -e "${YELLOW}清理旧容器...${NC}"for container in "${CONTAINERS[@]}"; doif docker ps -a --format "{{.Names}}" | grep -q "^$container$"; thendocker rm -f "$container" &> /dev/nullecho -e "已删除旧容器:$container"fidoneecho -e "${YELLOW}启动所有服务...${NC}"cd "$RAGFLOW_DIR" || exit 1docker-compose --profile elasticsearch up -decho -e "${YELLOW}等待服务就绪(30秒)...${NC}"sleep 30}# 8. 修复MySQL授权
fix_mysql_authorization() {echo -e "${YELLOW}修复MySQL授权...${NC}"if docker ps --format "{{.Names}}" | grep -q "^$MYSQL_CONTAINER$"; thendocker exec "$MYSQL_CONTAINER" sh -c "mysql -uroot -pinfini_rag_flow -e \"CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED BY 'infini_rag_flow';GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;FLUSH PRIVILEGES;\""echo -e "${GREEN}MySQL授权修复完成${NC}"elseecho -e "${RED}错误:$MYSQL_CONTAINER未启动,授权修复失败${NC}"fi
}# 9. 验证安装
verify_installation() {SERVER_IP=$(hostname -I | awk '{print $1}')# 检查服务是否运行if ! docker ps --format "{{.Names}}" | grep -q "^$SERVER_CONTAINER$"; thenecho -e "${RED}错误:$SERVER_CONTAINER未正常启动${NC}"echo -e "${YELLOW}服务日志:${NC}"docker logs "$SERVER_CONTAINER" 2>&1 | head -30exit 1fi# 检查关键错误if docker logs "$SERVER_CONTAINER" 2>&1 | grep -q "Error"; thenecho -e "${YELLOW}服务存在错误日志:${NC}"docker logs "$SERVER_CONTAINER" 2>&1 | grep "Error" | head -10fiecho -e "${GREEN}===== 安装成功!====="echo -e "Web访问地址:http://$SERVER_IP:$WEB_HTTP_PORT"echo -e "API访问地址:http://$SERVER_IP:$SVR_HTTP_PORT"
}# 主流程
main() {echo -e "${GREEN}===== RAGFlow安装脚本(终极修复版)=====${NC}"check_envget_portsprint_portsinstall_composegenerate_configsstart_servicesfix_mysql_authorizationverify_installationecho -e "${GREEN}===== 安装流程完成 ====="
}# 执行主函数
main
脚本会在docker中安装 redis 、 minio 、 es 、mysql 、ragflow ,如果服务器存在这些服务的记得处理下,
运行脚本
./install_ragflow.sh
如果重复运行脚本就需要执行以下命令进行清理后再重启
docker volume ls | grep data
docker volume rm 指定data
docker stop ragflow-server ragflow-minio ragflow-mysql ragflow-es-01 ragflow-redis
docker rm ragflow-server ragflow-minio ragflow-mysql ragflow-es-01 ragflow-redis
设置模型,前文中安装了deepseek-r1:7b
http://host.docker.internal:11434/
设置聊天默认模型
创建知识库
Windows
安装ragflow
:https://blog.csdn.net/YXWik/article/details/147122723