优化部署

This commit is contained in:
qaq
2025-06-13 10:11:56 +08:00
parent aade2cf0c9
commit 7f42e3142c
4 changed files with 57 additions and 45 deletions
+4 -5
View File
@@ -27,13 +27,12 @@
```bash ```bash
# 1. 进入部署目录 # 1. 进入部署目录
wget https://github.com/bqlpfy/forward-panel/raw/refs/heads/main/deployment.zip
unzip deployment.zip
cd deployment cd deployment
# 2. 给脚本添加执行权限
chmod +x deploy.sh chmod +x deploy.sh
# SERVER_HOST是后端地址 就是服务器ip:6365
# 3. 启动所有服务 DB_NAME=gost DB_USER=gost DB_PASSWORD=yourpwd JWT_SECRET=yoursecret SERVER_HOST=your.server.ip:6365 ./deploy.sh start
./deploy.sh start
``` ```
BIN
View File
Binary file not shown.
+38 -25
View File
@@ -28,19 +28,18 @@ show_help() {
echo " -h, --help 显示此帮助信息" echo " -h, --help 显示此帮助信息"
echo "" echo ""
echo "环境变量配置:" echo "环境变量配置:"
echo " SERVER_HOST 服务器地址 (默认: localhost:6365)" echo " DB_NAME 数据库名 (必须设置)"
echo " VUE_APP_API_URL 前端API地址 (默认: http://localhost:6365/api/v1)" echo " DB_USER 数据库用户 (必须设置)"
echo " VUE_APP_WS_URL WebSocket地址 (默认: ws://localhost:6365)" echo " DB_PASSWORD 数据库密码 (必须设置)"
echo " JWT_SECRET JWT密钥 (必须设置)"
echo " SERVER_HOST 服务器地址 (必须设置,格式: ip:port)"
echo ""
echo -e "${RED}注意: 所有环境变量都是必需的,不提供默认配置!${NC}"
echo "" echo ""
echo "示例:" echo "示例:"
echo " # 启动服务" echo " DB_NAME=gost DB_USER=gost DB_PASSWORD=yourpwd JWT_SECRET=yoursecret SERVER_HOST=192.168.1.100:6365 $0 start"
echo " $0 start"
echo "" echo ""
echo " # 使用服务器IP启动"
echo " SERVER_HOST=192.168.1.100:6365 $0 start"
echo ""
echo " # 自定义完整地址启动"
echo " VUE_APP_API_URL=http://192.168.1.100:6365/api/v1 VUE_APP_WS_URL=ws://192.168.1.100:6365 $0 start"
} }
# 检测可用的Docker Compose命令 # 检测可用的Docker Compose命令
@@ -95,20 +94,34 @@ get_db_config() {
start_services() { start_services() {
echo -e "${GREEN}启动Gost转发面板服务...${NC}" echo -e "${GREEN}启动Gost转发面板服务...${NC}"
# 如果设置了 SERVER_HOST,自动生成 API 和 WS 地址 # 检查必需的环境变量
if [ -n "$SERVER_HOST" ]; then local missing_vars=()
export VUE_APP_API_URL="http://${SERVER_HOST}/api/v1"
export VUE_APP_WS_URL="ws://${SERVER_HOST}" [ -z "$DB_NAME" ] && missing_vars+=("DB_NAME")
else [ -z "$DB_USER" ] && missing_vars+=("DB_USER")
# 设置默认环境变量 [ -z "$DB_PASSWORD" ] && missing_vars+=("DB_PASSWORD")
export VUE_APP_API_URL=${VUE_APP_API_URL:-"http://localhost:6365/api/v1"} [ -z "$JWT_SECRET" ] && missing_vars+=("JWT_SECRET")
export VUE_APP_WS_URL=${VUE_APP_WS_URL:-"ws://localhost:6365"} [ -z "$SERVER_HOST" ] && missing_vars+=("SERVER_HOST")
if [ ${#missing_vars[@]} -gt 0 ]; then
echo -e "${RED}错误: 缺少必需的环境变量!${NC}"
echo -e "${YELLOW}缺少的变量: ${missing_vars[*]}${NC}"
echo ""
echo -e "${YELLOW}使用方法:${NC}"
echo "DB_NAME=gost DB_USER=gost DB_PASSWORD=yourpwd JWT_SECRET=yoursecret SERVER_HOST=your.server.ip:6365 $0 start"
exit 1
fi fi
# 设置环境变量
export VUE_APP_API_URL="http://${SERVER_HOST}/api/v1"
export VUE_APP_WS_URL="ws://${SERVER_HOST}"
echo -e "${YELLOW}环境变量配置:${NC}" echo -e "${YELLOW}环境变量配置:${NC}"
if [ -n "$SERVER_HOST" ]; then echo "DB_NAME: $DB_NAME"
echo "SERVER_HOST: $SERVER_HOST" echo "DB_USER: $DB_USER"
fi echo "DB_PASSWORD: $DB_PASSWORD"
echo "JWT_SECRET: $JWT_SECRET"
echo "SERVER_HOST: $SERVER_HOST"
echo "VUE_APP_API_URL: $VUE_APP_API_URL" echo "VUE_APP_API_URL: $VUE_APP_API_URL"
echo "VUE_APP_WS_URL: $VUE_APP_WS_URL" echo "VUE_APP_WS_URL: $VUE_APP_WS_URL"
echo "" echo ""
@@ -143,10 +156,10 @@ EOF
DB_PASSWORD=$(get_db_config "MYSQL_PASSWORD") DB_PASSWORD=$(get_db_config "MYSQL_PASSWORD")
echo -e "${YELLOW}访问地址:${NC}" echo -e "${YELLOW}访问地址:${NC}"
echo " 前端界面: http://localhost:${FRONTEND_PORT:-80}" # 提取IP地址(去掉端口)
echo " 后端API: http://localhost:${BACKEND_PORT:-6365}" SERVER_IP=$(echo "$SERVER_HOST" | cut -d':' -f1)
echo " 数据库: localhost:${MYSQL_PORT:-3306} (用户名: ${DB_USER:-gost}, 密码: ${DB_PASSWORD:-pwd})" echo " 前端界面: http://${SERVER_IP}:${FRONTEND_PORT:-80}"
echo " Redis: localhost:${REDIS_PORT:-6379}" echo " 后端API: http://${SERVER_HOST}"
echo "" echo ""
echo -e "${YELLOW}默认管理员账号:${NC}" echo -e "${YELLOW}默认管理员账号:${NC}"
echo " 用户名: admin_user" echo " 用户名: admin_user"
+15 -15
View File
@@ -6,13 +6,13 @@ services:
container_name: gost-mysql container_name: gost-mysql
restart: unless-stopped restart: unless-stopped
environment: environment:
MYSQL_ROOT_PASSWORD: rootpwd # 数据库密码 MYSQL_ROOT_PASSWORD: ${DB_PASSWORD} # 数据库密码
MYSQL_DATABASE: gost # 数据库名 MYSQL_DATABASE: ${DB_NAME} # 数据库名
MYSQL_USER: gost # 数据库用户 MYSQL_USER: ${DB_USER} # 数据库用户
MYSQL_PASSWORD: pwd # 数据库密码 MYSQL_PASSWORD: ${DB_PASSWORD} # 数据库密码
TZ: Asia/Shanghai TZ: Asia/Shanghai
ports: # ports:
- "3306:3306" # - "3306:3306" # 不暴露到公网,只在容器内部访问
volumes: volumes:
- mysql_data:/var/lib/mysql - mysql_data:/var/lib/mysql
- ./gost.sql:/docker-entrypoint-initdb.d/init.sql:ro - ./gost.sql:/docker-entrypoint-initdb.d/init.sql:ro
@@ -29,8 +29,8 @@ services:
image: redis:alpine image: redis:alpine
container_name: gost-redis container_name: gost-redis
restart: unless-stopped restart: unless-stopped
ports: # ports:
- "6379:6379" # - "6379:6379" # 不暴露到公网,只在容器内部访问
networks: networks:
- gost-network - gost-network
healthcheck: healthcheck:
@@ -46,12 +46,12 @@ services:
restart: unless-stopped restart: unless-stopped
environment: environment:
DB_HOST: mysql # 数据库地址 DB_HOST: mysql # 数据库地址
DB_NAME: gost # 数据库名 DB_NAME: ${DB_NAME} # 数据库名
DB_USER: gost # 数据库用户 DB_USER: ${DB_USER} # 数据库用户
DB_PASSWORD: pwd # 数据库密码 DB_PASSWORD: ${DB_PASSWORD} # 数据库密码
JWT_SECRET: test123 # JWT密钥 JWT_SECRET: ${JWT_SECRET} # JWT密钥
LOG_DIR: /app/logs # 日志目录 LOG_DIR: /app/logs # 日志目录
SERVER_ADDR: 127.0.0.1:6365 # 服务器地址 ip:port 不能套cdn 用于节点连接 SERVER_ADDR: ${SERVER_HOST} # 服务器地址 ip:port 不能套cdn 用于节点连接
JAVA_OPTS: "-Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai" JAVA_OPTS: "-Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai"
ports: ports:
- "6365:6365" - "6365:6365"
@@ -84,8 +84,8 @@ services:
environment: environment:
BACKEND_HOST: backend # 后端地址 BACKEND_HOST: backend # 后端地址
BACKEND_PORT: 6365 # 后端端口 BACKEND_PORT: 6365 # 后端端口
VUE_APP_API_URL: ${VUE_APP_API_URL:-http://localhost:6365/api/v1} # 前端API地址 VUE_APP_API_URL: ${VUE_APP_API_URL} # 前端API地址
VUE_APP_WS_URL: ${VUE_APP_WS_URL:-ws://localhost:6365} # 前端WebSocket地址 VUE_APP_WS_URL: ${VUE_APP_WS_URL} # 前端WebSocket地址
depends_on: depends_on:
backend: backend:
condition: service_healthy condition: service_healthy