修改配置

This commit is contained in:
vet
2026-04-13 23:28:06 +07:00
parent fc351cf730
commit d6572d2217
6 changed files with 200 additions and 3 deletions

View File

@@ -7,14 +7,16 @@
# 2. 配置 GOPROXY自动测速选最快节点
# 3. 安装 Node.js / npm前端依赖
# 4. 安装 Docker基础设施容器
# 5. 写入 /etc/profile.d/deploy-env.sh永久生效
# 5. 安装 Nginx 并写入 PC/OpenIM 反代(:80 → 10001/10002/10008见 nginx/openim-pc-proxy.conf
# 6. 写入 /etc/profile.d/deploy-env.sh永久生效
#
# 用法:
# ./deploy-test/00-init-tools.sh # 安装全部
# ./deploy-test/00-init-tools.sh # 安装全部(含 Nginx 反代)
# ./deploy-test/00-init-tools.sh go # 只安装/配置 Go
# ./deploy-test/00-init-tools.sh node # 只安装 Node.js
# ./deploy-test/00-init-tools.sh docker # 只安装 Docker
# ./deploy-test/00-init-tools.sh goproxy # 只配置 GOPROXY
# sudo ./deploy-test/00-init-tools.sh nginx # 只安装 Nginx 反代(需 root
#
# 前置条件: root 或 sudo 权限Ubuntu/Debian 系统
#
@@ -241,6 +243,71 @@ _install_docker() {
success " Docker $(docker --version | awk '{print $3}' | tr -d ',') 安装完成"
}
# ──────────────────────────────────────────────────────────────────────────────
# 5. Nginx — PC / OpenIM 统一入口HTTP :80反代本机 10001/10002/10008
# ──────────────────────────────────────────────────────────────────────────────
_install_pc_nginx_proxy() {
step "安装 Nginx 并配置 OpenIM/PC 反代"
if [[ "$(id -u)" -ne 0 ]]; then
error " Nginx 安装需 root请执行: sudo $0 nginx"
return 1
fi
local script_dir
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local conf_src="${script_dir}/nginx/openim-pc-proxy.conf"
local conf_name="openim-pc-proxy.conf"
if [[ ! -f "$conf_src" ]]; then
error " 找不到配置: $conf_src"
return 1
fi
if ! _has nginx; then
if _has apt-get; then
apt-get update -y
apt-get install -y nginx
elif _has dnf; then
dnf install -y nginx
elif _has yum; then
yum install -y nginx
else
error " 未检测到 apt/dnf/yum请先手动安装 nginx"
return 1
fi
fi
if [[ -d /etc/nginx/sites-available ]]; then
install -m 0644 "$conf_src" "/etc/nginx/sites-available/${conf_name}"
mkdir -p /etc/nginx/sites-enabled
ln -sf "/etc/nginx/sites-available/${conf_name}" "/etc/nginx/sites-enabled/${conf_name}"
if [[ -f /etc/nginx/sites-enabled/default ]]; then
rm -f /etc/nginx/sites-enabled/default
info " 已移除 sites-enabled/default避免与 openim-pc-proxy 冲突"
fi
else
install -m 0644 "$conf_src" "/etc/nginx/conf.d/${conf_name}"
fi
nginx -t
systemctl enable nginx 2>/dev/null || true
systemctl restart nginx
success " Nginx 反代已启用(配置: $conf_src"
info " 请放行 TCP 80curl -sS http://127.0.0.1/nginx-health 应返回 ok"
info " .env.deploy-test 中 PC_BACKEND_ORIGIN=http://<公网IP>(与 DEPLOY_TEST_IP 一致)"
}
# all 时非 root 则跳过(不中断 Go/Node/Docker
_run_nginx_if_root() {
if [[ "$(id -u)" -eq 0 ]]; then
_install_pc_nginx_proxy
else
warn " 当前非 root已跳过 Nginx。需要时在服务器上执行: sudo $0 nginx"
fi
}
# ──────────────────────────────────────────────────────────────────────────────
# 执行
# ──────────────────────────────────────────────────────────────────────────────
@@ -258,15 +325,19 @@ case "$TARGET" in
docker)
_install_docker
;;
nginx)
_install_pc_nginx_proxy
;;
all)
_install_go
_config_goproxy
_install_node
_install_docker
_run_nginx_if_root
;;
*)
error "未知目标: $TARGET"
echo "用法: $0 [all|go|goproxy|node|docker]"
echo "用法: $0 [all|go|goproxy|node|docker|nginx]"
exit 1
;;
esac
@@ -284,6 +355,7 @@ _has npm && echo " npm: $(npm --version)" || echo
_has pnpm && echo " pnpm: $(pnpm --version)" || echo " pnpm: 未安装"
_has yarn && echo " yarn: $(yarn --version)" || echo " yarn: 未安装"
_has docker && echo " Docker: $(docker --version | awk '{print $3}' | tr -d ',')" || echo " Docker: 未安装"
_has nginx && echo " Nginx: $(nginx -v 2>&1 | sed 's/^nginx version: //')" || echo " Nginx: 未安装"
echo ""
echo -e "${BOLD}GOPROXY 配置:${NC}"
_has go && go env GOPROXY || echo " (go 未安装)"