提交 e446b17b authored 作者: 陈泽健's avatar 陈泽健

Merge remote-tracking branch 'origin/develop' into develop

...@@ -151,4 +151,32 @@ docker run -itd -p 8002:8002 -p 8000:8000 -p 8443:8443 -p 9009:9009 -v /var/www ...@@ -151,4 +151,32 @@ docker run -itd -p 8002:8002 -p 8000:8000 -p 8443:8443 -p 9009:9009 -v /var/www
### 应对措施 ### 应对措施
- 在构建过程中测试关键依赖的兼容性 - 在构建过程中测试关键依赖的兼容性
- 定期更新基础镜像和依赖包版本 - 定期更新基础镜像和依赖包版本
- 使用Docker安全扫描工具检查镜像漏洞 - 使用Docker安全扫描工具检查镜像漏洞
\ No newline at end of file
问题:
1、ModuleNotFoundError: No module named 'Crypto'
解决:pip install pycryptodome
实际安装:pycryptodome-3.23.0
2、ModuleNotFoundError: No module named 'requests'
解决:pip3 install requests
实际安装:installed certifi-2026.1.4 charset_normalizer-3.4.4 idna-3.11 requests-2.32.5 urllib3-2.6.3
3、ModuleNotFoundError: No module named 'PIL'
解决:pip3 install Pillow
实际安装:Pillow-12.1.0
4、ModuleNotFoundError: No module named 'debug_toolbar'
解决:pip3 install django-debug-toolbar
实际安装:django-debug-toolbar-6.1.0
5、ModuleNotFoundError: No module named 'rest_framework'
解决:pip3 install djangorestframework
实际安装:djangorestframework-3.16.1
6、ModuleNotFoundError: No module named 'rest_framework_swagger':
不兼容,官方推荐迁移到 drf-spectacular
7、
\ No newline at end of file
...@@ -964,7 +964,6 @@ function emqx_x86() ...@@ -964,7 +964,6 @@ function emqx_x86()
local container_name="uemqx" local container_name="uemqx"
local image_tar="/data/temp/uemqx5.8.7.tar.gz" local image_tar="/data/temp/uemqx5.8.7.tar.gz"
local image_name="emqx/emqx:5.8.7" local image_name="emqx/emqx:5.8.7"
local image_id="b3a758c850bb"
local host_config_dir="/data/middleware/emqx/config" local host_config_dir="/data/middleware/emqx/config"
local host_dir="/data/middleware/emqx" local host_dir="/data/middleware/emqx"
...@@ -1010,19 +1009,15 @@ function emqx_x86() ...@@ -1010,19 +1009,15 @@ function emqx_x86()
--name "$container_name" \ --name "$container_name" \
--mac-address="02:42:ac:12:00:06" \ --mac-address="02:42:ac:12:00:06" \
--privileged \ --privileged \
--cap-add ALL \ --restart=always \
--security-opt seccomp=unconfined \
--security-opt apparmor=unconfined \
--user root \
-p 1883:1883 \ -p 1883:1883 \
-p 8083:8083 \ -p 8083:8083 \
-p 8883:8883 \ -p 8883:8883 \
-v "$host_config_dir/emqx.conf:/opt/emqx/etc/emqx.conf:ro" \ -v "$host_config_dir/emqx.conf:/opt/emqx/etc/emqx.conf:ro" \
-v "$host_config_dir/auth-built-in-db-bootstrap.csv:/opt/emqx/etc/auth-built-in-db-bootstrap.csv:ro" \ -v "$host_config_dir/auth-built-in-db-bootstrap.csv:/opt/emqx/etc/auth-built-in-db-bootstrap.csv:ro" \
-v "$host_config_dir/acl.conf:/opt/emqx/etc/acl.conf:ro" \ -v "$host_config_dir/acl.conf:/opt/emqx/etc/acl.conf:ro" \
-v "$host_dir/data:/opt/emqx/data" \ -v "$host_dir/data:/opt/emqx/data" \
-v "$host_dir/log:/opt/emqx/log" \ -v "$host_dir/log:/opt/emqx/log" \
--restart=always \
"$image_name" "$image_name"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
...@@ -2783,6 +2778,38 @@ function nginx_x86() { ...@@ -2783,6 +2778,38 @@ function nginx_x86() {
fi fi
log "INFO" "镜像加载成功" log "INFO" "镜像加载成功"
# 检查证书文件是否存在,如果不存在则生成自签名证书
local cert_dir="/data/security/nginx_cert"
local cert_file="$cert_dir/server.crt"
local key_file="$cert_dir/server.key"
if [ ! -f "$cert_file" ] || [ ! -f "$key_file" ]; then
log "WARN" "证书文件不存在,正在生成自签名证书..."
# 进入证书目录
cd "$cert_dir" || {
log "ERROR" "无法进入证书目录 $cert_dir"
return 1
}
# 生成自签名证书
if ! openssl req -x509 \
-newkey rsa:2048 \
-nodes \
-keyout server.key \
-out server.crt \
-days 36500 \
-config san.cnf \
-extensions v3_req; then
log "ERROR" "证书生成失败"
return 1
fi
log "INFO" "证书生成成功"
else
log "INFO" "证书文件已存在,跳过生成"
fi
# 检查容器是否存在 # 检查容器是否存在
if docker ps -a --format '{{.Names}}' | grep -qw "$nginx_container_name"; then if docker ps -a --format '{{.Names}}' | grep -qw "$nginx_container_name"; then
log "WARN" "容器 $nginx_container_name 已存在,自动退出部署操作!!!" log "WARN" "容器 $nginx_container_name 已存在,自动退出部署操作!!!"
......
#!/bin/bash
#------------------------------工具类模块---------------------------------------------------
LOG_FILE="/var/log/new_auto_script.log"
mkdir -p "$(dirname "$LOG_FILE")" 2>/dev/null
function log() {
local timestamp=$(date "+%Y-%m-%d %H:%M:%S")
local INFO_COLOR="\033[32m"
local WARN_COLOR="\033[33m"
local ERROR_COLOR="\033[31m"
local DEBUG_COLOR="\033[36m"
local RESET_COLOR="\033[0m"
if [ $# -lt 2 ]; then
echo "Usage: log <level> <message>"
return 1
fi
local level=$1
local message=$2
case $level in
"INFO") color=$INFO_COLOR ;;
"WARN") color=$WARN_COLOR ;;
"ERROR") color=$ERROR_COLOR ;;
"DEBUG") color=$DEBUG_COLOR ;;
*) echo "Invalid log level: $level"; return 1 ;;
esac
echo -e "${color}[$timestamp] [$level] $message${RESET_COLOR}"
echo "[$timestamp] [$level] $message" >> "$LOG_FILE"
}
# ===========================================
# 脚本: replace_ip_interactive.sh
# 功能: 扫描配置文件,查找并替换IP(完全自动化版本)
# ===========================================
# --- 配置区域 ---
TARGET_DIR="/data"
BACKUP_DIR="/data/temp"
OLD_IP_INPUT="192.168.9.84"
# 检查命令行参数
if [ $# -ge 1 ]; then
NEW_IP_INPUT="$1"
log "INFO" "使用传入的IP地址: $NEW_IP_INPUT"
else
# 自动获取本机IP
NEW_IP_INPUT=$(hostname -I | awk '{print $1}' | cut -d' ' -f1)
if [[ -z "$NEW_IP_INPUT" ]]; then
NEW_IP_INPUT=$(ip addr show | grep -E 'inet\s+(192\.168|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.|10\.)' | awk '{print $2}' | cut -d/ -f1 | head -n1)
if [[ -z "$NEW_IP_INPUT" ]]; then
log "ERROR" "无法自动获取IP地址,请手动指定"
exit 1
fi
fi
log "INFO" "自动获取IP地址: $NEW_IP_INPUT"
fi
# 验证IP地址格式
if ! [[ $NEW_IP_INPUT =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
log "ERROR" "无效的IP地址格式: $NEW_IP_INPUT"
exit 1
fi
# 支持的配置文件扩展名
ALLOWED_EXTENSIONS=(
"\.js$"
"\.yml$"
"\.yaml$"
"\.json$"
"\.properties$"
"\.conf$"
"\.config$"
"\.ini$"
"\.env$"
"\.py$"
"\.xml$"
"\.txt$"
"\.sh$"
"\.cnf$"
)
EXT_REGEX=$(IFS='|'; echo "${ALLOWED_EXTENSIONS[*]}")
# 检查目标目录
if [[ ! -d "$TARGET_DIR" ]]; then
log "ERROR" "目录 '$TARGET_DIR' 不存在!"
exit 1
fi
# 确保备份目录存在
if [[ ! -d "$BACKUP_DIR" ]]; then
log "INFO" "备份目录 $BACKUP_DIR 不存在,正在创建..."
mkdir -p "$BACKUP_DIR" || {
log "ERROR" "无法创建备份目录 $BACKUP_DIR,请检查权限"
exit 1
}
log "INFO" "已创建 $BACKUP_DIR"
fi
# 转义旧IP用于sed
OLD_IP_ESCAPED=$(echo "$OLD_IP_INPUT" | sed 's/\./\\./g')
log "INFO" "开始自动化IP替换流程"
log "INFO" "扫描目录: $TARGET_DIR"
log "INFO" "查找旧IP: $OLD_IP_INPUT"
log "INFO" "替换为新IP: $NEW_IP_INPUT"
# 临时文件记录匹配的文件路径
MATCHED_FILES="/tmp/matched_files.$$"
> "$MATCHED_FILES"
# 使用 find 查找文件并处理
log "INFO" "正在扫描配置文件..."
find "$TARGET_DIR" -type f -regextype posix-extended -regex ".*($EXT_REGEX)" -print0 2>/dev/null | \
while IFS= read -r -d '' file; do
[[ -L "$file" ]] && continue
if ! file -b "$file" 2>/dev/null | grep -qi "text"; then
continue
fi
if grep -Fq "$OLD_IP_INPUT" "$file" 2>/dev/null; then
log "INFO" "发现匹配文件: $file"
echo "$file" >> "$MATCHED_FILES"
fi
done
# 检查是否有匹配的文件
if [[ ! -s "$MATCHED_FILES" ]]; then
log "INFO" "在指定类型的配置文件中未找到 '$OLD_IP_INPUT'。"
rm -f "$MATCHED_FILES"
exit 0
fi
MATCH_COUNT=$(wc -l < "$MATCHED_FILES")
log "INFO" "扫描完成,共找到 $MATCH_COUNT 个配置文件包含 '$OLD_IP_INPUT'。"
# 执行替换操作
log "INFO" "开始执行替换操作..."
SUCCESS_COUNT=0
FAIL_COUNT=0
while IFS= read -r file; do
if [[ -f "$file" ]]; then
# 创建备份文件名(替换斜杠为下划线)
BACKUP_NAME=$(echo "$file" | sed 's|^/||; s|/|_|g')".bak"
BACKUP_PATH="$BACKUP_DIR/$BACKUP_NAME"
# 创建备份
if cp "$file" "$BACKUP_PATH" 2>/dev/null; then
# 执行替换
if sed -i "s/$OLD_IP_ESCAPED/$NEW_IP_INPUT/g" "$file" 2>/dev/null; then
log "INFO" "✅ 已替换: $file"
((SUCCESS_COUNT++))
else
log "ERROR" "❌ 替换失败: $file"
((FAIL_COUNT++))
fi
else
log "ERROR" "❌ 备份失败: $file$BACKUP_PATH"
((FAIL_COUNT++))
fi
fi
done < "$MATCHED_FILES"
# 清理临时文件
rm -f "$MATCHED_FILES"
# 输出结果统计
log "INFO" "=================================================="
log "INFO" "IP替换完成: 成功 $SUCCESS_COUNT 个文件,失败 $FAIL_COUNT 个文件"
log "INFO" "备份文件保存在: $BACKUP_DIR"
log "INFO" "=================================================="
if [ $FAIL_COUNT -eq 0 ]; then
exit 0
else
exit 1
fi
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论