Skip to content

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.

FileKindSize
SKILL.mdskill md14.7 KB
assets/fleet-tracker.csvother617 B
assets/report-template.mdmarkdown850 B
references/app-compat.mdmarkdown14.5 KB
references/cloud-providers.mdmarkdown5.7 KB
references/fleet.mdmarkdown2.6 KB
references/kubernetes.mdmarkdown7.6 KB
references/pitfalls.mdmarkdown51.0 KB
references/recovery.mdmarkdown8.3 KB
scripts/backup.shexecutablescript5.0 KB
scripts/convert-el8.shexecutablescript7.6 KB
scripts/finalize.shexecutablescript12.5 KB
scripts/fleet_summary.pyexecutablescript7.9 KB
scripts/hop.shexecutablescript32.6 KB
scripts/k8s.shscript16.2 KB
scripts/known-hosts-fill.shscript2.7 KB
scripts/mysql-backup.shscript9.2 KB
scripts/nginx-static-build.shexecutablescript5.1 KB
scripts/post-audit.shexecutablescript12.4 KB
scripts/prep-el7.shexecutablescript13.5 KB
scripts/remote.pyexecutablescript9.7 KB
scripts/rescue-grubenv.shscript3.2 KB
scripts/state.shexecutablescript5.2 KB
scripts/survey.shexecutablescript28.6 KB
scripts/swap-openssh.shexecutablescript3.6 KB
scripts/verify.shexecutablescript5.3 KB

scripts/swap-openssh.sh

View on GitHub
#!/bin/bash
# swap-openssh.sh - 把自编译/第三方 openssh 换回发行版官方包(保留 sshd_config、端口、主机密钥)
#
# 为什么:leapp 不会升级"非官方签名"的 openssh,EL7 自编译 rpm 留到 EL8+ 后依赖缺失/SysV 脚本失效 → sshd 起不来 = 失联。
# 安全措施:
#   1. 先用官方二进制 sshd -t 测试现有 sshd_config,不通过就不换
#   2. 备份原 sshd/sshd-session 二进制
#   3. 用 systemd-run 脱离当前 SSH 会话执行(换包时当前会话可能被杀)
#   4. 换完 3 秒内端口没起来 → 自动用备份的旧 sshd 拉起来兜底
# 用法: bash swap-openssh.sh        (执行后用一个新连接验证,再看 /root/os-upgrade-kit/ossh-swap/swap.log)
export LC_ALL=C
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
W=/root/os-upgrade-kit/ossh-swap; mkdir -p "$W"; cd "$W" || exit 1
rpm -q openssh-server >/dev/null 2>&1 || { echo "openssh-server 未安装(rpm),无需替换"; exit 0; }
V=$(rpm -q --qf '%{VENDOR}' openssh-server)
case "$V" in *CentOS*|*AlmaLinux*|*"Red Hat"*) echo "openssh-server 已是官方包($V),无需替换"; exit 0;; esac
PORT=$(sshd -T 2>/dev/null | awk '/^port /{print $2; exit}'); PORT=${PORT:-22}
echo "当前: $(rpm -q openssh-server) vendor='$V'  sshd 端口 $PORT"

rm -f ./*.rpm; rm -rf x
if command -v dnf >/dev/null; then dnf -q download openssh openssh-server openssh-clients 2>&1 | tail -2
else rpm -q yum-utils >/dev/null || yum -y install yum-utils >/dev/null; yumdownloader -q openssh openssh-server openssh-clients 2>&1 | tail -2; fi
# yumdownloader 默认取最高版本,自编译版本号更高时它可能取不到官方包 → 明确过滤官方签名
ls ./*.rpm >/dev/null 2>&1 || { echo "下载官方 openssh 失败,检查 yum 源"; exit 1; }
for r in ./*.rpm; do rpm -qp --qf '%{VENDOR}\n' "$r" | grep -qE "CentOS|AlmaLinux|Red Hat" || { echo "$r 不是官方包,退出"; exit 1; }; done
mkdir x && (cd x && for r in ../*.rpm; do rpm2cpio "$r" | cpio -idm 2>/dev/null; done)
x/usr/sbin/sshd -t -f /etc/ssh/sshd_config 2>&1 | grep -v "UsePAM no" ; x/usr/sbin/sshd -t -f /etc/ssh/sshd_config >/dev/null 2>&1 \
  || { echo "!! 官方 sshd 不接受现有 sshd_config(上面是报错),先修配置再换"; exit 1; }
echo "官方 sshd 测试现有配置: OK"
mkdir -p old-bin; cp -a /usr/sbin/sshd old-bin/; cp -a /usr/libexec/openssh/sshd-session old-bin/ 2>/dev/null; cp -a /etc/ssh "$W/etc-ssh.bak"

cat > swap.sh <<EOF
#!/bin/bash
exec > $W/swap.log 2>&1; set -x
cd $W
rpm -Uvh --oldpackage --replacefiles --replacepkgs ./*.rpm
cp -a $W/etc-ssh.bak/sshd_config /etc/ssh/sshd_config
[ -e /etc/rc.d/init.d/sshd ] && rpm -qf /etc/rc.d/init.d/sshd >/dev/null 2>&1 || rm -f /etc/rc.d/init.d/sshd /etc/rc.d/rc*.d/[SK]*sshd
chmod 600 /etc/ssh/ssh_host_*_key; getent group ssh_keys >/dev/null && chgrp ssh_keys /etc/ssh/ssh_host_*_key
systemctl daemon-reload
/usr/sbin/sshd -t || echo CONFIG_FAIL
for p in \$(pgrep -f '^/usr/sbin/sshd'); do [ "\$(ps -o ppid= -p \$p | tr -d ' ')" = 1 ] && kill \$p; done
sleep 1; systemctl reset-failed sshd; systemctl enable sshd; systemctl start sshd; sleep 3
if ss -tlnp | grep -q ":$PORT .*sshd"; then echo SWAP_OK; else
  echo SWAP_FAIL_FALLBACK
  if [ -x $W/old-bin/sshd-session ]; then $W/old-bin/sshd -f /etc/ssh/sshd_config -o SshdSessionPath=$W/old-bin/sshd-session
  else $W/old-bin/sshd -f /etc/ssh/sshd_config; fi
fi
EOF
chmod +x swap.sh
systemd-run --unit="ossh-swap-$(date +%s)" "$W/swap.sh" >/dev/null && echo "已在后台执行替换。15 秒后用【新连接】验证,再看 $W/swap.log(应有 SWAP_OK)"
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 323kUpdated Claude CodeCodexVerifiedInstall
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: 198kUpdated Claude CodeCodexVerifiedInstall
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: 119kUpdated Claude CodeCodexVerifiedInstall
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: 118kUpdated Claude CodeCodexVerifiedInstall