如何通过 SSH 到相关节点以在 Red Hat Enterprise Linux CoreOS 4.x 中生成 sosreport?
Environment
- Red Hat OpenShift Container Platform (RHOCP, OCP)
- 4.x
- Red Hat Enterprise Linux CoreOS (RHCOS)
Issue
* 如何在 Red Hat Enterprise Linux CoreOS 4.x 中生成 sos report?
* 如何为 Red Hat OpenShift 4.x 节点生成 sos report?
* 使用 rhel7/support-tools 镜像生成 sos report 会失败,并显示回溯信息。
[root@ip-1-1-1-1 ~]# podman run -it registry.access.redhat.com/rhel7/support-tools /usr/bin/bash
bash-4.2# sosreport
Traceback (most recent call last):
File "/usr/sbin/sosreport", line 19, in <module>
main(sys.argv[1:])
File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 1498, in main
sos = SoSReport(args)
File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 360, in __init__
self.policy = sos.policies.load(sysroot=self.opts.sysroot)
File "/usr/lib/python2.7/site-packages/sos/policies/__init__.py", line 44, in load
cache['policy'] = policy(sysroot=sysroot)
File "/usr/lib/python2.7/site-packages/sos/policies/redhat.py", line 258, in __init__
super(RHELPolicy, self).__init__(sysroot=sysroot)
File "/usr/lib/python2.7/site-packages/sos/policies/redhat.py", line 58, in __init__
sysroot = self._container_init()
File "/usr/lib/python2.7/site-packages/sos/policies/redhat.py", line 153, in _container_init
host_tmp_dir = os.path.abspath(self._host_sysroot + self._tmp_dir)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
Resolution
重要备注:按照设计,OpenShift 4.x 集群本身是不可变的,它依赖于 Operator 来应用集群更改。这代表,不建议通过 SSH 直接访问底层节点。如果直接进行了访问,节点还会被标记为 accessed 污点。
因此,在可能的情况下,在oc命令行中直接创建一个 debug pod 来生成 sosreport,而不是使用 SSH 来生成 sosreport。如需更多信息,请参阅如何在没有 SSH 的情况下,在 OpenShift4 节点中生成 sosreport。
只有在无法实现在没有 SSH 的情况下生成 sosreport 时, 才使用 SSH 直接连接到要生成 sosreport 的 OpenShift Container Platform 4.x 节点来生成 sosreport。在 SSH 到节点后,变为 root 并运行 toolbox 命令:
$ ssh core@NODE # ssh with core user using ssh key specified in install-config.yaml
[core@node ~]$ sudo -i
[root@node ~]# toolbox
Spawning a container 'toolbox-root' with image 'registry.redhat.io/rhel8/support-tools'
Detected RUN label in the container image. Using that as the default...
Command: /proc/self/exe run -it --name toolbox-root --privileged --ipc=host --net=host --pid=host -e HOST=/host -e NAME=toolbox-root -e IMAGE=registry.redhat.io/rhel8/support-tools:latest -v /run:/run -v /var/log:/var/log -v /etc/machine-id:/etc/machine-id -v /etc/localtime:/etc/localtime -v /:/host registry.redhat.io/rhel8/support-tools:latest
注: 在断开连接的环境中,需要对
registry.redhat.io/rhel8/support-tools在本地进行镜像。如果镜像可用,在运行toolbox前,在节点中创建一个/root/.toolboxrc文件,如下所示:
$ vi /root/.toolboxrc
REGISTRY=private-registry.example.com:5000
IMAGE=rhel8/support-tools
CLI 现在附加到容器中的一个新的 bash 会话中,并可执行 sos report :
[root@node ~]# sos report -k crio.all=on -k crio.logs=on -k podman.all=on -k podman.logs=on
这将在容器的 /host/var/tmp 目录中生成 sos 报告,该报告被映射到主机的 /var/tmp/ 中。
创建 sos 报告后,运行 exit 退出容器:
[root@node ~]# exit
[root@node ~]#
Root Cause
toolbox 命令运行 podman container runlabel run registry.redhat.io/rhel8/support-tools,这是 RHEL Atomic Host 中 atomic run registry.redhat.io/rhel7/support-tools 的替换。
Diagnostic Steps
如果 toolbox 没有按预期启动 debug 容器,请检查用户创建的 $HOME/.toolboxrc 文件,该文件可以覆盖 REGISTRY、IMAGE 或 TOOLBOX_NAME 选项的默认值。
在断开连接的环境中,需要创建该文件以引用已保存在本地环境中的镜像。
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.