新增深圳 K3s agent 与四节点 WireGuard 全互联接入脚本,将深圳归入香港逻辑 Worker 池并用污点限制为 Worker 专用。\n\n生产验收支持宁波 0、香港逻辑池 2 的双物理节点基线,补充副本拓扑分散、容量档位、链路巡检和零副本站点校验。\n\n已通过 Go 全量测试、go vet、govulncheck、迁移安全检查、ShellCheck、发布脚本测试、前后端 lint/test/build、Compose 与 Kubernetes 渲染校验。
101 lines
2.7 KiB
Bash
Executable File
101 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
cluster_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
|
|
cluster_env_file=${AI_GATEWAY_CLUSTER_ENV_FILE:-"$cluster_root/.env.local"}
|
|
cluster_ssh_key=${AI_GATEWAY_CLUSTER_SSH_KEY:-"$HOME/.ssh/id_ed25519_easyai_gateway_cluster"}
|
|
|
|
load_cluster_env() {
|
|
[[ -f $cluster_env_file && ! -L $cluster_env_file ]] || {
|
|
echo "missing local cluster environment file: $cluster_env_file" >&2
|
|
return 1
|
|
}
|
|
set -a
|
|
# shellcheck source=/dev/null
|
|
source "$cluster_env_file"
|
|
set +a
|
|
cluster_ssh_key=${AI_GATEWAY_CLUSTER_SSH_KEY:-$cluster_ssh_key}
|
|
|
|
: "${AI_GATEWAY_DEPLOY_HOST:?}"
|
|
: "${AI_GATEWAY_DEPLOY_HOST_2:?}"
|
|
: "${AI_GATEWAY_DEPLOY_HOST_3:?}"
|
|
: "${ALI_KEY:?}"
|
|
: "${ALI_SECRET:?}"
|
|
: "${ALI_REGION:?}"
|
|
: "${ALI_BUCKET:?}"
|
|
|
|
CLUSTER_NINGBO_HOST=${AI_GATEWAY_NINGBO_HOST:-$AI_GATEWAY_DEPLOY_HOST}
|
|
CLUSTER_LOS_ANGELES_HOST=${AI_GATEWAY_LOS_ANGELES_HOST:-$AI_GATEWAY_DEPLOY_HOST_2}
|
|
CLUSTER_HONGKONG_HOST=${AI_GATEWAY_HONGKONG_HOST:-$AI_GATEWAY_DEPLOY_HOST_3}
|
|
CLUSTER_SHENZHEN_HOST=${AI_GATEWAY_SHENZHEN_HOST:-}
|
|
export CLUSTER_NINGBO_HOST CLUSTER_LOS_ANGELES_HOST CLUSTER_HONGKONG_HOST CLUSTER_SHENZHEN_HOST
|
|
|
|
for host in "$CLUSTER_NINGBO_HOST" "$CLUSTER_HONGKONG_HOST" "$CLUSTER_LOS_ANGELES_HOST"; do
|
|
[[ $host =~ ^root@[A-Za-z0-9.-]+$ ]] || {
|
|
echo "cluster hosts must use root@host syntax" >&2
|
|
return 1
|
|
}
|
|
done
|
|
if [[ -n $CLUSTER_SHENZHEN_HOST && ! $CLUSTER_SHENZHEN_HOST =~ ^root@[A-Za-z0-9.-]+$ ]]; then
|
|
echo "Shenzhen Worker host must use root@host syntax" >&2
|
|
return 1
|
|
fi
|
|
[[ $ALI_REGION =~ ^[a-z0-9-]+$ && $ALI_BUCKET =~ ^[A-Za-z0-9.-]+$ ]] || {
|
|
echo 'invalid OSS region or bucket' >&2
|
|
return 1
|
|
}
|
|
[[ -f $cluster_ssh_key && ! -L $cluster_ssh_key ]] || {
|
|
echo "missing cluster SSH key: $cluster_ssh_key" >&2
|
|
return 1
|
|
}
|
|
}
|
|
|
|
cluster_ssh() {
|
|
local host=$1
|
|
shift
|
|
ssh \
|
|
-i "$cluster_ssh_key" \
|
|
-o BatchMode=yes \
|
|
-o ConnectTimeout=10 \
|
|
-o ServerAliveInterval=15 \
|
|
-o ServerAliveCountMax=3 \
|
|
"$host" "$@"
|
|
}
|
|
|
|
cluster_scp() {
|
|
scp \
|
|
-i "$cluster_ssh_key" \
|
|
-o BatchMode=yes \
|
|
-o ConnectTimeout=10 \
|
|
"$@"
|
|
}
|
|
|
|
require_commands() {
|
|
local command
|
|
for command in "$@"; do
|
|
command -v "$command" >/dev/null 2>&1 || {
|
|
echo "$command is required" >&2
|
|
return 1
|
|
}
|
|
done
|
|
}
|
|
|
|
assert_private_file() {
|
|
local path=$1
|
|
local mode
|
|
[[ -f $path && ! -L $path ]] || {
|
|
echo "missing private file: $path" >&2
|
|
return 1
|
|
}
|
|
if [[ $(uname -s) == Darwin ]]; then
|
|
mode=$(stat -f '%Lp' "$path")
|
|
else
|
|
mode=$(stat -c '%a' "$path")
|
|
fi
|
|
[[ $mode == 600 ]] || {
|
|
echo "private file must have mode 0600: $path" >&2
|
|
return 1
|
|
}
|
|
}
|