feat: 为检查脚本增加失败时的操作手册提示及详细步骤说明
This commit is contained in:
1 parent
0ead3cf91e
commit
b2bc382711
2 files changed
+44
-26
No files matched your search
+25
-16
@@ -18,6 +18,8 @@ TOTAL=0
|
||||
PASS_CNT=0
|
||||
FAIL_CNT=0
|
||||
TASK_CNT=0
|
||||
MANUAL_LOCATION=''
|
||||
MANUAL_HINT_SHOWN=0
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
@@ -34,6 +36,8 @@ banner() {
|
||||
}
|
||||
section() {
|
||||
TASK_CNT=$((TASK_CNT+1))
|
||||
MANUAL_LOCATION=${2:-}
|
||||
MANUAL_HINT_SHOWN=0
|
||||
printf '%b[➜] %d. %s%b\n' "$BLUE" "$TASK_CNT" "$1" "$NC"
|
||||
}
|
||||
error() {
|
||||
@@ -51,6 +55,11 @@ check() {
|
||||
else
|
||||
FAIL_CNT=$((FAIL_CNT+1))
|
||||
printf '%b[✘ 失败] %s%b\n' "$RED" "$failure_message" "$NC"
|
||||
# 同一任务只在第一次失败时提示手册位置;全部通过时不增加输出。
|
||||
if [ -n "$MANUAL_LOCATION" ] && [ "$MANUAL_HINT_SHOWN" -eq 0 ]; then
|
||||
printf '%b → 手册:%s%b\n' "$RED" "$MANUAL_LOCATION" "$NC"
|
||||
MANUAL_HINT_SHOWN=1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
finish() {
|
||||
@@ -71,7 +80,7 @@ finish() {
|
||||
exit 1
|
||||
}
|
||||
preflight() {
|
||||
if [ "$EUID" -ne 0 ]; then error '请以 root 身份在对应节点执行。未评分。'; exit 2; fi
|
||||
if [ "$EUID" -ne 0 ]; then error '请在 compute 节点用 root 执行。未评分。'; exit 2; fi
|
||||
local cmd
|
||||
for cmd in awk grep sort tr timeout; do
|
||||
if ! command -v "$cmd" >/dev/null 2>&1; then error "缺少基础工具 $cmd,无法评分。"; exit 2; fi
|
||||
@@ -128,7 +137,7 @@ if ! valid_ipv4 "$CONTROLLER_IP"; then error '控制节点 IP 参数或 hosts
|
||||
if [ -n "${CHECK_COMPUTE_IP:-}" ] && ! valid_ipv4 "$CHECK_COMPUTE_IP"; then error 'CHECK_COMPUTE_IP 无效。未评分。'; exit 2; fi
|
||||
case "$REPO_BASE" in http://*|https://*) ;; *) error '软件源根 URL 必须使用 http(s)。未评分。'; exit 2;; esac
|
||||
|
||||
section '安全设置(8分)'
|
||||
section '安全设置(8分)' '节点环境准备 / 二、基础安全设置'
|
||||
firewall_stopped() { [ "$(timeout 10 systemctl is-active firewalld 2>/dev/null)" = inactive ]; }
|
||||
firewall_disabled() {
|
||||
local state
|
||||
@@ -147,7 +156,7 @@ check 2 'firewalld 自启已禁用' 'firewalld 自启未禁用' firewall_disable
|
||||
check 2 'SELinux 非强制模式' 'SELinux 仍强制执行或查询失败' selinux_runtime
|
||||
check 2 'SELinux 永久禁用' 'SELinux 未永久禁用' selinux_persistent
|
||||
|
||||
section '主机与网络(12分)'
|
||||
section '主机与网络(12分)' '节点环境准备 / 三、配置主机名解析(检查 /etc/hosts)'
|
||||
hostname_ok() { [ "$(hostname)" = compute ] && [ "$(tr -d '[:space:]' < /etc/hostname)" = compute ]; }
|
||||
controller_mapping() { [ "$(hosts_ip controller)" = "$CONTROLLER_IP" ]; }
|
||||
compute_mapping() {
|
||||
@@ -164,7 +173,7 @@ check 2 '主机名解析' '主机名解析与 hosts 不一致' both_resolve
|
||||
check 2 'localhost 映射保留' 'localhost 映射缺失' localhost_preserved
|
||||
check 2 'ping controller' 'ping controller 不通' timeout 8 ping -4 -c 2 -W 2 controller
|
||||
|
||||
section '软件源(15分)'
|
||||
section '软件源(15分)' '节点环境准备 / 四、配置软件源(配置文件、重建缓存)'
|
||||
# 每个仓库分别评价配置、repomd 索引、已有缓存,各1分。
|
||||
shopt -s nullglob
|
||||
REPOS=(/etc/yum.repos.d/*.repo)
|
||||
@@ -222,7 +231,7 @@ CentOS-QEMU-EV.repo|local-qemu-ev|vault-centos-qemu-ev
|
||||
CentOS-OpenStack-rocky.repo|local-openstack-rocky|vault-centos-openstack-rocky
|
||||
REPOLIST
|
||||
|
||||
section '时间同步(15分)'
|
||||
section '时间同步(15分)' '节点环境准备 / 五、配置 NTP 时间同步(按提示的步骤检查)'
|
||||
chrony_config() {
|
||||
awk '{sub(/[#!;].*/,"")}
|
||||
$1=="server" && $2=="controller" {n++; for(i=3;i<=NF;i++)if($i=="iburst")good++}
|
||||
@@ -237,16 +246,16 @@ chrony_synced() {
|
||||
$1 ~ /^[\^=]/ && $2!=ip {bad=1}
|
||||
END{exit !(found && !bad)}'
|
||||
}
|
||||
check 2 'chrony 已安装' 'chrony 未安装' rpm -q chrony
|
||||
check 4 'chrony 时间源配置' 'chrony 应仅启用 server controller iburst' chrony_config
|
||||
check 2 'chronyd 运行' 'chronyd 未运行' active_service chronyd
|
||||
check 2 'chronyd 自启' 'chronyd 未设置自启' enabled_service chronyd
|
||||
check 5 '时间已同步到 controller' '时间源未选中 controller 或有其他源' chrony_synced
|
||||
check 2 'chrony 已安装' 'chrony 未安装(第1步:安装软件)' rpm -q chrony
|
||||
check 4 'chrony 时间源配置' '时间源配置不符(第2步:修改 chrony.conf)' chrony_config
|
||||
check 2 'chronyd 运行' 'chronyd 未运行(第3步:启动服务)' active_service chronyd
|
||||
check 2 'chronyd 自启' 'chronyd 未设置自启(第3步:设置自启)' enabled_service chronyd
|
||||
check 5 '时间已同步到 controller' '尚未仅同步到 controller(第4步:检查 chronyc sources)' chrony_synced
|
||||
|
||||
section 'Nova 软件包(5分)'
|
||||
section 'Nova 软件包(5分)' '部署过程 / 一、安装并配置 Nova 计算组件 / 安装软件包'
|
||||
check 5 'nova-compute 已安装' 'nova-compute 未安装' rpm -q openstack-nova-compute
|
||||
|
||||
section 'Nova 配置(30分)'
|
||||
section 'Nova 配置(30分)' '部署过程 / 一、安装并配置 Nova 计算组件 / 编辑 /etc/nova/nova.conf'
|
||||
# 配置按小组评分;组内错误键附在失败提示中,不输出实际值或口令。
|
||||
config_group() {
|
||||
local points=$1 group=$2 key expected actual bad=''
|
||||
@@ -273,7 +282,7 @@ config_group() {
|
||||
done
|
||||
# my_ip 必须同时属于本机;即便 hosts 未完成,也不接受示例中的远端 IP。
|
||||
if [ "$group" = DEFAULT ] && ! compute_mapping >/dev/null 2>&1; then bad="$bad my_ip/hosts/本机地址"; fi
|
||||
check "$points" "Nova [$group]" "Nova [$group] 错误键:${bad:-文件不可读}" test -z "$bad"
|
||||
check "$points" "Nova [$group]" "请核对 nova.conf 的 [$group]:${bad:-文件不可读}" test -z "$bad"
|
||||
}
|
||||
config_group 6 DEFAULT enabled_apis 'osapi_compute,metadata' transport_url 'rabbit://openstack:openstack@controller' my_ip "$COMPUTE_IP" use_neutron true firewall_driver nova.virt.firewall.NoopFirewallDriver
|
||||
config_group 2 api auth_strategy keystone
|
||||
@@ -283,7 +292,7 @@ config_group 3 glance api_servers http://controller:9292
|
||||
config_group 2 oslo_concurrency lock_path /var/lib/nova/tmp
|
||||
config_group 5 placement region_name RegionOne project_domain_name Default project_name service auth_type password user_domain_name Default auth_url http://controller:5000/v3 username placement password placement
|
||||
|
||||
section '虚拟化类型(5分)'
|
||||
section '虚拟化类型(5分)' '部署过程 / 一、安装并配置 Nova 计算组件 / 配置硬件加速'
|
||||
virtualization_ok() {
|
||||
local type
|
||||
[ -r /proc/cpuinfo ] && [ -r "$CONF" ] || return 1
|
||||
@@ -294,9 +303,9 @@ virtualization_ok() {
|
||||
fi
|
||||
[ "$type" = qemu ]
|
||||
}
|
||||
check 5 '虚拟化类型' '虚拟化类型不匹配;无 vmx/svm 时需用 qemu' virtualization_ok
|
||||
check 5 '虚拟化类型' '虚拟化类型不符:无 vmx/svm 时设置 virt_type=qemu' virtualization_ok
|
||||
|
||||
section '服务状态(10分)'
|
||||
section '服务状态(10分)' '部署过程 / 一、安装并配置 Nova 计算组件 / 启动计算服务'
|
||||
for service in libvirtd openstack-nova-compute; do
|
||||
check 3 "$service 运行" "$service 未运行" active_service "$service"
|
||||
check 2 "$service 自启" "$service 未设置自启" enabled_service "$service"
|
||||
|
||||
+19
-10
@@ -18,6 +18,8 @@ TOTAL=0
|
||||
PASS_CNT=0
|
||||
FAIL_CNT=0
|
||||
TASK_CNT=0
|
||||
MANUAL_LOCATION=''
|
||||
MANUAL_HINT_SHOWN=0
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
@@ -34,6 +36,8 @@ banner() {
|
||||
}
|
||||
section() {
|
||||
TASK_CNT=$((TASK_CNT+1))
|
||||
MANUAL_LOCATION=${2:-}
|
||||
MANUAL_HINT_SHOWN=0
|
||||
printf '%b[➜] %d. %s%b\n' "$BLUE" "$TASK_CNT" "$1" "$NC"
|
||||
}
|
||||
error() {
|
||||
@@ -51,6 +55,11 @@ check() {
|
||||
else
|
||||
FAIL_CNT=$((FAIL_CNT+1))
|
||||
printf '%b[✘ 失败] %s%b\n' "$RED" "$failure_message" "$NC"
|
||||
# 同一任务只在第一次失败时提示手册位置;全部通过时不增加输出。
|
||||
if [ -n "$MANUAL_LOCATION" ] && [ "$MANUAL_HINT_SHOWN" -eq 0 ]; then
|
||||
printf '%b → 手册:%s%b\n' "$RED" "$MANUAL_LOCATION" "$NC"
|
||||
MANUAL_HINT_SHOWN=1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
finish() {
|
||||
@@ -71,7 +80,7 @@ finish() {
|
||||
exit 1
|
||||
}
|
||||
preflight() {
|
||||
if [ "$EUID" -ne 0 ]; then error '请以 root 身份在对应节点执行。未评分。'; exit 2; fi
|
||||
if [ "$EUID" -ne 0 ]; then error '请在 controller 节点用 root 执行。未评分。'; exit 2; fi
|
||||
local cmd
|
||||
for cmd in awk grep sort tr timeout; do
|
||||
if ! command -v "$cmd" >/dev/null 2>&1; then error "缺少基础工具 $cmd,无法评分。"; exit 2; fi
|
||||
@@ -156,7 +165,7 @@ for row in rows:
|
||||
' "$@" 2>/dev/null
|
||||
}
|
||||
|
||||
section '主机与网络(20分)'
|
||||
section '主机与网络(20分)' '节点环境准备 / 三、配置主机名解析(在 controller 检查 /etc/hosts)'
|
||||
hostname_ok() { [ "$(hostname)" = controller ] && [ "$(tr -d '[:space:]' < /etc/hostname)" = controller ]; }
|
||||
controller_mapping() {
|
||||
[ "$(hosts_ip controller)" = "$CONTROLLER_IP" ] &&
|
||||
@@ -170,7 +179,7 @@ check 4 'compute hosts 映射' 'compute hosts 映射缺失或冲突' compute_map
|
||||
check 4 '主机名解析' '主机名解析与 hosts 不一致' both_resolve
|
||||
check 4 'ping compute' 'ping compute 不通' timeout 8 ping -4 -c 2 -W 2 compute
|
||||
|
||||
section '管理员认证(10分)'
|
||||
section '管理员认证(10分)' '部署过程 / 二、将计算节点添加到 Cell 数据库 / 第1步(检查管理员凭证)'
|
||||
AUTH_OK=0
|
||||
if os_cli token issue >/dev/null; then AUTH_OK=1; fi
|
||||
check 10 '管理员认证' '管理员认证失败,检查 Keystone 和密码' test "$AUTH_OK" -eq 1
|
||||
@@ -192,12 +201,12 @@ compute_ready() {
|
||||
$1=="nova-compute" && $2=="compute" {n++; if($3=="enabled" && $4=="up")good++}
|
||||
END{exit !(n==1 && good==1)}'
|
||||
}
|
||||
section 'compute 注册(10分)'
|
||||
section 'compute 注册(10分)' '部署过程 / 二、将计算节点添加到 Cell 数据库 / 第2步'
|
||||
check 10 'compute 服务注册' 'compute 未唯一注册或查询失败' compute_registered
|
||||
section 'compute 状态(10分)'
|
||||
section 'compute 状态(10分)' '部署过程 / 一、安装并配置 Nova 计算组件 / 启动计算服务(回到 compute 检查)'
|
||||
check 10 'nova-compute enabled/up' 'nova-compute 未处于 enabled/up' compute_ready
|
||||
|
||||
section '服务状态(15分)'
|
||||
section '服务状态(15分)' '部署过程 / 三、验证部署结果 / 第1步(控制节点异常时回查环境准备第一节)'
|
||||
control_component() {
|
||||
[ "$SERVICES_OK" -eq 1 ] && printf '%s\n' "$SERVICES" | awk -v binary="$1" '
|
||||
$1==binary && $2=="controller" {n++; if($3=="enabled" && $4=="up")good++}
|
||||
@@ -212,7 +221,7 @@ check 5 'nova-scheduler enabled/up' 'nova-scheduler 缺失或未处于 enabled/u
|
||||
check 5 'nova-conductor enabled/up' 'nova-conductor 缺失或未处于 enabled/up' control_component nova-conductor
|
||||
check 5 '全部计算服务 enabled/up' '服务列表为空、查询失败或有异常服务' all_services_up
|
||||
|
||||
section 'Cell 映射(15分)'
|
||||
section 'Cell 映射(15分)' '部署过程 / 二、将计算节点添加到 Cell 数据库 / 第3步'
|
||||
# discover_hosts 会写数据库,评分时仅查询 host_mappings,避免替学生完成实验。
|
||||
cell_mapping() {
|
||||
local result
|
||||
@@ -223,9 +232,9 @@ cell_mapping() {
|
||||
/^[0-9a-fA-F-]+$/ && length($0)==36 && $0!="00000000-0000-0000-0000-000000000000" {good++}
|
||||
END{exit !(NR==1 && good==1)}'
|
||||
}
|
||||
check 15 'compute Cell 映射' 'Cell 映射异常,检查数据库和 discover_hosts' cell_mapping
|
||||
check 15 'compute Cell 映射' 'compute 加入 Cell 异常,检查 discover_hosts 结果及数据库连接' cell_mapping
|
||||
|
||||
section '服务目录(10分)'
|
||||
section '服务目录(10分)' '部署过程 / 三、验证部署结果 / 第2步'
|
||||
CATALOG_OK=0
|
||||
if [ "$AUTH_OK" -eq 1 ] && os_cli catalog list >/dev/null; then CATALOG_OK=1; fi
|
||||
catalog_endpoints() {
|
||||
@@ -244,7 +253,7 @@ catalog_endpoints() {
|
||||
check 5 'compute 服务目录与端点' 'compute 服务目录或端点异常' catalog_endpoints compute 8774
|
||||
check 5 'placement 服务目录与端点' 'placement 服务目录或端点异常' catalog_endpoints placement 8778
|
||||
|
||||
section '部署检查(10分)'
|
||||
section '部署检查(10分)' '部署过程 / 三、验证部署结果 / 第3步'
|
||||
# Rocky 返回码:0=全部成功,1=警告,2=失败;仅 0 得分,命令缺失/超时也失败。
|
||||
check 10 'nova-status upgrade check' 'nova-status 检查未全部成功' timeout 40 su -s /bin/sh -c 'nova-status upgrade check' nova
|
||||
finish
|
||||
Reference in new issue
Block a user