seaworld008/centos7-lighthouse / skills/centos7-almalinux-upgrade
centos7-almalinux-upgrade
Flagged把老旧 CentOS 7 / CentOS 8(及 RHEL7/8 系)服务器原地升级到最新 AlmaLinux 10(经 ELevate/Leapp 7→8→9→10,CentOS 8 先用 almalinux-deploy 转换),并保证业务、容器、nginx、kubectl 等升级后照常工作。凡是用户提到 CentOS 7 / CentOS 停服 / EOL / 老系统升级 / 迁移到 AlmaLinux / Rocky / CentOS 继任者 / ELevate / leapp / 系统漏洞要升级系统、批量升级阿里云/华为云/AWS 上的 CentOS 服务器,都要使用本技能——即使用户没说"升级"而只说"系统太老了""换个新系统但业务不能停"。In-place upgrade CentOS 7 to AlmaLinux 10 safely, single server or whole fleet.
scripts/verify.sh
View on GitHub#!/bin/bash
# verify.sh - 每跳升级后对比业务基线
# 用法: bash verify.sh <BACKUP_DIR 或 baseline.tsv 路径> [--wait 秒]
# --wait N : 先最多等 N 秒,让容器 / Java 应用起来再对比(默认 90)
# 输出: FAIL(必须处理)/ WARN(需判断是否预期变化)/ OK,退出码 = FAIL 数量
export LC_ALL=C
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HERE=$(cd "$(dirname "$0")" && pwd)
BL=$1; [ -d "$BL" ] && BL="$BL/baseline.tsv"
[ -f "$BL" ] || { echo "用法: verify.sh <baseline.tsv|BACKUP_DIR>"; exit 99; }
WAIT=90; [ "$2" = "--wait" ] && WAIT=${3:-90}
# 等待:直到基线里 running 的容器都 running,且没有 restarting,或超时
t=0
while [ $t -lt "$WAIT" ]; do
want=$(awk -F'\t' '$1=="ctr" && $3=="running"{print $2}' "$BL")
ok=1
for c in $want; do [ "$(docker inspect -f '{{.State.Status}}' "$c" 2>/dev/null)" = running ] || ok=0; done
docker ps --format '{{.Status}}' 2>/dev/null | grep -qiE "restarting|starting" && ok=0
[ $ok = 1 ] && [ $t -ge 30 ] && break
sleep 10; t=$((t+10))
done
# 反复重启检测:快照时刚好处于 running 也可能在 crash-loop(真实踩坑:快照瞬间显示 running)。间隔 30 秒看 RestartCount 是否还在涨
FLAP=""
if command -v docker >/dev/null 2>&1 && [ "$WAIT" -gt 0 ]; then
r1=$(docker ps -aq | xargs -r docker inspect -f '{{.Name}} {{.RestartCount}}' 2>/dev/null); sleep 30
r2=$(docker ps -aq | xargs -r docker inspect -f '{{.Name}} {{.RestartCount}}' 2>/dev/null)
FLAP=$(join <(echo "$r1" | sort) <(echo "$r2" | sort) 2>/dev/null | awk '$3>$2{print substr($1,2)" ("$2"→"$3")"}' | tr '\n' ' ')
fi
NOW=$(mktemp); bash "$HERE/state.sh" > "$NOW" 2>/dev/null
FAIL=0; WARNN=0
fail() { echo "FAIL $*"; FAIL=$((FAIL+1)); }
warn() { echo "WARN $*"; WARNN=$((WARNN+1)); }
echo "== 系统: $(awk -F'\t' '$1=="os"{print $2}' "$BL") → $(awk -F'\t' '$1=="os"{print $2}' "$NOW") kernel $(uname -r)"
# 服务:基线 active 的现在不 active
declare -A RENAMED=( [ntpd.service]=chronyd.service [dbus.service]=dbus-broker.service [network.service]=NetworkManager.service [iptables.service]=nftables.service )
awk -F'\t' '$1=="unit"{print $2}' "$BL" | while read -r u; do
grep -qP "^unit\t${u//./\\.}$" "$NOW" && continue
alt=${RENAMED[$u]}; [ -n "$alt" ] && grep -qP "^unit\t${alt//./\\.}$" "$NOW" && { echo "OK $u → $alt(预期的替换)"; continue; }
# 新版本 unit 带 Condition*(如 sssd 无配置文件就不启动):条件不满足而跳过属于预期
# 先区分"unit 已不存在"(被卸载/替换——要人判断)和"条件不满足被跳过"(预期);不存在的 unit 也会返回 ConditionResult=no
[ "$(systemctl show -p LoadState --value "$u" 2>/dev/null)" = not-found ] && { echo "WARN 服务 $u 已不存在(被卸载或改名):确认是否符合预期"; continue; }
[ "$(systemctl show -p ConditionResult --value "$u" 2>/dev/null)" = no ] && { echo "OK $u 未启动:启动条件不满足(无配置,新版本 unit 自动跳过,预期)"; continue; }
echo "WARN 服务 $u 升级前在运行,现在没有(systemctl status $u)"
done | tee /tmp/.v_units
WARNN=$((WARNN+$(grep -c ^WARN /tmp/.v_units)))
# 端口
awk -F'\t' '$1=="port"{print $2}' "$BL" | while read -r p; do
grep -qP "^port\t$p$" "$NOW" && continue
case "$p" in
udp/*) echo "WARN 端口 $p 升级前在监听,现在没有(UDP 常因 dhcp/chrony 等实现变化而不同)";;
*) echo "FAIL 端口 $p 升级前在监听,现在没有";;
esac
done | tee /tmp/.v_ports
FAIL=$((FAIL+$(grep -c ^FAIL /tmp/.v_ports))); WARNN=$((WARNN+$(grep -c ^WARN /tmp/.v_ports)))
# 容器
awk -F'\t' '$1=="ctr"{print $2"\t"$3}' "$BL" | while IFS=$'\t' read -r n s; do
now=$(awk -F'\t' -v n="$n" '$1=="ctr" && $2==n{print $3}' "$NOW")
if [ "$s" = running ] && [ "$now" != running ]; then echo "FAIL 容器 $n: 升级前 running,现在 ${now:-不存在}(docker logs --tail 50 $n)"; fi
done | tee /tmp/.v_ctr
FAIL=$((FAIL+$(grep -c ^FAIL /tmp/.v_ctr)))
[ -n "$FLAP" ] && { echo "FAIL 容器在 30 秒内仍在重启(crash-loop): $FLAP → docker logs --tail 50 <name>"; FAIL=$((FAIL+1)); }
# HTTP
awk -F'\t' '$1=="http"{print $2"\t"$3}' "$BL" | while IFS=$'\t' read -r url code; do
now=$(awk -F'\t' -v u="$url" '$1=="http" && $2==u{print $3}' "$NOW")
[ -z "$now" ] && now=$(curl -sk -o /dev/null -m 8 -w '%{http_code}' "$url")
[ "$code" = "$now" ] && continue
if [ "$code" != 000 ] && [ "$now" = 000 ]; then echo "FAIL $url: $code → $now(无响应)"
else echo "WARN $url: $code → $now"; fi
done | tee /tmp/.v_http
FAIL=$((FAIL+$(grep -c ^FAIL /tmp/.v_http))); WARNN=$((WARNN+$(grep -c ^WARN /tmp/.v_http)))
# kube
b=$(awk -F'\t' '$1=="kube"{print $3}' "$BL"); n=$(awk -F'\t' '$1=="kube"{print $3}' "$NOW")
[ -n "$b" ] && { [ "$b" = "$n" ] && echo "OK kubectl get nodes: $n Ready" || { echo "FAIL kubectl: 基线 $b 个 Ready 节点,现在 ${n:-命令失败}"; FAIL=$((FAIL+1)); }; }
echo "== systemctl --failed:"; systemctl --failed --no-legend --no-pager
echo "== 磁盘:"; df -h / /var /boot 2>/dev/null | awk 'NR==1||!seen[$0]++'
cp "$NOW" "$(dirname "$BL")/state-$(date +%Y%m%d-%H%M).tsv" 2>/dev/null
rm -f "$NOW" /tmp/.v_units /tmp/.v_ports /tmp/.v_ctr /tmp/.v_http
echo "== 结果: FAIL=$FAIL WARN=$WARNN"
exit $FAIL
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |