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/state.sh
View on GitHub#!/bin/bash
# state.sh - 输出当前"业务状态快照"(TSV),用于升级前基线和每跳之后对比
# 用法: bash state.sh > state.tsv
# 行格式:
# os <release>
# unit <service> (当前 active 的常驻服务)
# port <proto>/<port> (监听端口,不含地址,便于跨版本对比)
# ctr <name> <state> (docker 容器)
# http <url> <code> (nginx 各 server_name 的本地 https/http 状态码 + 各 TCP 端口 http 探测)
# kube nodes <Ready数量>
export LC_ALL=C
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
printf "os\t%s\n" "$(cat /etc/redhat-release 2>/dev/null)"
systemctl list-units --type=service --state=active --no-legend --no-pager 2>/dev/null \
| awk '{print $1}' | sed 's/^●//' \
| grep -vE "^(user@|user-runtime-dir@|session-|run-|leapp|systemd-|dracut|kmod|plymouth|getty@|serial-getty@|lvm2-pvscan@|initrd|sshd-keygen@|rhel-|cloud-|kdump|import-state|selinux|ldconfig|dnf-makecache|NetworkManager-wait-online|nis-domainname|loadmodules|network.service|rpc-statd|var-lib|blk-availability|microcode|readonly-root)" \
| sort -u | sed 's/^/unit\t/'
# 只监听 127.0.0.1 的临时端口(≥32768,如 kubelet 的 dockershim streaming 端口)每次启动都随机 → 不进基线
EPH=$(awk '{print $1}' /proc/sys/net/ipv4/ip_local_port_range 2>/dev/null); EPH=${EPH:-32768}
ss -tlnu 2>/dev/null | tail -n +2 | awk -v e="$EPH" '{split($5,a,":"); p=a[length(a)]; if ($5 ~ /^127\./ && p+0 >= e) next; print "port\t" $1 "/" p}' | sort -u # EL7 的 ss 没有 -H
if command -v docker >/dev/null 2>&1; then
# k8s_ 开头的是 kubelet 管理的 pod 容器(名字带 pod hash 和重启次数,重启后必然变化)→ 不进基线,用 k8s.sh pods 在集群层面对比
# Docker < 20.10 的 docker ps --format 没有 {{.State}}(报模板错误、不输出任何行)→ 用 {{.Status}} 推出状态
{ docker ps -a --format '{{.Names}}\t{{.State}}' 2>/dev/null || docker ps -a --format '{{.Names}}\t{{.Status}}' 2>/dev/null \
| awk -F'\t' '{s=$2; if (s ~ /^Up/) s=(s ~ /Paused/ ? "paused" : "running"); else if (s ~ /^Exited/) s="exited"; else if (s ~ /^Created/) s="created"; else if (s ~ /^Restarting/) s="restarting"; else if (s ~ /^Dead/) s="dead"; else if (s ~ /^Removal/) s="removing"; print $1 "\t" s}'; } \
| grep -v '^k8s_' | sort | sed 's/^/ctr\t/'
fi
# nginx 虚拟主机探测:宿主机 nginx + 容器里的 nginx/openresty/tengine(docker-proxy 映射到本机 80/443)
NG=$(pgrep -a nginx 2>/dev/null | grep master | grep -oE "/[^ ]*nginx( |$)" | head -1 | tr -d ' ')
[ -n "$NG" ] && [ ! -x "$NG" ] && NG="" # 容器里的 nginx 进程,路径在宿主机上不存在
[ -z "$NG" ] && command -v nginx >/dev/null 2>&1 && NG=$(command -v nginx)
# --http1.1 需要 curl ≥7.33;EL7 的 curl 7.29 不认识这个参数,整条命令报错 → 所有探测都成了 000(真实踩坑)
H11=""; curl --http1.1 -s -o /dev/null file:///dev/null 2>/dev/null && H11="--http1.1"
{
[ -n "$NG" ] && $NG -T 2>/dev/null
if command -v docker >/dev/null 2>&1; then
docker ps --format '{{.Names}} {{.Image}}' 2>/dev/null | grep -iE "nginx|openresty|tengine" | awk '{print $1}' | while read -r c; do
# 老 nginx(<1.9.2)没有 -T:退回到直接读容器挂载点和常见配置目录里的 *.conf
dests=$(docker inspect -f '{{range .Mounts}}{{.Destination}} {{end}}' "$c" 2>/dev/null)
docker exec "$c" sh -c "nginx -T 2>/dev/null || openresty -T 2>/dev/null || find $dests /etc/nginx /usr/local/openresty/nginx/conf /usr/local/nginx/conf /usr/servers/nginx/conf -name '*.conf' -type f -exec cat {} + 2>/dev/null" 2>/dev/null
done
fi
} | grep -E "^\s*server_name\s" | sed -E 's/^\s*server_name\s+//; s/;.*//' | tr ' ' '\n' \
| grep -vE "^(_|localhost|\*.*|~.*|)$" | sort -u | while read -r h; do
for sch in https http; do
port=443; [ $sch = http ] && port=80
# 固定 --http1.1(curl 支持时):EL7 的 curl 不走 h2,EL8+ 的 curl 默认协商 h2,且对非法响应头(如 add_header "X-Foo:" 带冒号)直接报 PROTOCOL_ERROR → 000,基线前后不可比
code=$(curl -sk $H11 -o /dev/null -m 8 -w '%{http_code}' --resolve "$h:$port:127.0.0.1" "$sch://$h/" 2>/dev/null)
printf "http\t%s://%s/\t%s\n" "$sch" "$h" "${code:-000}"
done
done
# 所有 TCP 端口按 IP 做 http 探测(443 用 https;非 http 服务稳定返回 000,作为基线照样可比)
SSHP=$(sshd -T 2>/dev/null | awk '/^port /{print $2}')
ss -tln 2>/dev/null | tail -n +2 | awk -v e="$EPH" '{split($4,a,":"); p=a[length(a)]; if ($4 ~ /^127\./ && p+0 >= e) next; print p}' | sort -un | while read -r p; do
case "$p" in 22|25|111|323|10050) continue;; esac
echo " $SSHP " | grep -q " $p " && continue
sch=http; [ "$p" = 443 ] || [ "$p" = 8443 ] && sch=https
code=$(curl -sk $H11 -o /dev/null -m 4 -w '%{http_code}' "$sch://127.0.0.1:$p/" 2>/dev/null)
printf "http\t%s://127.0.0.1:%s/\t%s\n" "$sch" "$p" "${code:-000}"
done
if command -v kubectl >/dev/null 2>&1 && [ -s /root/.kube/config ]; then
n=$(timeout 20 kubectl get nodes --no-headers 2>/dev/null | awk '$2 ~ /^Ready/' | wc -l)
printf "kube\tnodes\t%s\n" "$n"
fi
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 |