个人文档
This commit is contained in:
parent
fee432e610
commit
b8eb75287d
10
.idea/material_theme_project_new.xml
generated
Normal file
10
.idea/material_theme_project_new.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MaterialThemeProjectNewConfig">
|
||||
<option name="metadata">
|
||||
<MTProjectMetadataState>
|
||||
<option name="userId" value="3c7a1e0f:19e913df385:-7fff" />
|
||||
</MTProjectMetadataState>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
204
sh/MD5.sh
Normal file
204
sh/MD5.sh
Normal file
@ -0,0 +1,204 @@
|
||||
#!/bin/bash
|
||||
# ================================================
|
||||
# KR数据同步后 MD5 校验与重试脚本
|
||||
# 功能:对比源目录与远程目标目录的 MD5(基于相对路径),不一致则重新同步
|
||||
# 用法:./kr_data_sync_verify.sh [YYYYMMDD]
|
||||
# ================================================
|
||||
|
||||
# ---------- 配置参数 ----------
|
||||
#SRC_BASE="/home/sysop/kr_md_save_pkt_loss_v5/data/stockdata" #南方
|
||||
SRC_BASE="/home/sysop/kr_md_save_centos7_9_20260317/data/stockdata" #金桥
|
||||
DEST_HOST="swdata@119.167.194.234"
|
||||
DEST_PORT="60000"
|
||||
#DEST_BASE="/mnt/data1/data_new_nf/data/stockdata" #南方
|
||||
DEST_BASE="/mnt/data1/data_new/data/stockdata" #金桥
|
||||
DEST_MARK_BASE="/mnt/data1/md5"
|
||||
SSH_OPTS="-o ConnectTimeout=30 -o BatchMode=yes -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ServerAliveCountMax=3"
|
||||
LOG_DIR="/var/log/kr_data_sync"
|
||||
LOG_FILE="$LOG_DIR/verify_$(date +%Y%m%d).log"
|
||||
MAX_RETRIES=10
|
||||
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
# ---------- 日志函数 ----------
|
||||
log_info() {
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
log_error() {
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') [ERROR] $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "用法: $0 [YYYYMMDD]"
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_dependencies() {
|
||||
command -v rsync &>/dev/null || { log_error "请安装 rsync"; exit 1; }
|
||||
command -v md5sum &>/dev/null || { log_error "请安装 md5sum"; exit 1; }
|
||||
}
|
||||
|
||||
check_ssh() {
|
||||
log_info "检查 SSH 连接..."
|
||||
ssh -p "$DEST_PORT" $SSH_OPTS "$DEST_HOST" "echo ok" &>/dev/null || {
|
||||
log_error "SSH 连接失败"
|
||||
exit 1
|
||||
}
|
||||
log_info "SSH 连接正常"
|
||||
}
|
||||
|
||||
check_remote_md5sum() {
|
||||
ssh -p "$DEST_PORT" $SSH_OPTS "$DEST_HOST" "command -v md5sum" &>/dev/null || {
|
||||
log_error "远程主机缺少 md5sum"
|
||||
exit 1
|
||||
}
|
||||
log_info "远程 md5sum 可用"
|
||||
}
|
||||
|
||||
ensure_remote_mark_dir() {
|
||||
ssh -p "$DEST_PORT" $SSH_OPTS "$DEST_HOST" "mkdir -p '$DEST_MARK_BASE'" &>/dev/null || {
|
||||
log_error "无法创建远程标记目录 $DEST_MARK_BASE"
|
||||
exit 1
|
||||
}
|
||||
log_info "远程标记目录已确认: $DEST_MARK_BASE"
|
||||
}
|
||||
|
||||
# ========== 生成相对路径的 MD5 列表 ==========
|
||||
generate_local_md5() {
|
||||
local dir="$1"
|
||||
local tmpfile=$(mktemp)
|
||||
# 进入源目录,使用相对路径(以 ./ 开头)
|
||||
(cd "$dir" && find . -type f -print0 2>/dev/null | xargs -0 md5sum 2>/dev/null | sort -k2) > "$tmpfile"
|
||||
echo "$tmpfile"
|
||||
}
|
||||
|
||||
generate_remote_md5() {
|
||||
local dir="$1"
|
||||
local tmpfile=$(mktemp)
|
||||
# 远程进入目标目录,同样使用相对路径
|
||||
ssh -p "$DEST_PORT" $SSH_OPTS "$DEST_HOST" "cd '$dir' && find . -type f -print0 2>/dev/null | xargs -0 md5sum 2>/dev/null | sort -k2" > "$tmpfile" 2>/dev/null
|
||||
echo "$tmpfile"
|
||||
}
|
||||
# ====================================================
|
||||
|
||||
compare_md5() {
|
||||
local local_list="$1"
|
||||
local remote_list="$2"
|
||||
local diff_file=$(mktemp)
|
||||
|
||||
if [ ! -s "$local_list" ]; then
|
||||
log_error "本地文件列表为空"
|
||||
rm -f "$diff_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if diff "$local_list" "$remote_list" > "$diff_file" 2>&1; then
|
||||
log_info "MD5 校验一致"
|
||||
rm -f "$diff_file"
|
||||
return 0
|
||||
else
|
||||
log_error "MD5 校验不一致,差异如下:"
|
||||
cat "$diff_file" | tee -a "$LOG_FILE"
|
||||
rm -f "$diff_file"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
do_sync() {
|
||||
local src="$1"
|
||||
local dest="$2"
|
||||
log_info "开始同步: $src -> $dest"
|
||||
rsync -avz --progress --delete \
|
||||
-e "ssh -p $DEST_PORT $SSH_OPTS" \
|
||||
"$src/" \
|
||||
"$DEST_HOST:$dest/" 2>&1 | tee -a "$LOG_FILE"
|
||||
local sync_result=${PIPESTATUS[0]}
|
||||
if [ $sync_result -eq 0 ]; then
|
||||
log_info "同步完成"
|
||||
return 0
|
||||
else
|
||||
log_error "同步失败,退出码: $sync_result"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
create_mark_file() {
|
||||
local date_str="$1"
|
||||
#local remote_mark_file="$DEST_MARK_BASE/${date_str}_nf" #南方
|
||||
local remote_mark_file="$DEST_MARK_BASE/${date_str}_jq" #金桥
|
||||
echo "Sync completed and verified at $(date -u '+%Y-%m-%d %H:%M:%S UTC')" | \
|
||||
ssh -p "$DEST_PORT" $SSH_OPTS "$DEST_HOST" "cat > '$remote_mark_file'"
|
||||
if [ $? -eq 0 ]; then
|
||||
log_info "已创建标记文件: $remote_mark_file"
|
||||
else
|
||||
log_error "创建标记文件失败"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local target_date="$1"
|
||||
[ -z "$target_date" ] && target_date=$(date +%Y%m%d)
|
||||
if ! [[ "$target_date" =~ ^[0-9]{8}$ ]]; then
|
||||
log_error "日期格式必须为 YYYYMMDD"
|
||||
usage
|
||||
fi
|
||||
|
||||
local src_dir="$SRC_BASE/$target_date"
|
||||
local dest_dir="$DEST_BASE/$target_date"
|
||||
local remote_mark_file="$DEST_MARK_BASE/$target_date"
|
||||
|
||||
log_info "========== 开始 MD5 校验与同步任务 =========="
|
||||
log_info "日期: $target_date"
|
||||
log_info "源目录: $src_dir"
|
||||
log_info "目标目录: $dest_dir"
|
||||
log_info "标记文件: $remote_mark_file"
|
||||
|
||||
[ ! -d "$src_dir" ] && { log_error "源目录不存在: $src_dir"; exit 1; }
|
||||
|
||||
check_dependencies
|
||||
check_ssh
|
||||
check_remote_md5sum
|
||||
ensure_remote_mark_dir
|
||||
|
||||
local retry_count=0
|
||||
local success=false
|
||||
|
||||
while [ $retry_count -lt $MAX_RETRIES ]; do
|
||||
retry_count=$((retry_count + 1))
|
||||
log_info "===== 第 $retry_count 次校验 ====="
|
||||
|
||||
local local_md5=$(generate_local_md5 "$src_dir")
|
||||
local remote_md5=$(generate_remote_md5 "$dest_dir")
|
||||
|
||||
if compare_md5 "$local_md5" "$remote_md5"; then
|
||||
success=true
|
||||
rm -f "$local_md5" "$remote_md5"
|
||||
break
|
||||
else
|
||||
rm -f "$local_md5" "$remote_md5"
|
||||
log_info "MD5 不一致,执行同步..."
|
||||
if ! do_sync "$src_dir" "$dest_dir"; then
|
||||
log_error "同步失败,终止重试"
|
||||
exit 1
|
||||
fi
|
||||
sleep 5
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$success" = true ]; then
|
||||
log_info "经过 $retry_count 次校验,MD5 已一致"
|
||||
create_mark_file "$target_date"
|
||||
log_info "任务完成,已生成标记文件"
|
||||
else
|
||||
log_error "达到最大重试次数 $MAX_RETRIES,仍然无法使 MD5 一致"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "========== 任务结束 =========="
|
||||
}
|
||||
|
||||
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
||||
usage
|
||||
fi
|
||||
main "$1"
|
||||
55
sh/catps.txt
Normal file
55
sh/catps.txt
Normal file
@ -0,0 +1,55 @@
|
||||
cat > /home/system/zabbix_agent/ps/check_heartbeat.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
# 获取当前小时和分钟
|
||||
current_hour=$(date +"%H"|sed 's/^0//')
|
||||
current_minute=$(date +"%M"|sed 's/^0//')
|
||||
|
||||
# 转换为24小时制的时间格式
|
||||
current_time=$((current_hour * 60 + current_minute))
|
||||
|
||||
# 设定时间段(09:15到14:57)的开始和结束时间(以分钟计)
|
||||
start_time=$((9*60+15)) # 09:15
|
||||
end_time=$((14*60+57)) # 14:57
|
||||
|
||||
#展示strategy_date_*.log的文件路径
|
||||
strategy_dir=$(find /home/system/app_* -name "strategy_`date '+%Y%m%d'`_*.log" -regextype posix-extended ! -regex '.*/test_log/.*')
|
||||
|
||||
#在9:00-14:57循环判断日志时间和系统时间相差是否超过30s
|
||||
if [[ $current_time -ge $start_time ]] && [[ $current_time -lt $end_time ]]; then
|
||||
if [[ -z "${strategy_dir}" ]]; then
|
||||
echo 0 #心跳正常
|
||||
else
|
||||
array_error=()
|
||||
for dir_path in ${strategy_dir}; do
|
||||
time_heart=$(# 取最后1000行,直接匹配最后一个时间 time 或 timestamp 字段并提取日期时间
|
||||
tail -n 1000 ${dir_path} | grep -E '"time"|"timestamp"' | tail -2 | head -1 | sed -E '
|
||||
# 格式1: "time": "2025-12-12 14:56:25:010" -> 2025-12-12 14:56:25
|
||||
s/.*"time"[[:space:]]*:[[:space:]]*"([0-9]{4}-[0-9]{2}-[0-9]{2}) ([0-9]{2}:[0-9]{2}:[0-9]{2}):[0-9]+".*/\1 \2/p
|
||||
|
||||
# 格式2: "timestamp": "12/12/2025, 14:56:26" -> 2025-12-12 14:56:26
|
||||
s/.*"timestamp"[[:space:]]*:[[:space:]]*"([0-9]{2})\/([0-9]{2})\/([0-9]{4}), ([0-9]{2}:[0-9]{2}:[0-9]{2})".*/\3-\1-\2 \4/p
|
||||
' -n)
|
||||
|
||||
ct=$(date +%s)
|
||||
lt=$(date -d "${time_heart}" +%s)
|
||||
minus=$((${ct} - ${lt}))
|
||||
if [[ -z "${time_heart}" ]]; then
|
||||
continue
|
||||
else
|
||||
if [[ ${minus} -ge 180 ]]; then
|
||||
array_error+=(${dir_path})
|
||||
fi
|
||||
fi
|
||||
done
|
||||
if [[ ${#array_error[@]} -gt 0 ]]; then
|
||||
echo ${array_error[@]} #列出数组的所有元素
|
||||
else
|
||||
echo 0 #心跳正常
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo 0 #心跳正常
|
||||
fi
|
||||
EOF
|
||||
|
||||
sh /home/system/zabbix_agent/ps/check_heartbeat.sh
|
||||
57
sh/check_heartbeat.txt
Normal file
57
sh/check_heartbeat.txt
Normal file
@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
# 获取当前小时和分钟
|
||||
current_hour=$(date +"%H"|sed 's/^0//')
|
||||
current_minute=$(date +"%M"|sed 's/^0//')
|
||||
|
||||
# 转换为24小时制的时间格式
|
||||
current_time=$((current_hour * 60 + current_minute))
|
||||
|
||||
# 设定时间段(09:15到14:57)的开始和结束时间(以分钟计)
|
||||
start_time=$((9*60+15)) # 09:15
|
||||
end_time=$((14*60+57)) # 14:57
|
||||
filter_time=$((9*60+35)) # 09:35
|
||||
|
||||
#展示strategy_date_*.log的文件路径
|
||||
strategy_dir=$(find /home/system/app_* -name "strategy_`date '+%Y%m%d'`_*.log" -regextype posix-extended ! -regex '.*/test_log/.*')
|
||||
|
||||
# 新增:九点三十五之后过滤 fundflow
|
||||
if [[ $current_time -ge $filter_time ]]; then
|
||||
strategy_dir=$(echo "$strategy_dir" | grep -v 'fundflow')
|
||||
fi
|
||||
|
||||
#在9:00-14:57循环判断日志时间和系统时间相差是否超过30s
|
||||
if [[ $current_time -ge $start_time ]] && [[ $current_time -lt $end_time ]]; then
|
||||
if [[ -z "${strategy_dir}" ]]; then
|
||||
echo 0 #心跳正常
|
||||
else
|
||||
array_error=()
|
||||
for dir_path in ${strategy_dir}; do
|
||||
time_heart=$(# 取最后1000行,直接匹配最后一个时间 time 或 timestamp 字段并提取日期时间
|
||||
tail -n 1000 ${dir_path} | grep -E '"time"|"timestamp"' | tail -2 | head -1 | sed -E '
|
||||
# 格式1: "time": "2025-12-12 14:56:25:010" -> 2025-12-12 14:56:25
|
||||
s/.*"time"[[:space:]]*:[[:space:]]*"([0-9]{4}-[0-9]{2}-[0-9]{2}) ([0-9]{2}:[0-9]{2}:[0-9]{2}):[0-9]+".*/\1 \2/p
|
||||
|
||||
# 格式2: "timestamp": "12/12/2025, 14:56:26" -> 2025-12-12 14:56:26
|
||||
s/.*"timestamp"[[:space:]]*:[[:space:]]*"([0-9]{2})\/([0-9]{2})\/([0-9]{4}), ([0-9]{2}:[0-9]{2}:[0-9]{2})".*/\3-\1-\2 \4/p
|
||||
' -n)
|
||||
|
||||
ct=$(date +%s)
|
||||
lt=$(date -d "${time_heart}" +%s)
|
||||
minus=$((${ct} - ${lt}))
|
||||
if [[ -z "${time_heart}" ]]; then
|
||||
continue
|
||||
else
|
||||
if [[ ${minus} -ge 180 ]]; then
|
||||
array_error+=(${dir_path})
|
||||
fi
|
||||
fi
|
||||
done
|
||||
if [[ ${#array_error[@]} -gt 0 ]]; then
|
||||
echo ${array_error[@]} #列出数组的所有元素
|
||||
else
|
||||
echo 0 #心跳正常
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo 0 #心跳正常
|
||||
fi
|
||||
29
sh/check_xtpsvr.txt
Normal file
29
sh/check_xtpsvr.txt
Normal file
@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 配置企业微信机器人Webhook URL
|
||||
WEBHOOK_URL="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=your_webhook_key"
|
||||
|
||||
# 检查xtpsvr进程是否运行
|
||||
if ps -ef | grep -q '[x]tpsvr'; then
|
||||
exit 0 # 进程正常运行,静默退出
|
||||
else
|
||||
# 构造告警消息
|
||||
ALERT_MSG=" xtpsvr进程已停止运行!\n> 服务器: $(hostname)\n> 时间: $(date "+%Y-%m-%d %H:%M:%S")"
|
||||
|
||||
# JSON消息体
|
||||
JSON_MSG=$(cat <<EOF
|
||||
{
|
||||
"msgtype": "text",
|
||||
"text": {
|
||||
"content": "$ALERT_MSG",
|
||||
"mentioned_mobile_list": ["@all"]
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
# 发送企业微信告警(后台执行避免阻塞)
|
||||
nohup curl -s -X POST -H "Content-Type: application/json" -d "$JSON_MSG" "$WEBHOOK_URL" >/dev/null 2>&1 &
|
||||
|
||||
exit 1
|
||||
fi
|
||||
266
sh/init.sh
Normal file
266
sh/init.sh
Normal file
@ -0,0 +1,266 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 设置脚本在遇到错误时立即退出
|
||||
set -e
|
||||
|
||||
[ "$(id -u)" -ne 0 ] && { echo "必须以 root 用户身份运行此脚本。"; exit 1; }
|
||||
|
||||
# 检查 tuned-adm 命令是否存在,如果存在则执行
|
||||
if command -v tuned-adm &> /dev/null; then
|
||||
tuned-adm profile network-latency
|
||||
else
|
||||
echo "Warning: The 'tuned-adm' command is not available."
|
||||
fi
|
||||
|
||||
# EPB not enabled on this platform
|
||||
#x86_energy_perf_policy performance
|
||||
|
||||
###################### core ###################
|
||||
echo "# 开始检查内核参数..."
|
||||
# limits.conf
|
||||
declare -r LIMITS_CONF_APPEND='
|
||||
* soft core unlimited
|
||||
* hard core unlimited
|
||||
'
|
||||
if ! grep -qE '\* soft core unlimited|\* hard core unlimited' /etc/security/limits.conf; then
|
||||
echo "$LIMITS_CONF_APPEND" >> /etc/security/limits.conf
|
||||
else
|
||||
echo "The limits have already been set in /etc/security/limits.conf"
|
||||
fi
|
||||
|
||||
ulimit -c unlimited
|
||||
|
||||
|
||||
###################### rc.local ###################
|
||||
echo "# 开始检查rc.local..."
|
||||
# rc.local
|
||||
if [ ! -f "/etc/rc.d/rc.local" ]; then
|
||||
echo "Error: /etc/rc.d/rc.local file does not exist. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
chmod +x /etc/rc.d/rc.local
|
||||
|
||||
ETHTOOL_COMMANDS=(
|
||||
"ethtool -G p1p1 rx 2048 tx 2048"
|
||||
"ethtool -G ens1f0 rx 2048 tx 2048"
|
||||
"ethtool -C ens1f0 rx-usecs 0 rx-usecs-irq 0 adaptive-rx off"
|
||||
"ethtool -C p1p2 rx-usecs 0 rx-usecs-irq 0 adaptive-rx off"
|
||||
)
|
||||
# 检查 rc.local 文件中是否已包含相应行,如果没有则追加
|
||||
for cmd in "${ETHTOOL_COMMANDS[@]}"; do
|
||||
if ! grep -Fxq "$cmd" /etc/rc.d/rc.local; then
|
||||
echo "$cmd" >> /etc/rc.d/rc.local
|
||||
fi
|
||||
done
|
||||
|
||||
###################### GRUB ###################
|
||||
## TODO: 这个需要手工操作
|
||||
echo "# 开始检查GRUB..."
|
||||
# 设置GRUB 引导参数
|
||||
|
||||
# 读取当前GRUB_CMDLINE_LINUX值
|
||||
CURRENT_CMDLINE=$(grep GRUB_CMDLINE_LINUX /etc/default/grub | cut -d '"' -f2)
|
||||
|
||||
# 获取系统CPU核心数
|
||||
CPU_COUNT=$(nproc)
|
||||
|
||||
# 要检查和添加的配置项
|
||||
ADDITIONAL_OPTS="ipv6.disable=1 selinux=0 isolcpus=1-$((CPU_COUNT-1)) nohz_full=1-$((CPU_COUNT-1)) transparent_hugepage=never default_hugepagesz=1G hugepagesz=1G hugepages=32 intel_idle.max_cstate=0 processor.max_cstate=0 idle=poll intel_iommu=off nosoftlockup mce=ignore_ce nmi_watchdog=0 pcie_aspm=off nohz=off audit=0"
|
||||
|
||||
# 需要检查的配置项列表(排除isolcpus和nohz_full)
|
||||
CHECK_OPTS="ipv6.disable=1 selinux=0 transparent_hugepage=never default_hugepagesz=1G hugepagesz=1G hugepages=32 intel_idle.max_cstate=0 processor.max_cstate=0 idle=poll intel_iommu=off nosoftlockup mce=ignore_ce nmi_watchdog=0 pcie_aspm=off nohz=off audit=0"
|
||||
|
||||
# 检查并添加配置项
|
||||
for opt in $CHECK_OPTS; do
|
||||
if [[ ! $CURRENT_CMDLINE =~ $opt ]]; then
|
||||
CURRENT_CMDLINE+=" $opt"
|
||||
fi
|
||||
done
|
||||
|
||||
# 特别处理 isolcpus 和 nohz_full
|
||||
if [[ ! $CURRENT_CMDLINE =~ isolcpus= ]]; then
|
||||
CURRENT_CMDLINE+=" isolcpus=1-$((CPU_COUNT-1))"
|
||||
fi
|
||||
if [[ ! $CURRENT_CMDLINE =~ nohz_full= ]]; then
|
||||
CURRENT_CMDLINE+=" nohz_full=1-$((CPU_COUNT-1))"
|
||||
fi
|
||||
|
||||
# 更新GRUB_CMDLINE_LINUX
|
||||
#awk -v cmdline="${CURRENT_CMDLINE}" 'BEGIN{FS="=";OFS="="} $1 == "GRUB_CMDLINE_LINUX" {$2 = "\""cmdline"\""} 1' /etc/default/grub | tee /etc/default/grub > /dev/null
|
||||
|
||||
# 重启grub配置
|
||||
#update-grub
|
||||
|
||||
####################### 大页检查 ########################
|
||||
echo "# 开始检查大页..."
|
||||
|
||||
# 检查 HugePages 是否启用
|
||||
HUGE_PAGES_TOTAL=$(grep -i HugePages_Total /proc/meminfo | awk '{print $2}')
|
||||
if [ "$HUGE_PAGES_TOTAL" -eq 0 ]; then
|
||||
echo "Error: HugePages are not enabled or configured properly."
|
||||
else
|
||||
echo "HugePages are enabled with a total of $HUGE_PAGES_TOTAL pages."
|
||||
fi
|
||||
|
||||
# 检查 hugetlbfs 是否挂载
|
||||
if ! mount | grep -q hugetlbfs; then
|
||||
echo "Error: hugetlbfs is not mounted."
|
||||
else
|
||||
echo "hugetlbfs is correctly mounted."
|
||||
fi
|
||||
|
||||
# 如果 HugePages 没有启用或 hugetlbfs 没有挂载,进行配置
|
||||
if [ "$HUGE_PAGES_TOTAL" -eq 0 ] || ! mount | grep -q hugetlbfs; then
|
||||
echo "Configuring HugePages..."
|
||||
|
||||
# 更新内核参数
|
||||
grubby --update-kernel=ALL --args="default_hugepagesz=1G hugepagesz=1G hugepages=4"
|
||||
|
||||
# 检查配置是否成功
|
||||
if grubby --info=ALL | grep -q "default_hugepagesz=1G"; then
|
||||
echo "HugePages configuration updated successfully."
|
||||
|
||||
# 尝试挂载 hugetlbfs
|
||||
mkdir -p /dev/hugepages
|
||||
mount -t hugetlbfs nodev /dev/hugepages
|
||||
|
||||
if mount | grep -q hugetlbfs; then
|
||||
echo "hugetlbfs mounted successfully."
|
||||
else
|
||||
echo "Error: Failed to mount hugetlbfs."
|
||||
fi
|
||||
else
|
||||
echo "Error: Failed to update HugePages configuration."
|
||||
fi
|
||||
fi
|
||||
|
||||
####################### 检查虚拟网卡 ########################
|
||||
echo "# 开始检查并删除虚拟网卡..."
|
||||
|
||||
set +e
|
||||
systemctl stop libvirtd.service 2>/dev/null
|
||||
systemctl disable libvirtd.service 2>/dev/null
|
||||
set -e
|
||||
|
||||
# 检查 virbr0 网桥是否存在
|
||||
if ifconfig virbr0 &> /dev/null; then
|
||||
echo "virbr0 exists."
|
||||
# 如果存在,可以在此处添加删除 virbr0 的命令
|
||||
# 因为 libvirt 会在需要时自动重建它
|
||||
# 可以考虑使用 libvirt 的工具来管理网络,例如 'virsh net-destroy default'
|
||||
else
|
||||
echo "virbr0 does not exist."
|
||||
fi
|
||||
|
||||
####################### selinux ########################
|
||||
echo "# 开始关闭SELINUX..."
|
||||
|
||||
# 检查 SELinux 当前的状态
|
||||
current_selinux_status=$(grep ^SELINUX= /etc/selinux/config | awk -F "=" '{print $2}' | tr -d ' ')
|
||||
|
||||
# 如果 SELinux 不是 disabled 状态,则进行修改
|
||||
if [ "$current_selinux_status" != "disabled" ]; then
|
||||
# 备份原来的配置文件
|
||||
cp /etc/selinux/config /etc/selinux/config.bak
|
||||
|
||||
# 使用 sed 命令更新 SELINUX 参数为 disabled
|
||||
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
|
||||
|
||||
echo "SELinux has been set to disabled."
|
||||
else
|
||||
echo "SELinux is already disabled."
|
||||
fi
|
||||
|
||||
####################### 网络低延迟 ########################
|
||||
echo "# 开始设置网络低延迟..."
|
||||
|
||||
cd /proc/sys/net/ipv4
|
||||
sysctl -w net.core.rmem_default=134217728
|
||||
sysctl -w net.core.rmem_max=134217728
|
||||
sysctl -w net.core.wmem_default=134217728
|
||||
sysctl -w net.core.wmem_max=134217728
|
||||
sysctl -w net.ipv4.udp_mem="134217728 134217728 268435456"
|
||||
sysctl -w net.ipv4.udp_rmem_min=134217728
|
||||
sysctl -w net.ipv4.udp_wmem_min=134217728
|
||||
|
||||
sh -c 'echo "net.ipv4.tcp_low_latency = 0" >> /etc/sysctl.conf'
|
||||
sh -c 'echo "vm.nr_hugepages=4096" >> /etc/sysctl.conf'
|
||||
sh -c 'echo "net.core.rmem_default=134217728" >> /etc/sysctl.conf'
|
||||
sh -c 'echo "net.core.rmem_max=134217728" >> /etc/sysctl.conf'
|
||||
sh -c 'echo "net.core.wmem_default=134217728" >> /etc/sysctl.conf'
|
||||
sh -c 'echo "net.core.wmem_max=134217728" >> /etc/sysctl.conf'
|
||||
sh -c 'echo "net.ipv4.udp_mem=134217728 134217728 268435456" >> /etc/sysctl.conf'
|
||||
sh -c 'echo "net.ipv4.udp_rmem_min=134217728" >> /etc/sysctl.conf'
|
||||
sh -c 'echo "net.ipv4.udp_wmem_min=134217728" >> /etc/sysctl.conf'
|
||||
sh -c 'echo "net.core.netdev_max_backlog=4000" >> /etc/sysctl.conf'
|
||||
|
||||
sysctl -p /etc/sysctl.conf
|
||||
|
||||
####################### 关闭服务 ########################
|
||||
echo "# 开始关闭各种无用的服务..."
|
||||
|
||||
set +e
|
||||
|
||||
systemctl set-default multi-user.target
|
||||
systemctl disable firewalld.service
|
||||
systemctl stop firewalld.service
|
||||
|
||||
systemctl stop libvirtd.service
|
||||
systemctl disable libvirtd.service
|
||||
systemctl stop iptables.service
|
||||
systemctl stop firewalld.service
|
||||
systemctl stop irqbalance.service
|
||||
systemctl stop abrt-ccpp.service
|
||||
systemctl stop abrt-oops.service
|
||||
systemctl stop abrt-xorg.service
|
||||
systemctl stop abrtd.service
|
||||
systemctl stop alsa-state.service
|
||||
systemctl stop cups.service
|
||||
systemctl stop ModemManager.service
|
||||
systemctl stop postfix.service
|
||||
systemctl disable firewalld.service
|
||||
systemctl disable iptables.service
|
||||
systemctl disable irqbalance.service
|
||||
systemctl disable alsa-state.service
|
||||
systemctl disable cups.service
|
||||
systemctl disable ModemManager.service
|
||||
systemctl disable postfix.service
|
||||
systemctl stop cpuspower
|
||||
systemctl stop firewalld
|
||||
|
||||
#chkconfig NetworkManager off
|
||||
#chkconfig --del NetworkManager
|
||||
|
||||
set -e
|
||||
|
||||
|
||||
# 检查 tuned-adm 命令是否存在,如果存在则执行
|
||||
if command -v tuned-adm &> /dev/null; then
|
||||
tuned-adm profile network-latency
|
||||
else
|
||||
echo "Warning: The 'tuned-adm' command is not available."
|
||||
fi
|
||||
|
||||
####################### SSH配置 ########################
|
||||
echo "# 开始配置SSH服务..."
|
||||
ssh_options="ClientAliveInterval 30
|
||||
ClientAliveCountMax 10"
|
||||
|
||||
# 检查这些行是否已存在于 sshd_config 文件中
|
||||
if ! grep -qxF "[[:space:]]*ClientAliveInterval 30" /etc/ssh/sshd_config ||
|
||||
! grep -qxF "[[:space:]]*ClientAliveCountMax 10" /etc/ssh/sshd_config; then
|
||||
# 如果不存在,则添加到文件的末尾
|
||||
echo -e "$ssh_options" >> /etc/ssh/sshd_config
|
||||
echo "Options added to /etc/ssh/sshd_config"
|
||||
else
|
||||
echo "Options already present in /etc/ssh/sshd_config"
|
||||
fi
|
||||
|
||||
# 重启 SSH 服务
|
||||
systemctl restart sshd
|
||||
|
||||
####################### SSH配置 ########################
|
||||
echo "# 开始添加用户boyi_trader..."
|
||||
useradd boyi_trader
|
||||
|
||||
echo "DONE! PLS RESTART!"
|
||||
37
sh/log_del.bat
Normal file
37
sh/log_del.bat
Normal file
@ -0,0 +1,37 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
rem 设置保留天数
|
||||
set days_to_keep=3
|
||||
|
||||
rem 计算截止日期(当前日期减去保留天数)
|
||||
for /f "tokens=1-3 delims=/- " %%a in ('date /t') do (
|
||||
set current_day=%%a
|
||||
set current_month=%%b
|
||||
set current_year=%%c
|
||||
)
|
||||
|
||||
rem 使用PowerShell计算截止日期(更准确的方法)
|
||||
for /f %%d in ('powershell -command "(Get-Date).AddDays(-%days_to_keep%).ToString('yyyy-MM-dd')"') do (
|
||||
set cutoff_date=%%d
|
||||
)
|
||||
|
||||
echo 正在删除 %cutoff_date% 之前的日志文件...
|
||||
echo.
|
||||
|
||||
for /D %%A in ("D:\*") do (
|
||||
if exist "%%A\userdata\log\*.log" (
|
||||
echo 正在检查目录: %%A\userdata\log
|
||||
|
||||
rem 使用forfiles命令删除3天前的文件
|
||||
forfiles /p "%%A\userdata\log" /m "*.log" /d -%days_to_keep% /c "cmd /c echo 正在删除 @path && del /q @path"
|
||||
|
||||
rem 显示剩余文件
|
||||
echo 剩余文件:
|
||||
dir "%%A\userdata\log\*.log" /b 2>nul || echo 目录中没有日志文件
|
||||
echo.
|
||||
)
|
||||
)
|
||||
|
||||
echo 清理完成!
|
||||
pause
|
||||
6
sh/logseq_del.bat
Normal file
6
sh/logseq_del.bat
Normal file
@ -0,0 +1,6 @@
|
||||
@echo off
|
||||
set SrcDir=C:\test
|
||||
set DaysAgo=0 %日期自定义,此处代表0天前%
|
||||
forfiles /p %SrcDir% /s /m udpseq* /c "cmd /c del /f /q /a @path"
|
||||
forfiles /p %SrcDir% /s /m INFO_* /c "cmd /c del /f /q /a @path"
|
||||
forfiles /p %SrcDir% /s /m quote.log.* /c "cmd /c del /f /q /a @path"
|
||||
370
sh/reboot_route_nc.txt
Normal file
370
sh/reboot_route_nc.txt
Normal file
@ -0,0 +1,370 @@
|
||||
#!/bin/bash
|
||||
#定义颜色变量
|
||||
RED='\E[1;31m' # 红
|
||||
GREEN='\E[1;32m' # 绿
|
||||
YELOW='\E[1;33m' # 黄
|
||||
BLUE='\E[1;34m' # 蓝
|
||||
PINK='\E[1;35m' # 粉红
|
||||
SHAN='\E[33;5m' # 黄色闪烁警示
|
||||
RES='\E[0m' # 清除颜色
|
||||
#定义颜色动作
|
||||
SETCOLOR_SUCCESS="echo -en \\E[1;32m"
|
||||
SETCOLOR_FAILURE="echo -en \\E[1;31m"
|
||||
SETCOLOR_WARNING="echo -en \\E[1;33m"
|
||||
SETCOLOR_NORMAL="echo -en \\E[0;39m"
|
||||
|
||||
#定义变量
|
||||
date=` date +'%Y%m%d_%H%M%S' `
|
||||
date_init=` date +'%Y%m%d %H:%M:%S' `
|
||||
scripts_path='/root/scripts'
|
||||
original='original.conf'
|
||||
trans_file='trans_server.txt'
|
||||
aliyun_file='visit_aliyun_server.txt'
|
||||
passwd_file='password.txt'
|
||||
nc_file='nc_ipport.txt'
|
||||
aliyun_nc_file='aliyun_nc_ipport.txt'
|
||||
nc_yes_no='nc_yes_no.log'
|
||||
nc_rpm='nmap-ncat-6.40-19.el7.x86_64.rpm'
|
||||
ssh_port=22
|
||||
|
||||
#准备开始
|
||||
echo -e "\n\n***********************************************"
|
||||
echo -e "* ${YELOW} 服务器清除缓存开始! ${RES} *"
|
||||
echo -e "* ${YELOW} ${date_init} ${RES} *"
|
||||
echo -e "***********************************************\n\n"
|
||||
|
||||
#判断系统本身是否已安装nc,sshpass
|
||||
which nc > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${RED} 请先安装nc ${RES}"
|
||||
exit
|
||||
fi
|
||||
|
||||
which sshpass > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${RED} 请先安装sshpass ${RES}"
|
||||
exit
|
||||
fi
|
||||
|
||||
#判断目录是否存在
|
||||
if [ ! -d ${scripts_path}/conf ] || [ ! -d ${scripts_path}/files ] || [ ! -d ${scripts_path}/build ] || [ ! -d ${scripts_path}/rpm ] || [ ! -d ${scripts_path}/backup ] ; then
|
||||
mkdir -p ${scripts_path}/conf ${scripts_path}/files ${scripts_path}/build ${scripts_path}/rpm ${scripts_path}/backup
|
||||
fi
|
||||
|
||||
#判断配置文件是否存在
|
||||
if [ ! -f ${scripts_path}/conf/${original} ] ; then
|
||||
echo -e "${RED} 配置文件${scripts_path}/conf/${original}不存在,请先添加配置文件。 ${RES}"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ! -f ${scripts_path}/rpm/${nc_rpm} ] ; then
|
||||
ehco -e "${RED} nc包${scripts_path}/rpm/${nc_rpm}不存在,请先上传安装包。 ${RES} "
|
||||
exit
|
||||
fi
|
||||
|
||||
#判断本机IP在original.conf配置文件里面是否存在,如果存在就删除该行
|
||||
ip a | grep "inet " | awk '{print $2}' | awk -F'/' '{print $1}' > ${scripts_path}/build/local_ip.txt
|
||||
for local_ip in $(cat ${scripts_path}/build/local_ip.txt) ; do
|
||||
sed -i "/${local_ip}/d" ${scripts_path}/conf/${original}
|
||||
done
|
||||
rm -rf ${scripts_path}/build/local_ip.txt
|
||||
|
||||
#扫描配置文件内容到对应的文件
|
||||
grep ${trans_file%.txt} ${scripts_path}/conf/${original} | grep -v ${trans_file} | grep -v ^# | awk -F, '{print $1}' > ${scripts_path}/build/${trans_file}
|
||||
grep ${aliyun_file%.txt} ${scripts_path}/conf/${original} | grep -v ${aliyun_file} | grep -v ^# | awk -F, '{print $1}' > ${scripts_path}/build/${aliyun_file}
|
||||
grep ${passwd_file%.txt} ${scripts_path}/conf/${original} | grep -v ${passwd_file} | grep -v ^# | awk -F, '{print $1}' > ${scripts_path}/build/${passwd_file}
|
||||
grep ${nc_file%.txt} ${scripts_path}/conf/${original} | grep -v ${nc_file} | grep -v ${aliyun_nc_file%.txt} | grep -v ^# | awk -F, '{print $1}' > ${scripts_path}/build/${nc_file}
|
||||
grep ${aliyun_nc_file%.txt} ${scripts_path}/conf/${original} | grep -v ${aliyun_nc_file} | grep -v ^# | awk -F, '{print $1}' > ${scripts_path}/build/${aliyun_nc_file}
|
||||
|
||||
#判断文件是否为空
|
||||
echo > ${scripts_path}/files/${nc_yes_no}
|
||||
if [ ! -s ${scripts_path}/build/${trans_file} ] ; then
|
||||
echo -e "${RED} 交易服务器IP为空 ${RES}"
|
||||
echo "交易服务器IP为空" >> ${scripts_path}/files/${nc_yes_no}
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ! -s ${scripts_path}/build/${passwd_file} ] ; then
|
||||
echo -e "${RED} 服务器登录密码为空 ${RES}"
|
||||
echo "服务器登录密码为空" >> ${scripts_path}/files/${nc_yes_no}
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ! -s ${scripts_path}/build/${nc_file} ] ; then
|
||||
echo -e "${RED} 外访IP端口号为空 ${RES}"
|
||||
echo "访IP端口号为空" >> ${scripts_path}/files/${nc_yes_no}
|
||||
exit
|
||||
fi
|
||||
|
||||
#显示要测试的服务器IP
|
||||
echo -e "\n本次要测试的服务器IP为:" >> ${scripts_path}/files/${nc_yes_no}
|
||||
awk '{print $0}' ${scripts_path}/build/${trans_file} >> ${scripts_path}/files/${nc_yes_no}
|
||||
echo -e "\n===============================================\n" >> ${scripts_path}/files/${nc_yes_no}
|
||||
|
||||
#测试交易服务器是否能ssh远程连接
|
||||
array_ssherror=()
|
||||
for trans_ip in $(cat ${scripts_path}/build/${trans_file}) ; do
|
||||
nc -zw2 ${trans_ip} ${ssh_port}
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN} ${trans_ip}:${ssh_port} 端口访问成功 ${RES}"
|
||||
else
|
||||
echo -e "${RED} ${trans_ip}:${ssh_port} 端口访问失败 ${RES}"
|
||||
echo "${trans_ip}:${ssh_port} 端口访问失败" >> ${scripts_path}/files/${nc_yes_no}
|
||||
sed -i "/${trans_ip}/d" ${scripts_path}/build/${trans_file}
|
||||
array_ssherror+=("${trans_ip}:${ssh_port}--端口访问失败")
|
||||
fi
|
||||
done
|
||||
|
||||
#分割线
|
||||
echo -e "\n===============================================\n"
|
||||
|
||||
#测试交易服务器是否能正常登录
|
||||
array_login=()
|
||||
for trans_ip in $(cat ${scripts_path}/build/${trans_file}) ; do
|
||||
sshpass -f ${scripts_path}/build/${passwd_file} ssh -o StrictHostKeyChecking=no -o ConnectTimeout=2 root@${trans_ip} 'ls' > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN} ${trans_ip} 登录成功 ${RES}"
|
||||
else
|
||||
echo -e "${RED} ${trans_ip} 用户名或密码错误 ${RES}"
|
||||
echo "${trans_ip} 用户名或密码错误" >> ${scripts_path}/files/${nc_yes_no}
|
||||
sed -i "/${trans_ip}/d" ${scripts_path}/build/${trans_file}
|
||||
array_login+=("${trans_ip}--用户名或密码错误")
|
||||
fi
|
||||
done
|
||||
|
||||
#分割线
|
||||
echo -e "\n===============================================\n"
|
||||
|
||||
#检查远程服务器是否已经安装nc,如果没有安装,则拷贝过去进行安装,如果还是失败,就跳过
|
||||
array_nc=()
|
||||
for trans_ip in $(cat ${scripts_path}/build/${trans_file}) ; do
|
||||
sshpass -f ${scripts_path}/build/${passwd_file} ssh -o StrictHostKeyChecking=no root@${trans_ip} 'which nc' > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
sshpass -f ${scripts_path}/build/${passwd_file} scp -o StrictHostKeyChecking=no ${scripts_path}/rpm/${nc_rpm} root@${trans_ip}:/root
|
||||
sshpass -f ${scripts_path}/build/${passwd_file} ssh -o StrictHostKeyChecking=no root@${trans_ip} 'rpm -ivh nmap-ncat-6.40-19.el7.x86_64.rpm' > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${RED} ${trans_ip} nc安装失败! ${RES}"
|
||||
echo "${trans_ip} nc安装失败!" >> ${scripts_path}/files/${nc_yes_no}
|
||||
sed -i "/${trans_ip}/d" ${scripts_path}/build/${trans_file}
|
||||
array_nc+=("${trans_ip}--nc安装失败!")
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
#备份重启前的路由表并且重启
|
||||
for trans_ip in $(cat ${scripts_path}/build/${trans_file}) ; do
|
||||
sshpass -f ${scripts_path}/build/${passwd_file} ssh -o StrictHostKeyChecking=no root@${trans_ip} 'route -n > /root/route.txt'
|
||||
sshpass -f ${scripts_path}/build/${passwd_file} scp -o StrictHostKeyChecking=no root@${trans_ip}:/root/route.txt ${scripts_path}/files/${trans_ip}_old.txt
|
||||
sshpass -f ${scripts_path}/build/${passwd_file} ssh -o StrictHostKeyChecking=no root@${trans_ip} 'reboot' > /dev/null 2>&1
|
||||
echo -e "${YELOW} ${trans_ip} 正在重启... ${RES}"
|
||||
done
|
||||
|
||||
#分割线
|
||||
echo -e "\n===============================================\n"
|
||||
|
||||
#检测服务器是否重启成功
|
||||
array_reboot=()
|
||||
reboot_num=0
|
||||
for trans_ip in $(cat ${scripts_path}/build/${trans_file}) ; do
|
||||
|
||||
#设置倒计时时间(秒)
|
||||
end_time=$(( $(date +%s) + 600 )) # 600秒后结束倒计时的时间戳(当前时间戳+600秒)
|
||||
|
||||
#实时倒计时循环
|
||||
while [ "$(date +%s)" -lt "$end_time" ] ; do
|
||||
current_time=$(( $(date +%s) - $(date +%s -d "1970-01-01 UTC") )) #当前时间戳减去1970年1月1日UTC的时间戳,得到当前时间(秒)
|
||||
remaining=$(( end_time - current_time )) #计算剩余时间(秒)
|
||||
sshpass -f ${scripts_path}/build/${passwd_file} ssh -o StrictHostKeyChecking=no -o ConnectTimeout=2 -n root@${trans_ip} 'ls' > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
display_array=( "正在重启. " "正在重启.. " "正在重启..." )
|
||||
for dis_cat in "${display_array[@]}"; do
|
||||
current_time=$(( $(date +%s) - $(date +%s -d "1970-01-01 UTC") )) #当前时间戳减去1970年1月1日UTC的时间戳,得到当前时间(秒)
|
||||
remaining=$(( end_time - current_time )) #计算剩余时间(秒)
|
||||
printf " %s 倒计时:%03d秒\r" "服务器${trans_ip} ${dis_cat}" "${remaining}" #\r使光标回到行首,实现实时更新显示,不换行
|
||||
sleep 1
|
||||
echo -ne "\033[2K"
|
||||
done
|
||||
else
|
||||
echo -e "${GREEN} ${trans_ip} 重启成功 ${RES} "
|
||||
break
|
||||
fi
|
||||
done
|
||||
sleep 1
|
||||
if [ "$(date +%s)" -ge "$end_time" ] ; then
|
||||
echo -ne "\033[2K"
|
||||
echo -e "${RED} ${trans_ip} 重启失败 ${RES} "
|
||||
reboot_num=$(( reboot_num + 1 ))
|
||||
array_reboot+=("${trans_ip}--重启失败")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${reboot_num} -ne 0 ] ; then
|
||||
echo -e "\n${RED} 有${reboot_num}个服务器重启失败 ${RES}"
|
||||
echo "有${reboot_num}个服务器重启失败" >> ${scripts_path}/files/${nc_yes_no}
|
||||
fi
|
||||
|
||||
#echo -e "\n${GREEN} 服务器重启中,请等待10分钟... ${RES}\n"
|
||||
|
||||
##设置倒计时时间(秒)
|
||||
#end_time=$(( $(date +%s) + 600 )) # 600秒后结束倒计时的时间戳(当前时间戳+600秒)
|
||||
|
||||
##实时倒计时循环
|
||||
#while [ "$(date +%s)" -lt "$end_time" ]; do
|
||||
# current_time=$(( $(date +%s) - $(date +%s -d "1970-01-01 UTC") )) #当前时间戳减去1970年1月1日UTC的时间戳,得到当前时间(秒)
|
||||
# remaining=$(( end_time - current_time )) #计算剩余时间(秒)
|
||||
# printf " 倒计时:%03d秒\r" $remaining #\r使光标回到行首,实现实时更新显示,不换行
|
||||
# sleep 1 #等待1秒
|
||||
#done
|
||||
#echo " 倒计时结束!"
|
||||
|
||||
#分割线
|
||||
#echo -e "\n===============================================\n"
|
||||
|
||||
##检测服务器是否重启成功
|
||||
#reboot_num=0
|
||||
#for trans_ip in $(cat ${scripts_path}/build/${trans_file}) ; do
|
||||
# sshpass -f ${scripts_path}/build/${passwd_file} ssh -o StrictHostKeyChecking=no -o ConnectTimeout=2 root@${trans_ip} 'ls' > /dev/null 2>&1
|
||||
# if [ $? -eq 0 ]; then
|
||||
# echo -e "${GREEN} ${trans_ip} 重启成功 ${RES}"
|
||||
# else
|
||||
# echo -e "${RED} ${trans_ip} 重启失败 ${RES}"
|
||||
# echo "${trans_ip} 重启失败" >> ${scripts_path}/files/${nc_yes_no}
|
||||
# sed -i "/${trans_ip}/d" ${scripts_path}/build/${trans_file}
|
||||
# reboot_num=$(( reboot_num + 1 ))
|
||||
# fi
|
||||
#done
|
||||
#if [ ${reboot_num} -ne 0 ] ; then
|
||||
# echo -e "\n${RED} 有${reboot_num}个服务器重启失败 ${RES}"
|
||||
# echo "有${reboot_num}个服务器重启失败" >> ${scripts_path}/files/${nc_yes_no}
|
||||
#fi
|
||||
|
||||
#分割线
|
||||
echo -e "\n===============================================\n"
|
||||
|
||||
#备份重启后的路由表并且对比看是否一致
|
||||
array_diffroute=()
|
||||
route_num=0
|
||||
for trans_ip in $(cat ${scripts_path}/build/${trans_file}) ; do
|
||||
sshpass -f ${scripts_path}/build/${passwd_file} ssh -o StrictHostKeyChecking=no root@${trans_ip} 'route -n > /root/route.txt'
|
||||
sshpass -f ${scripts_path}/build/${passwd_file} scp -o StrictHostKeyChecking=no root@${trans_ip}:/root/route.txt ${scripts_path}/files/${trans_ip}_new.txt
|
||||
awk '{if ($5 != "0") print $0}' ${scripts_path}/files/${trans_ip}_old.txt | awk '{$5 = ""; $6 = ""; $7 = ""; print $0}' > ${scripts_path}/files/${trans_ip}_old_modify.txt
|
||||
awk '{if ($5 != "0") print $0}' ${scripts_path}/files/${trans_ip}_new.txt | awk '{$5 = ""; $6 = ""; $7 = ""; print $0}' > ${scripts_path}/files/${trans_ip}_new_modify.txt
|
||||
diff ${scripts_path}/files/${trans_ip}_old_modify.txt ${scripts_path}/files/${trans_ip}_new_modify.txt
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN} ${trans_ip} 路由没变 ${RES}"
|
||||
else
|
||||
echo -e "${RED} ${trans_ip} 路由前后不一致 ${RES}"
|
||||
echo "${trans_ip} 路由前后不一致" >> ${scripts_path}/files/${nc_yes_no}
|
||||
echo -e "\n===============================================\n" >> ${scripts_path}/files/${nc_yes_no}
|
||||
echo -e "${trans_ip} 重启前路由\n" >> ${scripts_path}/files/${nc_yes_no}
|
||||
awk '{print $0}' ${scripts_path}/files/${trans_ip}_old.txt >> ${scripts_path}/files/${nc_yes_no}
|
||||
echo -e "\n===============================================\n" >> ${scripts_path}/files/${nc_yes_no}
|
||||
echo -e "${trans_ip} 重启后路由\n" >> ${scripts_path}/files/${nc_yes_no}
|
||||
awk '{print $0}' ${scripts_path}/files/${trans_ip}_new.txt >> ${scripts_path}/files/${nc_yes_no}
|
||||
echo -e "\n===============================================\n" >> ${scripts_path}/files/${nc_yes_no}
|
||||
echo -e "\n===============================================\n"
|
||||
route_num=$(( route_num + 1 ))
|
||||
array_diffroute+=("${trans_ip}--路由前后不一致")
|
||||
fi
|
||||
rm -rf ${scripts_path}/files/${trans_ip}_old_modify.txt
|
||||
rm -rf ${scripts_path}/files/${trans_ip}_new_modify.txt
|
||||
done
|
||||
if [ ${route_num} -ne 0 ] ; then
|
||||
echo -e "\n${RED} 有${route_num}个服务器路由不一致 ${RES}"
|
||||
echo "有${route_num}个服务器路由不一致" >> ${scripts_path}/files/${nc_yes_no}
|
||||
fi
|
||||
|
||||
#分割线
|
||||
echo -e "\n===============================================\n"
|
||||
|
||||
#测试端口连通性
|
||||
array_port=()
|
||||
for trans_ip in $(cat ${scripts_path}/build/${trans_file}) ; do
|
||||
echo -e "${GREEN} 测试${trans_ip}服务器端口联通性 ${RES}\n"
|
||||
echo -e "测试${trans_ip}服务器端口联通性\n" >> ${scripts_path}/files/${nc_yes_no}
|
||||
while IFS=' ' read -r ip port desc || [[ -n "$ip" && -n "$port" && -n "$desc" ]] ; do
|
||||
sshpass -f ${scripts_path}/build/${passwd_file} ssh -o StrictHostKeyChecking=no -n root@${trans_ip} "nc -zw2 ${ip} ${port}"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN} ${desc} ${ip} ${port} 端口访问成功 ${RES}"
|
||||
echo -e " ${desc} ${ip} ${port} 端口访问成功" >> ${scripts_path}/files/${nc_yes_no}
|
||||
else
|
||||
echo -e "${RED} ${desc} ${ip} ${port} 端口访问失败。。。。。。 ${RES}"
|
||||
echo -e " ${desc} ${ip} ${port} 端口访问失败。。。。。。" >> ${scripts_path}/files/${nc_yes_no}
|
||||
array_port+=("${trans_ip}访问${desc}${ip}:${port}失败")
|
||||
fi
|
||||
done < ${scripts_path}/build/${nc_file}
|
||||
if [ -s ${scripts_path}/build/${aliyun_file} ] ; then
|
||||
for aliyun_ip in $(cat ${scripts_path}/build/${aliyun_file}) ; do
|
||||
if [ "${trans_ip}" = "${aliyun_ip}" ] ; then
|
||||
while IFS=' ' read -r ip port desc || [[ -n "$ip" && -n "$port" && -n "$desc" ]] ; do
|
||||
sshpass -f ${scripts_path}/build/${passwd_file} ssh -o StrictHostKeyChecking=no -n root@${trans_ip} "nc -zw2 ${ip} ${port}"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN} ${desc} ${ip} ${port} 端口访问成功 ${RES}"
|
||||
echo -e " ${desc} ${ip} ${port} 端口访问成功" >> ${scripts_path}/files/${nc_yes_no}
|
||||
else
|
||||
echo -e "${RED} ${desc} ${ip} ${port} 端口访问失败。。。。。。 ${RES}"
|
||||
echo -e " ${desc} ${ip} ${port} 端口访问失败。。。。。。" >> ${scripts_path}/files/${nc_yes_no}
|
||||
array_port+=("${trans_ip}访问${desc}${ip}:${port}失败")
|
||||
fi
|
||||
done < ${scripts_path}/build/${aliyun_nc_file}
|
||||
fi
|
||||
done
|
||||
fi
|
||||
echo -e "\n===============================================\n"
|
||||
echo -e "\n===============================================\n" >> ${scripts_path}/files/${nc_yes_no}
|
||||
done
|
||||
|
||||
|
||||
#展示报错服务器
|
||||
if [ ${#array_ssherror[@]} -ne 0 ]; then
|
||||
for element_ssherror in "${array_ssherror[@]}" ; do
|
||||
echo -e "${RED} ${element_ssherror} ${RES}"
|
||||
done
|
||||
echo -e "\n===============================================\n"
|
||||
fi
|
||||
|
||||
if [ ${#array_login[@]} -ne 0 ]; then
|
||||
for element_login in "${array_login[@]}" ; do
|
||||
echo -e "${RED} ${element_login} ${RES}"
|
||||
done
|
||||
echo -e "\n===============================================\n"
|
||||
fi
|
||||
|
||||
if [ ${#array_nc[@]} -ne 0 ]; then
|
||||
for element_nc in "${array_nc[@]}" ; do
|
||||
echo -e "${RED} ${element_nc} ${RES}"
|
||||
done
|
||||
echo -e "\n===============================================\n"
|
||||
fi
|
||||
|
||||
if [ ${#array_reboot[@]} -ne 0 ]; then
|
||||
for element_reboot in "${array_reboot[@]}" ; do
|
||||
echo -e "${RED} ${element_reboot} ${RES}"
|
||||
done
|
||||
echo -e "\n===============================================\n"
|
||||
fi
|
||||
|
||||
if [ ${#array_diffroute[@]} -ne 0 ]; then
|
||||
for element_diffroute in "${array_diffroute[@]}" ; do
|
||||
echo -e "${RED} ${element_diffroute} ${RES}"
|
||||
done
|
||||
echo -e "\n===============================================\n"
|
||||
fi
|
||||
|
||||
if [ ${#array_port[@]} -ne 0 ]; then
|
||||
for element_port in "${array_port[@]}" ; do
|
||||
echo -e "${RED} ${element_port} ${RES}"
|
||||
done
|
||||
echo -e "\n===============================================\n"
|
||||
fi
|
||||
|
||||
#备份必要的文件
|
||||
echo -e "\n${GREEN} 文件已备份到目录${scripts_path}/backup/${date}_nc下 ${RES}"
|
||||
echo "文件已备份到目录${scripts_path}/backup/${date}_nc下" >> ${scripts_path}/files/${nc_yes_no}
|
||||
echo -e "${GREEN} ${scripts_path}/backup/${nc_yes_no}是报错和连通性测试结果文件 ${RES}\n"
|
||||
echo "${scripts_path}/backup/${nc_yes_no}是报错和连通性测试结果文件" >> ${scripts_path}/files/${nc_yes_no}
|
||||
mkdir -p ${scripts_path}/backup/${date}_nc
|
||||
cp -rf ${scripts_path}/files/${nc_yes_no} ${scripts_path}/backup
|
||||
mv ${scripts_path}/files ${scripts_path}/build ${scripts_path}/backup/${date}_nc
|
||||
cp -rf ${scripts_path}/conf/${original} ${scripts_path}/backup/${date}_nc/build
|
||||
|
||||
4
sh/udpseq_del.bat
Normal file
4
sh/udpseq_del.bat
Normal file
@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
set SrcDir=C:\fcserver_q-x64\xtp\quote2\1
|
||||
set DaysAgo=0 %日期自定义,此处代表0天前%
|
||||
forfiles /p %SrcDir% /m udpseq* /c "cmd /c del /f /q /a @path"
|
||||
98
sh/xz_log_all.sh
Normal file
98
sh/xz_log_all.sh
Normal file
@ -0,0 +1,98 @@
|
||||
#!/bin/bash
|
||||
# 功能:扫描 /home/system 下所有包含指定年份日志的目录,列出确认再打包
|
||||
# 删除功能在74 75 行
|
||||
# 用法:./xz_log_all.sh <年份> 例如:./xz_log_all.sh 2025
|
||||
|
||||
set -u
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "错误:请指定年份,例如 ./xz_log_all.sh 2025"
|
||||
exit 1
|
||||
fi
|
||||
year="$1"
|
||||
|
||||
if ! [[ "$year" =~ ^[0-9]{4}$ ]]; then
|
||||
echo "错误:年份格式不正确,应为四位数字"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 临时文件
|
||||
dir_all=$(mktemp)
|
||||
dir_target=$(mktemp)
|
||||
trap "rm -f $dir_all $dir_target" EXIT
|
||||
|
||||
echo "正在扫描 /home/system 下的日志目录..."
|
||||
find /home/system -type f -name "*.log" -printf "%h\n" 2>/dev/null | sort -u > "$dir_all"
|
||||
|
||||
echo "正在检查各目录中是否存在 ${year} 年的日志文件..."
|
||||
while IFS= read -r dir; do
|
||||
[ -d "$dir" ] || continue
|
||||
if find "$dir" -maxdepth 1 -type f -name "*$year*.log" -printf "%f\n" 2>/dev/null | grep -q .; then
|
||||
echo "$dir" >> "$dir_target"
|
||||
fi
|
||||
done < "$dir_all"
|
||||
|
||||
if [ ! -s "$dir_target" ]; then
|
||||
echo "未找到任何包含 ${year} 年日志的目录,退出。"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "找到以下 ${year} 年日志所在的目录(共 $(wc -l < "$dir_target") 个):"
|
||||
cat -n "$dir_target" | sed 's/^/ /'
|
||||
|
||||
read -p "是否开始打包这些目录中的 ${year} 年日志?(y/N) " -r confirm
|
||||
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
|
||||
echo "操作已取消。"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
success_count=0
|
||||
fail_count=0
|
||||
total=$(wc -l < "$dir_target")
|
||||
echo "开始打包(共 $total 个目录)..."
|
||||
|
||||
# 循环读取目录列表
|
||||
while IFS= read -r dir; do
|
||||
current=$((success_count + fail_count + 1))
|
||||
echo "[$current/$total] 正在处理目录:$dir"
|
||||
|
||||
# 使用子shell处理,避免影响父shell环境,并重定向 stdin 以防干扰
|
||||
(
|
||||
cd "$dir" < /dev/null || exit 1
|
||||
|
||||
# 统计文件数量
|
||||
file_count=$(find . -maxdepth 1 -type f -name "*$year*.log" -printf "%f\n" 2>/dev/null | wc -l)
|
||||
if [ "$file_count" -eq 0 ]; then
|
||||
echo " 目录中没有 $year 年的日志文件,跳过"
|
||||
exit 0
|
||||
fi
|
||||
echo " 找到 $file_count 个文件,正在压缩..."
|
||||
|
||||
# 打包压缩(直接管道传递 null 分隔的文件名)
|
||||
if find . -maxdepth 1 -type f -name "*$year*.log" -printf "%f\0" | tar --null -c -T - | xz -9 > "${year}.tar.xz"; then
|
||||
echo " ✓ 已生成 ${year}.tar.xz"
|
||||
# 如需删除原始文件,取消下面注释
|
||||
find . -maxdepth 1 -type f -name "*$year*.log" -delete
|
||||
echo " 已删除原始文件"
|
||||
exit 0
|
||||
else
|
||||
echo " ✗ 打包失败 $dir" >&2
|
||||
exit 1
|
||||
fi
|
||||
)
|
||||
|
||||
# 根据子shell退出码统计成功/失败
|
||||
if [ $? -eq 0 ]; then
|
||||
((success_count++))
|
||||
else
|
||||
((fail_count++))
|
||||
fi
|
||||
|
||||
done < "$dir_target"
|
||||
|
||||
echo "完成!成功: $success_count, 失败: $fail_count"
|
||||
if [ $fail_count -gt 0 ]; then
|
||||
echo "请检查失败的目录。"
|
||||
fi
|
||||
echo "如需删除原始日志文件,可进入对应目录手动执行:rm -f *${year}*.log"
|
||||
echo "当前已启用删除原始文件"
|
||||
108
sh/xz_log_all_month.sh
Normal file
108
sh/xz_log_all_month.sh
Normal file
@ -0,0 +1,108 @@
|
||||
#!/bin/bash
|
||||
# 功能:按年份/月份打包 /home/system 下的日志文件
|
||||
# 用法:
|
||||
# ./xz_log_all.sh 打包上个月的日志
|
||||
# ./xz_log_all.sh 2025 打包2025年全年
|
||||
# ./xz_log_all.sh 202503 打包2025年3月
|
||||
# 注意:删除原始文件功能在89行,可自行注释或开启
|
||||
|
||||
set -u
|
||||
|
||||
# -------------------- 参数解析 --------------------
|
||||
if [ $# -eq 0 ]; then
|
||||
# 无参数:打包上个月
|
||||
match_str=$(date -d "$(date +%Y-%m-01) -1 month" +%Y%m)
|
||||
echo "未指定年份/月份,将打包上个月 ($match_str) 的日志。"
|
||||
elif [ $# -eq 1 ]; then
|
||||
param="$1"
|
||||
if [[ "$param" =~ ^[0-9]{4}$ ]]; then
|
||||
match_str="$param"
|
||||
echo "将打包 $match_str 年全年的日志。"
|
||||
elif [[ "$param" =~ ^[0-9]{6}$ ]]; then
|
||||
match_str="$param"
|
||||
echo "将打包 $match_str 年月的日志。"
|
||||
else
|
||||
echo "错误:参数必须是 4 位年份或 6 位年月(如 2025 或 202503)"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "错误:参数数量不正确,最多接受一个参数。"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# -------------------- 临时文件 --------------------
|
||||
dir_all=$(mktemp)
|
||||
dir_target=$(mktemp)
|
||||
trap "rm -f $dir_all $dir_target" EXIT
|
||||
|
||||
# -------------------- 扫描目录 --------------------
|
||||
echo "正在扫描 /home/system 下的日志目录..."
|
||||
find /home/system -type f -name "*.log" -printf "%h\n" 2>/dev/null | sort -u > "$dir_all"
|
||||
|
||||
echo "正在检查各目录中是否存在匹配 $match_str 的日志文件..."
|
||||
while IFS= read -r dir; do
|
||||
[ -d "$dir" ] || continue
|
||||
if find "$dir" -maxdepth 1 -type f -name "*${match_str}*.log" -printf "%f\n" 2>/dev/null | grep -q .; then
|
||||
echo "$dir" >> "$dir_target"
|
||||
fi
|
||||
done < "$dir_all"
|
||||
|
||||
if [ ! -s "$dir_target" ]; then
|
||||
echo "未找到任何包含匹配 $match_str 的日志的目录,退出。"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "找到以下匹配的目录(共 $(wc -l < "$dir_target") 个):"
|
||||
cat -n "$dir_target" | sed 's/^/ /'
|
||||
|
||||
read -p "手动执行前请查看该脚本是否开启删除功能,确认后再继续,是否开始打包这些目录中的日志?(y/N) " -r confirm
|
||||
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
|
||||
echo "操作已取消。"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# -------------------- 执行打包 --------------------
|
||||
success_count=0
|
||||
fail_count=0
|
||||
total=$(wc -l < "$dir_target")
|
||||
archive_name="${match_str}.tar.xz"
|
||||
echo "开始打包(共 $total 个目录)..."
|
||||
|
||||
while IFS= read -r dir; do
|
||||
current=$((success_count + fail_count + 1))
|
||||
echo "[$current/$total] 正在处理目录:$dir"
|
||||
|
||||
# 使用子 shell 处理单个目录
|
||||
(
|
||||
cd "$dir" < /dev/null || exit 1
|
||||
|
||||
file_count=$(find . -maxdepth 1 -type f -name "*${match_str}*.log" -printf "%f\n" 2>/dev/null | wc -l)
|
||||
if [ "$file_count" -eq 0 ]; then
|
||||
echo " 目录中没有匹配的日志文件,跳过"
|
||||
exit 0
|
||||
fi
|
||||
echo " 找到 $file_count 个文件,正在压缩..."
|
||||
|
||||
if find . -maxdepth 1 -type f -name "*${match_str}*.log" -printf "%f\0" | tar --null -c -T - | xz -9 > "$archive_name"; then
|
||||
echo " ✓ 已生成 $archive_name"
|
||||
# 如需删除原始文件,取消下面注释(谨慎!)
|
||||
find . -maxdepth 1 -type f -name "*${match_str}*.log" -delete
|
||||
exit 0
|
||||
else
|
||||
echo " ✗ 打包失败 $dir" >&2
|
||||
exit 1
|
||||
fi
|
||||
)
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
((success_count++))
|
||||
else
|
||||
((fail_count++))
|
||||
fi
|
||||
done < "$dir_target"
|
||||
|
||||
echo "完成!成功: $success_count, 失败: $fail_count"
|
||||
if [ $fail_count -gt 0 ]; then
|
||||
echo "请检查失败的目录。"
|
||||
fi
|
||||
echo "执行完成"
|
||||
4
sh/zhubi_del.bat
Normal file
4
sh/zhubi_del.bat
Normal file
@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
set SrcDir=C:\fcserver_q-x64
|
||||
set DaysAgo=3 %日期自定义,此处代表3天前%
|
||||
forfiles /p %SrcDir% /m zhubi_* /d -%DaysAgo% /c "cmd /c del /f /q /a @path"
|
||||
7
sh/微信双开.bat
Normal file
7
sh/微信双开.bat
Normal file
@ -0,0 +1,7 @@
|
||||
@echo off
|
||||
#关闭已经启动的微信
|
||||
taskkill /f /t /im WeChat.exe
|
||||
#想开几个微信就重复几行;其中C:\Program Files\Tencent\WeChat为安装路径,可以根据自己安装路径进行替换
|
||||
start /d "D:\Program Files\Tencent\Weixin\Weixin.exe"
|
||||
start /d "C:\Program Files\Tencent\WeChat" WeChat.exe
|
||||
exit
|
||||
Loading…
Reference in New Issue
Block a user