更新 goedge_add_node.sh
This commit is contained in:
parent
8ec57d1ad3
commit
d0e73a6a97
@ -56,7 +56,13 @@ CLUSTER_ID=""
|
|||||||
GROUP_ID=0
|
GROUP_ID=0
|
||||||
REGION_ID=0
|
REGION_ID=0
|
||||||
DNS_ROUTES=""
|
DNS_ROUTES=""
|
||||||
API_HOSTS=() # 存放多个API地址
|
|
||||||
|
# HTTP_API: 必填,用于脚本调用HTTP接口
|
||||||
|
HTTP_API=""
|
||||||
|
|
||||||
|
# RPC endpoints: 用于写入 api_node.yaml,可多地址
|
||||||
|
API_HOSTS=()
|
||||||
|
|
||||||
GRANT_ID=1 # 默认
|
GRANT_ID=1 # 默认
|
||||||
WEB_INSTALL=0 # 是否使用 --webinstall
|
WEB_INSTALL=0 # 是否使用 --webinstall
|
||||||
|
|
||||||
@ -94,8 +100,12 @@ while [[ $# -gt 0 ]]; do
|
|||||||
DNS_ROUTES="$2"
|
DNS_ROUTES="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--http-api)
|
||||||
|
HTTP_API="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
--api-host)
|
--api-host)
|
||||||
# 将后续所有非开头带 "--" 的参数视为host(可多个)
|
# 将后续所有非开头带 "--" 的参数视为RPC地址(可多个)
|
||||||
shift
|
shift
|
||||||
while [[ $# -gt 0 && ! $1 =~ ^-- ]]; do
|
while [[ $# -gt 0 && ! $1 =~ ^-- ]]; do
|
||||||
API_HOSTS+=("$1")
|
API_HOSTS+=("$1")
|
||||||
@ -113,20 +123,17 @@ while [[ $# -gt 0 ]]; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# 校验必填: acid, ackey, clusterid, api-host
|
# 校验必填: acid, ackey, clusterid, http-api
|
||||||
if [[ -z "$ACID" || -z "$ACKEY" || -z "$CLUSTER_ID" ]]; then
|
if [[ -z "$ACID" || -z "$ACKEY" || -z "$CLUSTER_ID" ]]; then
|
||||||
echo "[ERROR] 用法: $0 --acid <ACCESS_KEY_ID> --ackey <ACCESS_KEY> --clusterid <CLUSTER_ID> [--grantid <GRANT_ID>] [--name <NAME>] [--groupid <GROUP_ID>] [--regionid <REGION_ID>] [--dnsroutes <DNS_ROUTES>] [--api-host <HOST1> [HOST2]...] [--webinstall]"
|
echo "[ERROR] 用法: $0 --acid <ACCESS_KEY_ID> --ackey <ACCESS_KEY> --clusterid <CLUSTER_ID> --http-api <HTTP_API> [--grantid <GRANT_ID>] [--name <NAME>] [--groupid <GROUP_ID>] [--regionid <REGION_ID>] [--dnsroutes <DNS_ROUTES>] [--api-host <RPC1> [RPC2]...] [--webinstall]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ${#API_HOSTS[@]} -eq 0 ]]; then
|
if [[ -z "$HTTP_API" ]]; then
|
||||||
echo "[ERROR] 必须至少指定一个 --api-host"
|
echo "[ERROR] 必须指定 --http-api <HTTP_API>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 假设脚本中要选第一个 API_HOSTS[0] 作为获取 Token 的地址
|
|
||||||
MAIN_API_HOST="${API_HOSTS[0]}"
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# 3. 获取本机 IPv4, 拼装默认名称
|
# 3. 获取本机 IPv4, 拼装默认名称
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -145,12 +152,12 @@ if [[ -z "$NAME" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# 4. 获取 Token
|
# 4. 获取 Token (使用 HTTP_API)
|
||||||
###############################################################################
|
###############################################################################
|
||||||
echo "[INFO] 获取 Token..."
|
echo "[INFO] 获取 Token..."
|
||||||
get_token_resp=$(curl -s -X POST \
|
get_token_resp=$(curl -s -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
"$MAIN_API_HOST/APIAccessTokenService/getAPIAccessToken" \
|
"$HTTP_API/APIAccessTokenService/getAPIAccessToken" \
|
||||||
-d '{
|
-d '{
|
||||||
"type": "admin",
|
"type": "admin",
|
||||||
"accessKeyId": "'"$ACID"'",
|
"accessKeyId": "'"$ACID"'",
|
||||||
@ -206,7 +213,7 @@ EOF
|
|||||||
create_node_resp=$(curl -s -X POST \
|
create_node_resp=$(curl -s -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "X-Edge-Access-Token: $TOKEN" \
|
-H "X-Edge-Access-Token: $TOKEN" \
|
||||||
"$MAIN_API_HOST/NodeService/createNode" \
|
"$HTTP_API/NodeService/createNode" \
|
||||||
-d "$create_node_payload"
|
-d "$create_node_payload"
|
||||||
)
|
)
|
||||||
create_node_code=$(echo "$create_node_resp" | jq -r '.code')
|
create_node_code=$(echo "$create_node_resp" | jq -r '.code')
|
||||||
@ -249,7 +256,7 @@ EOF
|
|||||||
create_ips_resp=$(curl -s -X POST \
|
create_ips_resp=$(curl -s -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "X-Edge-Access-Token: $TOKEN" \
|
-H "X-Edge-Access-Token: $TOKEN" \
|
||||||
"$MAIN_API_HOST/NodeIPAddressService/createNodeIPAddresses" \
|
"$HTTP_API/NodeIPAddressService/createNodeIPAddresses" \
|
||||||
-d "$create_ips_payload"
|
-d "$create_ips_payload"
|
||||||
)
|
)
|
||||||
create_ips_code=$(echo "$create_ips_resp" | jq -r '.code')
|
create_ips_code=$(echo "$create_ips_resp" | jq -r '.code')
|
||||||
@ -267,7 +274,7 @@ echo "[INFO] 获取节点信息..."
|
|||||||
find_node_resp=$(curl -s -X POST \
|
find_node_resp=$(curl -s -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "X-Edge-Access-Token: $TOKEN" \
|
-H "X-Edge-Access-Token: $TOKEN" \
|
||||||
"$MAIN_API_HOST/NodeService/findEnabledNode" \
|
"$HTTP_API/NodeService/findEnabledNode" \
|
||||||
-d '{
|
-d '{
|
||||||
"nodeId": '"$NODE_ID"'
|
"nodeId": '"$NODE_ID"'
|
||||||
}'
|
}'
|
||||||
@ -298,7 +305,7 @@ EOF
|
|||||||
install_node_resp=$(curl -s -X POST \
|
install_node_resp=$(curl -s -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "X-Edge-Access-Token: $TOKEN" \
|
-H "X-Edge-Access-Token: $TOKEN" \
|
||||||
"$MAIN_API_HOST/NodeService/installNode" \
|
"$HTTP_API/NodeService/installNode" \
|
||||||
-d "$install_node_payload"
|
-d "$install_node_payload"
|
||||||
)
|
)
|
||||||
install_node_code=$(echo "$install_node_resp" | jq -r '.code')
|
install_node_code=$(echo "$install_node_resp" | jq -r '.code')
|
||||||
@ -308,8 +315,8 @@ EOF
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
# -------------------- 非web面板安装 -------------------- #
|
# -------------------- 手动安装模式 -------------------- #
|
||||||
echo "[INFO] 未指定 --webinstall,进入非web面板安装流程..."
|
echo "[INFO] 未指定 --webinstall,进入手动安装流程..."
|
||||||
|
|
||||||
if [[ ! -d /usr/local/goedge ]]; then
|
if [[ ! -d /usr/local/goedge ]]; then
|
||||||
sudo mkdir -p /usr/local/goedge
|
sudo mkdir -p /usr/local/goedge
|
||||||
@ -331,18 +338,17 @@ else
|
|||||||
|
|
||||||
sudo unzip -o edge-node.zip
|
sudo unzip -o edge-node.zip
|
||||||
|
|
||||||
# 将多个 API_HOSTS 拼成 JSON 数组(如果需要)
|
RPC_ENDPOINTS_JSON='[]'
|
||||||
# 例如:["https://1.2.3.4:8001","https://edge2.xxx.com:8001"]
|
if [[ ${#API_HOSTS[@]} -gt 0 ]]; then
|
||||||
# 这里只把它们转成空格->"",""简单写入
|
RPC_ENDPOINTS_JSON='['
|
||||||
# 当然也可保留只写API_HOSTS[0]
|
for ((i=0; i<${#API_HOSTS[@]}; i++)); do
|
||||||
RPC_ENDPOINTS_JSON='['
|
RPC_ENDPOINTS_JSON+="\"${API_HOSTS[i]}\""
|
||||||
for ((i=0; i<${#API_HOSTS[@]}; i++)); do
|
if [[ $i -lt $(( ${#API_HOSTS[@]} - 1 )) ]]; then
|
||||||
RPC_ENDPOINTS_JSON+="\"${API_HOSTS[i]}\""
|
RPC_ENDPOINTS_JSON+=","
|
||||||
if [[ $i -lt $(( ${#API_HOSTS[@]} - 1 )) ]]; then
|
fi
|
||||||
RPC_ENDPOINTS_JSON+=","
|
done
|
||||||
fi
|
RPC_ENDPOINTS_JSON+=']'
|
||||||
done
|
fi
|
||||||
RPC_ENDPOINTS_JSON+=']'
|
|
||||||
|
|
||||||
if [[ ! -f /usr/local/goedge/edge-node/configs/api_node.yaml ]]; then
|
if [[ ! -f /usr/local/goedge/edge-node/configs/api_node.yaml ]]; then
|
||||||
sudo tee /usr/local/goedge/edge-node/configs/api_node.yaml >/dev/null <<EOT
|
sudo tee /usr/local/goedge/edge-node/configs/api_node.yaml >/dev/null <<EOT
|
||||||
@ -352,7 +358,6 @@ secret: ""
|
|||||||
EOT
|
EOT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 将 rpc.endpoints 改为多地址数组
|
|
||||||
sudo sed -i "s|^rpc.endpoints:.*|rpc.endpoints: $RPC_ENDPOINTS_JSON|g" /usr/local/goedge/edge-node/configs/api_node.yaml
|
sudo sed -i "s|^rpc.endpoints:.*|rpc.endpoints: $RPC_ENDPOINTS_JSON|g" /usr/local/goedge/edge-node/configs/api_node.yaml
|
||||||
sudo sed -i "s|^nodeId:.*|nodeId: \"$NODE_UNIQUE_ID\"|g" /usr/local/goedge/edge-node/configs/api_node.yaml
|
sudo sed -i "s|^nodeId:.*|nodeId: \"$NODE_UNIQUE_ID\"|g" /usr/local/goedge/edge-node/configs/api_node.yaml
|
||||||
sudo sed -i "s|^secret:.*|secret: \"$NODE_SECRET\"|g" /usr/local/goedge/edge-node/configs/api_node.yaml
|
sudo sed -i "s|^secret:.*|secret: \"$NODE_SECRET\"|g" /usr/local/goedge/edge-node/configs/api_node.yaml
|
||||||
@ -373,7 +378,7 @@ EOF
|
|||||||
update_resp=$(curl -s -X POST \
|
update_resp=$(curl -s -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "X-Edge-Access-Token: $TOKEN" \
|
-H "X-Edge-Access-Token: $TOKEN" \
|
||||||
"$MAIN_API_HOST/NodeService/updateNodeIsInstalled" \
|
"$HTTP_API/NodeService/updateNodeIsInstalled" \
|
||||||
-d "$update_payload"
|
-d "$update_payload"
|
||||||
)
|
)
|
||||||
update_code=$(echo "$update_resp" | jq -r '.code')
|
update_code=$(echo "$update_resp" | jq -r '.code')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user