在GBase 8a的centos 8版本安装时,偶发卡住,查看后发现是一个简单的ssh命令没有返回,经排查发现,在centos 8里,其自带了几个yum源,导致运行某些不存在的命令时,会【推荐】安装rpm包,导致卡住。
目录导航
表现
GBase 8a安装时卡住
*********************************************************************************
Do you accept the above licence agreement ([Y,y]/[N,n])? y
*********************************************************************************
                     Welcome to install GBase products
*********************************************************************************
Environmental Checking on gcluster nodes.
查看代码,在ssh远程执行如下代码时
"export LANG=C; ret=`lssubsys -a`; echo $?
分析
手工执行不存在的命令出现推荐安装rpm
发现如下的输出
[root@redhat8_3 ~]# lssubsys -a
bash: lssubsys: command not found...
Install package 'libcgroup-tools' to provide command 'lssubsys'? [N/y]
除了打印出command not found之外,还额外出现了推荐安装rpm包的选择[Y/N],正是这个交互式输入,导致远程命令无法继续,从而卡住。
排查推荐的原因
经分析,在linux里对command not found的处理,有一个工具PackageKit.sh, 处理了command_not_found_handle
[root@redhat8_3 profile.d]# cat /etc/profile.d/PackageKit.sh
# Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
#
# Licensed under the GNU General Public License Version 2
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
command_not_found_handle () {
        local runcnf=1
        local retval=127
        # only search for the command if we're interactive
        [[ $- == *"i"* ]] || runcnf=0
        # don't run if DBus isn't running
        [[ ! -S /run/dbus/system_bus_socket ]] && runcnf=0
        # don't run if packagekitd doesn't exist in the _system_ root
        [[ ! -x '/usr/libexec/packagekitd' ]] && runcnf=0
        # don't run if bash command completion is being run
        [[ -n ${COMP_CWORD-} ]] && runcnf=0
        # don't run if we've been uninstalled since the shell was launched
        [[ ! -x '/usr/libexec/pk-command-not-found' ]] && runcnf=0
        # run the command, or just print a warning
        if [ $runcnf -eq 1 ]; then
                '/usr/libexec/pk-command-not-found' "$@"
                retval=$?
        elif [[ -n "${BASH_VERSION-}" ]]; then
                printf >&2 'bash: %scommand not found\n' "${1:+$1: }"
        fi
        # return success or failure
        return $retval
}
if [[ -n "${ZSH_VERSION-}" ]]; then
        command_not_found_handler () {
                command_not_found_handle "$@" && return 127
        }
fi
内部会调用command_not_found_handle命令,该命令对应的程序是 /usr/libexec/pk-command-not-found,查看进程,发现了lssubsys的命令
[root@redhat8_3 ~]# ps -ef | grep lssub
root       56417   56416  0 Jan20 pts/7    00:00:00 /usr/libexec/pk-command-not-found lssubsys -a
root       60747   21328  0 00:00 pts/6    00:00:00 grep --color=auto lssub
排查推荐的安装包来自哪里
查看yum数据源,发现有enable的
[root@redhat8_3 profile.d]# yum repolist all
repo id                                  repo name                                                                        status
appstream                                CentOS Linux 8 - AppStream                                                       enabled
appstream-source                         CentOS Linux 8 - AppStream - Source                                              disabled
baseos                                   CentOS Linux 8 - BaseOS                                                          enabled
baseos-source                            CentOS Linux 8 - BaseOS - Source                                                 disabled
cr                                       CentOS Linux 8 - ContinuousRelease                                               disabled
debuginfo                                CentOS Linux 8 - Debuginfo                                                       disabled
devel                                    CentOS Linux 8 - Devel WARNING! FOR BUILDROOT USE ONLY!                          disabled
extras                                   CentOS Linux 8 - Extras                                                          enabled
extras-source                            CentOS Linux 8 - Extras - Source                                                 disabled
fasttrack                                CentOS Linux 8 - FastTrack                                                       disabled
ha                                       CentOS Linux 8 - HighAvailability                                                disabled
media-appstream                          CentOS Linux 8 - Media - AppStream                                               disabled
media-baseos                             CentOS Linux 8 - Media - BaseOS                                                  disabled
plus                                     CentOS Linux 8 - Plus                                                            disabled
plus-source                              CentOS Linux 8 - Plus - Source                                                   disabled
powertools                               CentOS Linux 8 - PowerTools                                                      disabled
[root@redhat8_3 profile.d]#
这些数据源配置在/etc/yum.repos.d/下面
[root@redhat8_3 profile.d]# cd /etc/yum.repos.d/
[root@redhat8_3 yum.repos.d]# ll
total 48
-rw-r--r--. 1 root root  719 Nov  9  2020 CentOS-Linux-AppStream.repo
-rw-r--r--. 1 root root  704 Nov  9  2020 CentOS-Linux-BaseOS.repo
-rw-r--r--. 1 root root 1130 Nov  9  2020 CentOS-Linux-ContinuousRelease.repo
-rw-r--r--. 1 root root  318 Nov  9  2020 CentOS-Linux-Debuginfo.repo
-rw-r--r--. 1 root root  732 Nov  9  2020 CentOS-Linux-Devel.repo
-rw-r--r--. 1 root root  704 Nov  9  2020 CentOS-Linux-Extras.repo
-rw-r--r--. 1 root root  719 Nov  9  2020 CentOS-Linux-FastTrack.repo
-rw-r--r--. 1 root root  740 Nov  9  2020 CentOS-Linux-HighAvailability.repo
-rw-r--r--. 1 root root  693 Nov  9  2020 CentOS-Linux-Media.repo
-rw-r--r--. 1 root root  706 Nov  9  2020 CentOS-Linux-Plus.repo
-rw-r--r--. 1 root root  724 Nov  9  2020 CentOS-Linux-PowerTools.repo
-rw-r--r--. 1 root root  898 Nov  9  2020 CentOS-Linux-Sources.repo
关闭yum数据源
修改对应的配置文件,将其中的enable=1改成enable=0
[root@redhat8_3 yum.repos.d]# cat CentOS-Linux-AppStream.repo
# CentOS-Linux-AppStream.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client.  You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
[appstream]
name=CentOS Linux $releasever - AppStream
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[root@redhat8_3 yum.repos.d]# vi CentOS-Linux-AppStream.repo
[root@redhat8_3 yum.repos.d]# cat CentOS-Linux-AppStream.repo
# CentOS-Linux-AppStream.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client.  You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
[appstream]
name=CentOS Linux $releasever - AppStream
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[root@redhat8_3 yum.repos.d]#
其它几个都关掉,我本地测试只关掉了前2个,那个extra我没关。
[root@redhat8_3 yum.repos.d]# yum repolist all
repo id                                  repo name                                                                        status
appstream                                CentOS Linux 8 - AppStream                                                       disabled
appstream-source                         CentOS Linux 8 - AppStream - Source                                              disabled
baseos                                   CentOS Linux 8 - BaseOS                                                          disabled
baseos-source                            CentOS Linux 8 - BaseOS - Source                                                 disabled
cr                                       CentOS Linux 8 - ContinuousRelease                                               disabled
debuginfo                                CentOS Linux 8 - Debuginfo                                                       disabled
devel                                    CentOS Linux 8 - Devel WARNING! FOR BUILDROOT USE ONLY!                          disabled
extras                                   CentOS Linux 8 - Extras                                                          enabled
extras-source                            CentOS Linux 8 - Extras - Source                                                 disabled
fasttrack                                CentOS Linux 8 - FastTrack                                                       disabled
ha                                       CentOS Linux 8 - HighAvailability                                                disabled
media-appstream                          CentOS Linux 8 - Media - AppStream                                               disabled
media-baseos                             CentOS Linux 8 - Media - BaseOS                                                  disabled
plus                                     CentOS Linux 8 - Plus                                                            disabled
plus-source                              CentOS Linux 8 - Plus - Source                                                   disabled
powertools                               CentOS Linux 8 - PowerTools                                                      disabled
[root@redhat8_3 yum.repos.d]#
验证命令是否不再出现推荐安装
再次运行,发现只报错command no found,不再出现推荐安装的选项了。
[root@redhat8_3 ~]# lssubsys -a
bash: lssubsys: command not found...
[root@redhat8_3 ~]#
尝试安装集群
正常安装,没有卡住。
*********************************************************************************
Do you accept the above licence agreement ([Y,y]/[N,n])? y
*********************************************************************************
                     Welcome to install GBase products
*********************************************************************************
Environmental Checking on gcluster nodes.
Cgconfig service is not exist on host ['10.0.2.181'], resource manangement can not be used, continue ([Y,y]/[N,n])? n
总结
linux的PackageKit工具,对不存在的命令进行了人性化推荐,导致远程运行不存在的命令时出现了推荐安装的选项,而调用方并没有处理这种情况,导致一直带等待客户输入,从而卡住。
解决方案
- 等待新版本
 - 暂时关闭yum数据源(临时措施)
 - 手工安装上依赖的命令包(临时措施)