新增GPU部分

This commit is contained in:
zeaslity
2025-11-12 18:14:10 +08:00
parent 4b274a02c8
commit fd60868b97
15 changed files with 1220 additions and 96 deletions

View File

@@ -0,0 +1,16 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: pyfusion-configmap
namespace: xakny
data:
config.yaml: |-
mqtt:
broker: "helm-emqxs"
port: 1883
username: "cmii"
password: "odD8#Ve7.B"
topics:
mqtt_topic: "bridge/DP74b4ef9fb4aaf269/device_data/FU_PAM/+"
sensor_topic: "fromcheck/DP74b4ef9fb4aaf269/device_data/FU_PAM/+"

View File

@@ -0,0 +1,9 @@
server {
listen 8088;
server_name localhost;
charset utf-8;
location / {
add_header Content-Type 'text/html; charset=utf-8';
return 200 "平台已过试用期,请联系系统管理员";
}
}

View File

@@ -0,0 +1,35 @@
# 关停
## 关停Nginx
1. 移动 /etc/nginx/conf.d/real-proxy.conf /etc/nginx/conf.d/real-proxy.conf_back
2. 移动 /etc/nginx/conf.d/offline.conf_back /etc/nginx/conf.d/offline.conf
3. 重启nginx systemctl restart nginx
## 执行harbor关停
docker-compose -f /root/wdd/harbor/docker-compose.yml down -v
## 执行关停暴露面
kubectl delete -f /root/wdd/install/k8s-ingress-nginx.yaml
## 执行关停脚本
bash /root/wdd/ccc.sh
# 恢复
## 恢复nginx
1. 移动 /etc/nginx/conf.d/real-proxy.conf_back /etc/nginx/conf.d/real-proxy.conf
2. 移动 /etc/nginx/conf.d/offline.conf /etc/nginx/conf.d/offline.conf_back
3. 重启nginx systemctl restart nginx
## 启动Harbor
docker-compose -f /root/wdd/harbor/docker-compose.yml up -d
等待30秒
## 开启ingress暴露面
kubectl apply -f /root/wdd/install/k8s-ingress-nginx.yaml
## 恢复业务
kubectl apply -f /root/wdd/all-deployment-xakny.yaml

View File

@@ -0,0 +1,167 @@
#!/bin/bash
#
# @author Assistant
# @version 1.0
# @license MIT
#
# Script to manage nginx configuration changes, stop harbor, and run a custom script.
# Logs all operations to /root/wdd/ccc.log with detailed levels.
#
# Dependencies:
# - Required commands: mv, systemctl, docker-compose, bash
# - File paths: /etc/nginx/conf.d/, /root/wdd/harbor/docker-compose.yml, /root/wdd/ccc.sh
# - Permissions: root access for file operations and systemctl
#
# Global Constants
readonly LOG_FILE="/root/wdd/ccc.log"
# Error handling: exit on error, unset variable, pipe failure; trap signals
set -euo pipefail
trap 'error_handler' EXIT ERR INT TERM
###
# Logs a message with timestamp and level to both the log file and stderr.
# @param level string The log level (DEBUG, INFO, WARN, ERROR)
# @param message string The message to log
# @return void
# @require date, tee commands
###
log() {
local level="$1"
local message="$2"
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$timestamp] [$level] $message" | tee -a "$LOG_FILE" >&2
}
###
# Handles errors during script execution, logs error, and exits.
# @return void
###
error_handler() {
local exit_code=$?
log ERROR "Script terminated with exit code $exit_code"
exit $exit_code
}
###
# Moves a file from source to destination with logging.
# @param source_path string Path to the source file
# @param dest_path string Path to the destination file
# @return 0 on success, non-zero on failure
# @require mv command
###
move_file() {
local source_path="$1"
local dest_path="$2"
log INFO "Moving file: $source_path to $dest_path"
# > Check if source exists before moving
if [[ ! -f "$source_path" ]]; then
log WARN "Source file $source_path does not exist, skipping move"
return 1
fi
mv "$source_path" "$dest_path"
log INFO "File moved successfully: $source_path to $dest_path"
return 0
}
###
# Restarts the nginx service with systemctl.
# @return 0 on success, non-zero on failure
# @require systemctl command, nginx service
###
restart_nginx() {
log INFO "Restarting nginx service"
systemctl restart nginx
log INFO "Nginx restarted successfully"
return 0
}
###
# Restarts the nginx service with systemctl.
# @return 0 on success, non-zero on failure
# @require systemctl command, nginx service
###
stop_ingress_expose() {
log INFO "Stop Ingress Exposition!"
kubectl delete -f /root/wdd/install/k8s-ingress-nginx.yaml
log INFO "Stop Ingress Exposition Success"
return 0
}
###
# Stops the harbor stack using docker-compose down.
# @return 0 on success, non-zero on failure
# @require docker-compose command, /root/wdd/harbor/docker-compose.yml
###
stop_harbor() {
local compose_file="/root/wdd/harbor/docker-compose.yml"
log INFO "Stopping harbor stack with docker-compose"
# > Check if docker-compose file exists
if [[ ! -f "$compose_file" ]]; then
log ERROR "Docker-compose file $compose_file not found"
return 1
fi
docker-compose -f "$compose_file" down -v
log INFO "Harbor stack stopped successfully"
return 0
}
###
# Executes a bash script with logging.
# @param script_path string Path to the script to execute
# @return Exit code of the executed script
# @require bash command
###
run_script() {
local script_path="$1"
log INFO "Executing script: $script_path"
# > Check if script exists and is executable
if [[ ! -f "$script_path" ]]; then
log ERROR "Script $script_path not found"
return 1
fi
if [[ ! -x "$script_path" ]]; then
log WARN "Script $script_path is not executable, attempting to run with bash"
fi
bash "$script_path"
local script_exit_code=$?
log INFO "Script executed with exit code: $script_exit_code"
return $script_exit_code
}
###
# Main function orchestrating the entire process.
# @return void
###
main() {
log INFO "Starting main script execution"
# Move first configuration file
move_file "/etc/nginx/conf.d/real-proxy.conf" "/etc/nginx/conf.d/real-proxy.conf_back"
# Move second configuration file
move_file "/etc/nginx/conf.d/offline.conf_back" "/etc/nginx/conf.d/offline.conf"
# Restart nginx service
restart_nginx
# Stop harbor stack
stop_harbor
# Execute the custom script
run_script "/root/wdd/ccc.sh"
log INFO "Main script completed successfully"
}
# Function Call Graph:
# main
# -> move_file (for real-proxy.conf)
# -> move_file (for offline.conf_back)
# -> restart_nginx
# -> stop_harbor
# -> run_script
# Execute main function
main "$@"

View File

@@ -0,0 +1,186 @@
#!/bin/bash
#
# Nginx及业务环境恢复脚本
# Author: AI Assistant
# Version: 1.0.0
# License: MIT
#
# 全局常量定义
readonly LOG_FILE="/root/wdd/ccc.log"
readonly NGINX_CONF_BACKUP="/etc/nginx/conf.d/real-proxy.conf_back"
readonly NGINX_CONF_LIVE="/etc/nginx/conf.d/real-proxy.conf"
readonly OFFLINE_CONF_LIVE="/etc/nginx/conf.d/offline.conf"
readonly OFFLINE_CONF_BACKUP="/etc/nginx/conf.d/offline.conf_back"
readonly HARBOR_COMPOSE_FILE="/root/wdd/harbor/docker-compose.yml"
readonly K8S_INGRESS_FILE="/root/wdd/install/k8s-ingress-nginx.yaml"
readonly K8S_DEPLOYMENT_FILE="/root/wdd/all-deployment-xakny.yaml"
# 依赖命令检查列表
readonly REQUIRED_COMMANDS=("systemctl" "docker-compose" "kubectl" "mv" "sleep")
# 初始化脚本执行环境
set -euo pipefail
trap 'log ERROR "脚本被中断"; exit 130' INT TERM
###
# 分级日志记录函数
# @param level string 日志级别DEBUG/INFO/WARN/ERROR
# @param message string 日志消息内容
# @return 无返回值
# @require 无外部依赖
###
log() {
local level="$1"
local message="$2"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local log_entry="[${timestamp}] ${level}: ${message}"
# 输出到控制台和日志文件
echo "${log_entry}" | tee -a "${LOG_FILE}" >&2
}
###
# 检查命令依赖是否存在
# @param 无参数
# @return 0-检查通过 1-缺少依赖
# @require 无外部依赖
###
check_dependencies() {
for cmd in "${REQUIRED_COMMANDS[@]}"; do
if ! command -v "${cmd}" &> /dev/null; then
log ERROR "缺少必要命令: ${cmd}"
return 1
fi
done
log DEBUG "所有依赖命令检查通过"
return 0
}
###
# 恢复Nginx配置文件并重启服务
# @param 无参数
# @return 0-操作成功 1-操作失败
# @require systemctl, mv命令
###
restore_nginx() {
log INFO "开始恢复Nginx配置"
# > 恢复主配置文件
if ! mv "${NGINX_CONF_BACKUP}" "${NGINX_CONF_LIVE}"; then
log ERROR "恢复real-proxy.conf失败"
return 1
fi
log DEBUG "成功恢复real-proxy.conf"
# > 备份离线配置文件
if ! mv "${OFFLINE_CONF_LIVE}" "${OFFLINE_CONF_BACKUP}"; then
log WARN "备份offline.conf失败可能文件不存在"
else
log DEBUG "成功备份offline.conf"
fi
# > 重启Nginx服务
if ! systemctl restart nginx; then
log ERROR "Nginx服务重启失败"
return 1
fi
log INFO "Nginx服务重启成功"
return 0
}
###
# 启动Harbor容器服务
# @param 无参数
# @return 0-启动成功 1-启动失败
# @require docker-compose, sleep命令
###
start_harbor() {
log INFO "开始启动Harbor服务"
if ! docker-compose -f "${HARBOR_COMPOSE_FILE}" up -d; then
log ERROR "Harbor启动失败"
return 1
fi
log INFO "Harbor启动完成等待30秒初始化..."
sleep 30
log DEBUG "Harbor初始化等待完成"
return 0
}
###
# 启用K8S Ingress暴露面
# @param 无参数
# @return 0-应用成功 1-应用失败
# @require kubectl命令
###
enable_ingress() {
log INFO "开始应用K8S Ingress配置"
if ! kubectl apply -f "${K8S_INGRESS_FILE}"; then
log ERROR "Ingress配置应用失败"
return 1
fi
log INFO "Ingress配置应用成功"
return 0
}
###
# 恢复业务Deployment配置
# @param 无参数
# @return 0-应用成功 1-应用失败
# @require kubectl命令
###
restore_business() {
log INFO "开始恢复业务Deployment"
if ! kubectl apply -f "${K8S_DEPLOYMENT_FILE}"; then
log ERROR "业务Deployment应用失败"
return 1
fi
log INFO "业务Deployment恢复成功"
return 0
}
###
# 主执行函数
# @param 无参数
# @return 0-全部成功 1-任意步骤失败
# @require 所有子函数依赖
###
main() {
log INFO "===== 开始执行环境恢复脚本 ====="
# > 检查命令依赖
if ! check_dependencies; then
log ERROR "依赖检查失败,脚本终止"
return 1
fi
# 函数执行序列
local steps=(
restore_nginx
start_harbor
enable_ingress
restore_business
)
for step in "${steps[@]}"; do
if ! ${step}; then
log ERROR "执行步骤 ${step} 失败"
return 1
fi
done
log INFO "===== 环境恢复脚本执行完成 ====="
return 0
}
# 执行主函数并捕获退出状态
if main; then
exit 0
else
exit 1
fi

View File

@@ -0,0 +1,50 @@
upstream proxy_server {
ip_hash;
server 192.168.0.3:30500;
server 192.168.0.4:30500;
server 192.168.0.5:30500;
}
server {
listen 8088;
server_name localhost;
location / {
proxy_pass http://proxy_server;
client_max_body_size 5120m;
client_body_buffer_size 5120m;
client_body_timeout 6000s;
proxy_send_timeout 10000s;
proxy_read_timeout 10000s;
proxy_connect_timeout 600s;
proxy_max_temp_file_size 5120m;
proxy_request_buffering on;
proxy_buffering off;
proxy_buffer_size 4k;
proxy_buffers 4 12k;
proxy_set_header Host fake-domain.xakny.io;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /_AMapService/v4/map/styles {
set $args "$args&jscode=cf66cea95bdcdfcf8048456b36f357a1";
proxy_pass https://webapi.amap.com/v4/ap/styles;
}
location /_AMapService/ {
set $args "$args&jscode=cf66cea95bdcdfcf8048456b36f357a1";
proxy_pass https://restapi.amap.com/;
}
location /rtc/v1/ {
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
proxy_pass http://127.0.0.1:30985/rtc/v1/;
}
location ~ ^/\w*/actuator/ {
return 403;
}
}

View File

@@ -1,3 +1,7 @@
%}3}vbJXWv
%}3}vbJXWv
192.168.0.2
SuperCyy.123