first
This commit is contained in:
109
domain-api/deploy/multi-region/install_mainland_worker_quick.sh
Executable file
109
domain-api/deploy/multi-region/install_mainland_worker_quick.sh
Executable file
@@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
CONFIG_FILE="${SCRIPT_DIR}/install_mainland_worker_quick.conf"
|
||||
CONFIG_EXAMPLE="${SCRIPT_DIR}/install_mainland_worker_quick.conf.example"
|
||||
|
||||
if [[ ! -f "${CONFIG_FILE}" ]]; then
|
||||
echo "未找到配置文件:${CONFIG_FILE}"
|
||||
echo "请先执行:cp ${CONFIG_EXAMPLE} ${CONFIG_FILE}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "${CONFIG_FILE}"
|
||||
|
||||
: "${GIT_REPO_URL:=YOUR_GIT_REPO_URL}"
|
||||
: "${GIT_BRANCH:=main}"
|
||||
: "${DB_NAME:=domain}"
|
||||
: "${DB_USER:=domainuser}"
|
||||
: "${DB_PASSWORD:=CHANGE_ME_DB_PASSWORD}"
|
||||
: "${SYNC_SHARED_TOKEN:=CHANGE_ME_SYNC_SHARED_TOKEN}"
|
||||
: "${MAINLAND_WORKER_NODE_CODE:=mainland-worker-01}"
|
||||
: "${MAINLAND_CONTROLLER_IP:=127.0.0.1}"
|
||||
: "${TARGET_API_BASE_URL:=https://api.domain.com/api/v1}"
|
||||
|
||||
WORKSPACE_ROOT="/www/wwwroot"
|
||||
REPO_DIR="${WORKSPACE_ROOT}/getDomain"
|
||||
BASE_DIR="/opt/domaincheck"
|
||||
DOMAINCHECK_DIR="${BASE_DIR}/domainCheck"
|
||||
DOMAIN_API_DIR="${BASE_DIR}/domain-api"
|
||||
|
||||
if [[ "${GIT_REPO_URL}" == "YOUR_GIT_REPO_URL" || "${DB_PASSWORD}" == "CHANGE_ME_DB_PASSWORD" || "${SYNC_SHARED_TOKEN}" == "CHANGE_ME_SYNC_SHARED_TOKEN" || "${MAINLAND_CONTROLLER_IP}" == "127.0.0.1" ]]; then
|
||||
echo "请先修改配置文件中的必填项:GIT_REPO_URL / DB_PASSWORD / SYNC_SHARED_TOKEN / MAINLAND_CONTROLLER_IP"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "${WORKSPACE_ROOT}"
|
||||
cd "${WORKSPACE_ROOT}"
|
||||
if [[ ! -d "${REPO_DIR}/.git" ]]; then
|
||||
git clone "${GIT_REPO_URL}" getDomain
|
||||
fi
|
||||
cd "${REPO_DIR}"
|
||||
git fetch --all
|
||||
git checkout "${GIT_BRANCH}"
|
||||
git pull --ff-only origin "${GIT_BRANCH}"
|
||||
|
||||
mkdir -p "${BASE_DIR}"
|
||||
ln -sfn "${REPO_DIR}/domain-api" "${DOMAIN_API_DIR}"
|
||||
ln -sfn "${REPO_DIR}/domain-web" "${BASE_DIR}/domain-web"
|
||||
ln -sfn "${REPO_DIR}/domainCheck" "${DOMAINCHECK_DIR}"
|
||||
|
||||
cd "${DOMAINCHECK_DIR}"
|
||||
python3.11 -m venv .venv || true
|
||||
source .venv/bin/activate
|
||||
pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
"${DOMAINCHECK_DIR}/.venv/bin/pip" install fastapi uvicorn pydantic-settings psycopg2-binary redis openpyxl python-multipart
|
||||
|
||||
cat >"${DOMAINCHECK_DIR}/.env" <<EOF
|
||||
DB_HOST=${MAINLAND_CONTROLLER_IP}
|
||||
DB_PORT=5432
|
||||
DB_DATABASE=${DB_NAME}
|
||||
DB_USER=${DB_USER}
|
||||
DB_PASSWORD=${DB_PASSWORD}
|
||||
|
||||
REDIS_HOST=${MAINLAND_CONTROLLER_IP}
|
||||
REDIS_PORT=6379
|
||||
REDIS_PASSWORD=
|
||||
REDIS_DB=0
|
||||
EOF
|
||||
|
||||
cd "${DOMAIN_API_DIR}"
|
||||
bash deploy/multi-region/bootstrap_mainland.sh /opt/domaincheck worker
|
||||
|
||||
cat >/etc/default/domaincheck-worker <<EOF
|
||||
WORKER_MODE=linux-systemd
|
||||
QT_QPA_PLATFORM=offscreen
|
||||
NODE_CODE=${MAINLAND_WORKER_NODE_CODE}
|
||||
NODE_REGION=mainland
|
||||
NODE_ROLE=worker
|
||||
|
||||
DB_HOST=${MAINLAND_CONTROLLER_IP}
|
||||
DB_PORT=5432
|
||||
DB_DATABASE=${DB_NAME}
|
||||
DB_USER=${DB_USER}
|
||||
DB_PASSWORD=${DB_PASSWORD}
|
||||
|
||||
REDIS_HOST=${MAINLAND_CONTROLLER_IP}
|
||||
REDIS_PORT=6379
|
||||
REDIS_PASSWORD=
|
||||
REDIS_DB=0
|
||||
|
||||
SYNC_PUSH_ENABLED=true
|
||||
SYNC_SOURCE_REGION=mainland
|
||||
SYNC_TARGET_REGION=overseas
|
||||
SYNC_TARGET_API_BASE_URL=${TARGET_API_BASE_URL}
|
||||
SYNC_SHARED_TOKEN=${SYNC_SHARED_TOKEN}
|
||||
SYNC_BATCH_SIZE=200
|
||||
SYNC_POLL_INTERVAL_SECONDS=30
|
||||
EOF
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable domaincheck-worker
|
||||
systemctl restart domaincheck-worker
|
||||
|
||||
echo
|
||||
echo "国内 worker 部署完成,建议继续在国外机查看:"
|
||||
echo "curl https://api.domain.com/api/v1/runtime/cluster"
|
||||
Reference in New Issue
Block a user