首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >OAT 添加服务器时导致 yum 不可用

OAT 添加服务器时导致 yum 不可用

作者头像
爱可生开源社区
发布2026-02-03 14:53:54
发布2026-02-03 14:53:54
590
举报

作者:姚嵩,外星人,舍利小王子。

爱可生开源社区出品,原创内容未经授权不得随意使用,转载请联系小编并注明来源。

本文约 1700 字,预计阅读需要 5 分钟。


一、故障描述

使用 OAT 添加服务器时,导致 yum 不可用。

OAT 版本

版本号:4.4.0

操作

  1. 使用 OAT 添加服务器
  2. 网页路径:服务器 --> 添加服务器

任务报错内容

代码语言:javascript
复制
[2025-12-30T13:52:22.960+0800] ERROR - bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory
[2025-12-30T13:52:23.007+0800] ERROR - Install deps libaio libatomic gdb sysstat perf failed. If you are sure that the dependencies that failed to install are not needed, you can ignore them by specifying the system parameter oat.server.ignore_deps

二、报错分析

从报错日志中发现,在使用 yum 安装依赖包时,报错:

代码语言:javascript
复制
- bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory

于是登陆要添加的服务器主机,手动执行命令 yum provides '*/pvcreate' 确认待添加的主机 yum 是否能正常执行,结果是执行报错,手动执行的报错和任务报错内容一致:

代码语言:javascript
复制
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory

因为主机上的 yum 原先确认是可用的,但在 OAT上执行添加服务器操作后,yum 变为不可用,猜测是 OAT 导致的 yum 不可用。继续查看任务中的报错内容,发现其中含安装依赖包的完整代码(见文末附录)。

查看代码后发现,以下代码逻辑存在问题:

代码语言:javascript
复制
if [[ "$os_type" =~ ^(centos7_or_uosc|redhat9_or_rocky9|kylin_like)$ ]]; then
    for cmd_pkg in mysql:mariadb python:python ifconfig:net-tools mtr:mtr tar:tar strings:binutils dig:bind-utils :libaio curl:curl :libatomic nc:nc ip:iproute gdb:gdb sar:sysstat perf:perf top:procps-ng asar:antsar
    do
        cmd=$(echo "$cmd_pkg" | cut -d':' -f1)
        pkg=$(echo "$cmd_pkg" | cut -d':' -f2)
        if [[ "$pkg" == "antsar" ]]; then
            if ! rpm --quiet --query antsar; then
                rpm -i /tmp/antsar-2.1.9-20250905115440.alios7.x86_64.rpm.y82oIAzZ.rpm
                tmp_exit_code=$?
                if [[ $tmp_exit_code != 0 ]]; then
                    final_exit_code=$tmp_exit_code
                    install_failed_deps="$install_failed_deps $pkg"
                fi
            fi
        elif [[ "$pkg" =~ ^python ]]; then
            python_version=$(python -V 2>&1 | awk '{print $2}')
            if [[ "$pkg" == "python2" && "$python_version" =~ ^2 ]] || [[ "$pkg" == "python3" && "$python_version" =~ ^3 ]]; then
                continue
            fi
            yum install --nogpgcheck -y $pkg
            tmp_exit_code=$?
            if [[ $tmp_exit_code != 0 ]]; then
                final_exit_code=$tmp_exit_code
                install_failed_deps="$install_failed_deps $pkg"
            else
                python_version=$(python -V 2>&1 | awk '{print $2}')
                if [[ "$pkg" == "python2" ]]; then
                    if ! echo "$python_version"|grep -q "^2"; then
                        alternatives --install /usr/bin/python python /usr/bin/python2 1
                    fi
                else
                    if ! echo "$python_version"|grep -q "^3"; then
                        alternatives --install /usr/bin/python python /usr/bin/python3 1
                    fi
                fi
            fi
......

贴合我的场景做说明:

当前我主机的 python 版本是 2.7.5,cmd 得到的结果是 for 循环中 : 的左边项,pkg 得到的结果是 for 循环中 : 的右边项,python:python 得到的 cmd 的结果是 python,pkg 的结果是 python。

此时 匹配了 elif [[ "pkg" == "python3",所以就会执行 yum install --nogpgcheck -y

本场景安装返回的 tmp_exit_code 是 0,表示安装成功。此时重新获取 python_version="2.7.5",且因为 "$pkg" != "python2",所以执行了命令:

代码语言:javascript
复制
alternatives --install /usr/bin/python python /usr/bin/python3 1

这是将 /usr/bin/python3 指定一个软链接到 /usr/bin/python,而主机上根本不存在 /usr/bin/python3,所以 yum 在使用 /usr/bin/python 时报错:No such file or directory

三、解决方法

先把可用的 python 文件替换 /usr/bin/python,让 yum 可用:

代码语言:javascript
复制
rm -f /usr/bin/python && ln -s  /usr/bin/python2 /usr/bin/python

再通过修改代码/替换文件的方式让子任务执行:

方式 1

修改代码 --> 手动执行代码 --> OAT 上跳过报错的子任务。

修改前:

代码语言:javascript
复制
            if [[ "$pkg" == "python2" && "$python_version" =~ ^2 ]] || [[ "$pkg" == "python3" && "$python_version" =~ ^3 ]]; then
...

修改后(还有一处需要修改,但是本次问题只需要修改此处即可)。

代码语言:javascript
复制
            if [[ "$pkg" == "python" && "$python_version" =~ ^2 ]] || [[ "$pkg" == "python" && "$python_version" =~ ^3 ]]; then
...

方式 2

拷贝 /usr/bin/python2/usr/bin/python3

代码语言:javascript
复制
ln -s  /usr/bin/python2 /usr/bin/python3

附录:OAT 日志中摘取的完整脚本

代码语言:javascript
复制
os_type=centos7_or_uosc
final_exit_code=0
install_failed_deps=""
if [[ "$os_type" =~ ^(centos7_or_uosc|redhat9_or_rocky9|kylin_like)$ ]]; then
    for cmd_pkg in mysql:mariadb python:python ifconfig:net-tools mtr:mtr tar:tar strings:binutils dig:bind-utils :libaio curl:curl :libatomic nc:nc ip:iproute gdb:gdb sar:sysstat perf:perf top:procps-ng asar:antsar
    do
        cmd=$(echo "$cmd_pkg" | cut -d':' -f1)
        pkg=$(echo "$cmd_pkg" | cut -d':' -f2)
        if [[ "$pkg" == "antsar" ]]; then
            if ! rpm --quiet --query antsar; then
                rpm -i /tmp/antsar-2.1.9-20250905115440.alios7.x86_64.rpm.y82oIAzZ.rpm
                tmp_exit_code=$?
                if [[ $tmp_exit_code != 0 ]]; then
                    final_exit_code=$tmp_exit_code
                    install_failed_deps="$install_failed_deps $pkg"
                fi
            fi
        elif [[ "$pkg" =~ ^python ]]; then
            python_version=$(python -V 2>&1 | awk '{print $2}')
            if [[ "$pkg" == "python2" && "$python_version" =~ ^2 ]] || [[ "$pkg" == "python3" && "$python_version" =~ ^3 ]]; then
                continue
            fi
            yum install --nogpgcheck -y $pkg
            tmp_exit_code=$?
            if [[ $tmp_exit_code != 0 ]]; then
                final_exit_code=$tmp_exit_code
                install_failed_deps="$install_failed_deps $pkg"
            else
                python_version=$(python -V 2>&1 | awk '{print $2}')
                if [[ "$pkg" == "python2" ]]; then
                    if ! echo "$python_version"|grep -q "^2"; then
                        alternatives --install /usr/bin/python python /usr/bin/python2 1
                    fi
                else
                    if ! echo "$python_version"|grep -q "^3"; then
                        alternatives --install /usr/bin/python python /usr/bin/python3 1
                    fi
                fi
            fi
        else
            if [[ -n "$cmd" ]] && which "$cmd" >/dev/null 2>&1; then
                continue
            fi
            yum install --nogpgcheck -y $pkg
            tmp_exit_code=$?
            if [[ $tmp_exit_code != 0 ]]; then
                final_exit_code=$tmp_exit_code
                install_failed_deps="$install_failed_deps $pkg"
            fi
        fi
    done
elif [[ "$os_type" == "suse" ]]; then
    for cmd_pkg in mysql:mariadb python:python ifconfig:net-tools mtr:mtr tar:tar strings:binutils dig:bind-utils :libaio curl:curl :libatomic nc:nc ip:iproute gdb:gdb sar:sysstat perf:perf top:procps-ng asar:antsar
    do
        cmd=$(echo "$cmd_pkg" | cut -d':' -f1)
        pkg=$(echo "$cmd_pkg" | cut -d':' -f2)
        if [[ "$pkg" == "antsar" ]]; then
            zypper --no-gpg-checks in -y  /tmp/antsar-2.1.9-20250905115440.alios7.x86_64.rpm.y82oIAzZ.rpm
            tmp_exit_code=$?
            if [[ $tmp_exit_code != 0 ]]; then
                final_exit_code=$tmp_exit_code
                install_failed_deps="$install_failed_deps $pkg"
            fi
        elif [[ "$pkg" == "net-tools" ]]; then
            if [[ -n "$cmd" ]] && which "$cmd" >/dev/null 2>&1; then
                continue
            fi
            zypper in -y net-tools
            tmp_exit_code=$?
            if [[ $tmp_exit_code != 0 ]] || ! which ifconfig &>/dev/null; then
                zypper in -y net-tools-deprecated
                tmp_exit_code=$?
                if [[ $tmp_exit_code != 0 ]]; then
                    final_exit_code=$tmp_exit_code
                    install_failed_deps="$install_failed_deps net-tools-deprecated"
                fi
            fi
        elif [[ "$pkg" =~ ^python ]]; then
            python_version=$(python -V 2>&1 | awk '{print $2}')
            if [[ "$pkg" == "python2" && "$python_version" =~ ^2 ]] || [[ "$pkg" == "python3" && "$python_version" =~ ^3 ]]; then
                continue
            fi
            zypper in -y $pkg
            tmp_exit_code=$?
            if [[ $tmp_exit_code != 0 ]]; then
                final_exit_code=$tmp_exit_code
                install_failed_deps="$install_failed_deps $pkg"
            else
                python_version=$(python -V 2>&1 | awk '{print $2}')
                if [[ "$pkg" == "python2" ]]; then
                    if ! echo "$python_version"|grep -q "^2"; then
                        alternatives --install /usr/bin/python python /usr/bin/python2 1
                    fi
                else
                    if ! echo "$python_version"|grep -q "^3"; then
                        alternatives --install /usr/bin/python python /usr/bin/python3 1
                    fi
                fi
            fi
        else
            if [[ -n "$cmd" ]] && which "$cmd" >/dev/null 2>&1; then
                continue
            fi
            zypper in -y $pkg
            tmp_exit_code=$?
            if [[ $tmp_exit_code != 0 ]]; then
                final_exit_code=$tmp_exit_code
                install_failed_deps="$install_failed_deps $pkg"
            fi
        fi
    done
elif [[ "$os_type" == "debian" ]]; then
    for cmd_pkg in mysql:mariadb python:python ifconfig:net-tools mtr:mtr tar:tar strings:binutils dig:bind-utils :libaio curl:curl :libatomic nc:nc ip:iproute gdb:gdb sar:sysstat perf:perf top:procps-ng asar:antsar
    do
        cmd=$(echo "$cmd_pkg" | cut -d':' -f1)
        pkg=$(echo "$cmd_pkg" | cut -d':' -f2)
        if [[ "$pkg" == "antsar" ]]; then
            alien -i /tmp/antsar-2.1.9-20250905115440.alios7.x86_64.rpm.y82oIAzZ.rpm
            which asar >/dev/null 2>&1 || rpm -ivh /tmp/antsar-2.1.9-20250905115440.alios7.x86_64.rpm.y82oIAzZ.rpm --nodeps
            tmp_exit_code=$?
            if [[ $tmp_exit_code != 0 ]]; then
                final_exit_code=$tmp_exit_code
                install_failed_deps="$install_failed_deps $pkg"
            fi
        elif [[ "$pkg" == "libaio1" ]]; then
            apt-get --allow-unauthenticated -y install $pkg
            tmp_exit_code=$?
            if [[ $tmp_exit_code != 0 ]]; then
                apt-get --allow-unauthenticated -y install libaio1t64
                tmp_exit_code=$?
                if [[ $tmp_exit_code != 0 ]]; then
                    final_exit_code=$tmp_exit_code
                    install_failed_deps="$install_failed_deps $pkg"
                fi
            fi
        elif [[ "$pkg" =~ ^python ]]; then
            python_version=$(python -V 2>&1 | awk '{print $2}')
            if [[ "$pkg" == "python2" && "$python_version" =~ ^2 ]] || [[ "$pkg" == "python3" && "$python_version" =~ ^3 ]]; then
                continue
            fi
            apt-get --allow-unauthenticated -y install $pkg
            tmp_exit_code=$?
            if [[ $tmp_exit_code != 0 ]]; then
                final_exit_code=$tmp_exit_code
                install_failed_deps="$install_failed_deps $pkg"
            else
                python_version=$(python -V 2>&1 | awk '{print $2}')
                if [[ "$pkg" == "python2" ]]; then
                    if ! echo "$python_version"|grep -q "^2"; then
                        update-alternatives --install /usr/bin/python python /usr/bin/python2 1
                    fi
                else
                    if ! echo "$python_version"|grep -q "^3"; then
                        update-alternatives --install /usr/bin/python python /usr/bin/python3 1
                    fi
                fi
            fi
        else
            if [[ -n "$cmd" ]] && which "$cmd" >/dev/null 2>&1; then
                continue
            fi
            apt-get --allow-unauthenticated -y install $pkg
            tmp_exit_code=$?
            if [[ $tmp_exit_code != 0 ]]; then
                final_exit_code=$tmp_exit_code
                install_failed_deps="$install_failed_deps $pkg"
            fi
        fi
    done
else
    echo "can not get the linux distribution info, need to install package manually. tips: you can skip this step, then install the packages if the later precheck step suggest"
    exit 1
fi

if [[ $final_exit_code != 0 ]]; then
    echo "Install deps${install_failed_deps} failed. If you are sure that the dependencies that failed to install are not needed, you can ignore them by specifying the system parameter oat.server.ignore_deps" >&2
fi
exit $final_exit_code

本文关键字:#OceanBase #OAT


本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2026-01-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 爱可生开源社区 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、故障描述
    • OAT 版本
    • 操作
    • 任务报错内容
  • 二、报错分析
  • 三、解决方法
  • 附录:OAT 日志中摘取的完整脚本
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档