作者:姚嵩,外星人,舍利小王子。
爱可生开源社区出品,原创内容未经授权不得随意使用,转载请联系小编并注明来源。
本文约 1700 字,预计阅读需要 5 分钟。
使用 OAT 添加服务器时,导致 yum 不可用。
版本号:4.4.0
[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 安装依赖包时,报错:
- bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory
于是登陆要添加的服务器主机,手动执行命令 yum provides '*/pvcreate' 确认待添加的主机 yum 是否能正常执行,结果是执行报错,手动执行的报错和任务报错内容一致:
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory
因为主机上的 yum 原先确认是可用的,但在 OAT上执行添加服务器操作后,yum 变为不可用,猜测是 OAT 导致的 yum 不可用。继续查看任务中的报错内容,发现其中含安装依赖包的完整代码(见文末附录)。
查看代码后发现,以下代码逻辑存在问题:
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",所以执行了命令:
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 可用:
rm -f /usr/bin/python && ln -s /usr/bin/python2 /usr/bin/python
再通过修改代码/替换文件的方式让子任务执行:
方式 1
修改代码 --> 手动执行代码 --> OAT 上跳过报错的子任务。
修改前:
if [[ "$pkg" == "python2" && "$python_version" =~ ^2 ]] || [[ "$pkg" == "python3" && "$python_version" =~ ^3 ]]; then
...
修改后(还有一处需要修改,但是本次问题只需要修改此处即可)。
if [[ "$pkg" == "python" && "$python_version" =~ ^2 ]] || [[ "$pkg" == "python" && "$python_version" =~ ^3 ]]; then
...
方式 2
拷贝 /usr/bin/python2 到 /usr/bin/python3。
ln -s /usr/bin/python2 /usr/bin/python3
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