test
This commit is contained in:
@@ -7,8 +7,9 @@
|
||||
# 2. 配置 GOPROXY(自动测速选最快节点)
|
||||
# 3. 安装 Node.js / npm(前端依赖)
|
||||
# 4. 安装 Docker(基础设施容器)
|
||||
# 5. 安装 Nginx 并写入 PC/OpenIM 反代(本机 HTTP :80;外部 HTTPS 由 LB/CDN 终止)
|
||||
# 6. 写入 /etc/profile.d/deploy-env.sh(永久生效)
|
||||
# 5. 安装 etcdctl(查看 Etcd 服务注册)
|
||||
# 6. 安装 Nginx 并写入 PC/OpenIM 反代(本机 HTTP :80;外部 HTTPS 由 LB/CDN 终止)
|
||||
# 7. 写入 /etc/profile.d/deploy-env.sh(永久生效)
|
||||
#
|
||||
# 用法:
|
||||
# ./deploy-test/00-init-tools.sh # 安装全部(含 Nginx 反代)
|
||||
@@ -16,6 +17,7 @@
|
||||
# ./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 etcdctl # 只安装 etcdctl(需 root)
|
||||
# sudo ./deploy-test/00-init-tools.sh nginx # 只安装 Nginx 反代(需 root)
|
||||
#
|
||||
# 前置条件: root 或 sudo 权限,Ubuntu/Debian 系统
|
||||
@@ -31,6 +33,7 @@ init_script_log
|
||||
GO_VERSION="${GO_VERSION:-1.22.5}"
|
||||
GO_ARCH="${GO_ARCH:-amd64}" # amd64 / arm64
|
||||
NODE_VERSION="${NODE_VERSION:-20}" # Node.js LTS 大版本
|
||||
ETCDCTL_VERSION="${ETCDCTL_VERSION:-3.5.17}"
|
||||
PROFILE_FILE="/etc/profile.d/deploy-env.sh"
|
||||
|
||||
TARGET="${1:-all}"
|
||||
@@ -244,7 +247,69 @@ _install_docker() {
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
# 5. Nginx — PC / OpenIM 统一入口(本机 HTTP :80)
|
||||
# 5. etcdctl
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
_install_etcdctl() {
|
||||
step "安装 etcdctl ${ETCDCTL_VERSION}"
|
||||
|
||||
if _has etcdctl; then
|
||||
success " etcdctl 已安装: $(etcdctl version | head -1)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "$(id -u)" -ne 0 ]]; then
|
||||
warn " etcdctl 安装需 root,请执行: sudo $0 etcdctl"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if _has apt-get; then
|
||||
apt-get update -y
|
||||
if apt-get install -y etcd-client; then
|
||||
success " etcdctl 安装完成: $(etcdctl version | head -1)"
|
||||
return 0
|
||||
fi
|
||||
warn " apt 安装 etcd-client 失败,尝试下载官方二进制"
|
||||
elif _has dnf; then
|
||||
if dnf install -y etcd; then
|
||||
success " etcdctl 安装完成: $(etcdctl version | head -1)"
|
||||
return 0
|
||||
fi
|
||||
warn " dnf 安装 etcd 失败,尝试下载官方二进制"
|
||||
elif _has yum; then
|
||||
if yum install -y etcd; then
|
||||
success " etcdctl 安装完成: $(etcdctl version | head -1)"
|
||||
return 0
|
||||
fi
|
||||
warn " yum 安装 etcd 失败,尝试下载官方二进制"
|
||||
fi
|
||||
|
||||
local arch
|
||||
case "$(uname -m)" in
|
||||
x86_64|amd64) arch="amd64" ;;
|
||||
aarch64|arm64) arch="arm64" ;;
|
||||
*)
|
||||
error " 不支持的架构: $(uname -m),请手动安装 etcdctl"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
local tarball="etcd-v${ETCDCTL_VERSION}-linux-${arch}.tar.gz"
|
||||
local url="https://github.com/etcd-io/etcd/releases/download/v${ETCDCTL_VERSION}/${tarball}"
|
||||
local tmp="/tmp/${tarball}"
|
||||
local out_dir="/tmp/etcd-v${ETCDCTL_VERSION}-linux-${arch}"
|
||||
|
||||
info " 下载 ${url}"
|
||||
curl -fL --progress-bar -o "$tmp" "$url"
|
||||
rm -rf "$out_dir"
|
||||
tar -C /tmp -xzf "$tmp"
|
||||
install -m 0755 "${out_dir}/etcdctl" /usr/local/bin/etcdctl
|
||||
rm -rf "$tmp" "$out_dir"
|
||||
|
||||
success " etcdctl 安装完成: $(etcdctl version | head -1)"
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
# 6. Nginx — PC / OpenIM 统一入口(本机 HTTP :80)
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
_install_pc_nginx_proxy() {
|
||||
step "安装 Nginx 并配置 OpenIM/PC 反代"
|
||||
@@ -317,7 +382,7 @@ _install_pc_nginx_proxy() {
|
||||
info " 浏览器打开 https://${proxy_domain}/"
|
||||
}
|
||||
|
||||
# all 时非 root 则跳过(不中断 Go/Node/Docker)
|
||||
# all 时非 root 则跳过(不中断 Go/Node/Docker/etcdctl)
|
||||
_run_nginx_if_root() {
|
||||
if [[ "$(id -u)" -eq 0 ]]; then
|
||||
_install_pc_nginx_proxy
|
||||
@@ -343,6 +408,9 @@ case "$TARGET" in
|
||||
docker)
|
||||
_install_docker
|
||||
;;
|
||||
etcdctl)
|
||||
_install_etcdctl
|
||||
;;
|
||||
nginx)
|
||||
_install_pc_nginx_proxy
|
||||
;;
|
||||
@@ -351,11 +419,12 @@ case "$TARGET" in
|
||||
_config_goproxy
|
||||
_install_node
|
||||
_install_docker
|
||||
_install_etcdctl
|
||||
_run_nginx_if_root
|
||||
;;
|
||||
*)
|
||||
error "未知目标: $TARGET"
|
||||
echo "用法: $0 [all|go|goproxy|node|docker|nginx]"
|
||||
echo "用法: $0 [all|go|goproxy|node|docker|etcdctl|nginx]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -373,6 +442,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 etcdctl && echo " etcdctl: $(etcdctl version | head -1 | sed 's/^etcdctl version: //')" || echo " etcdctl: 未安装"
|
||||
_has nginx && echo " Nginx: $(nginx -v 2>&1 | sed 's/^nginx version: //')" || echo " Nginx: 未安装"
|
||||
echo ""
|
||||
echo -e "${BOLD}GOPROXY 配置:${NC}"
|
||||
|
||||
Reference in New Issue
Block a user