如何在OpenShift v4 CoreOS节点上运行telnet / tcpdump
。
您可以通过以下链接以PDF格式下载本文来支持我们。
以PDF格式下载指南
关
。
。
。
自OpenShift 4发行以来,推荐并支持在所有OpenShift Container Platform计算机上运行的Red Hat Enterprise Linux CoreOS(RHCOS)操作系统。 RHCOS将红帽企业Linux(RHEL)的质量标准与Container Linux的自动远程升级功能结合在一起。
RHCOS没有随附的软件包管理器,例如yum和dnf。该操作系统是 rpm-ostree
一个系统,其中更新是通过容器映像传递的,并且是OpenShift容器平台更新过程的一部分。
如果不支持直接下载和安装OS Package Manager和RPM软件包,则运行未随OS预先打包的工具的唯一方法是使用容器。对于CoreOS 工具箱 您可以启动一个容器以引入您喜欢的调试和管理工具。
在OpenShift 4 RHC OS计算机上运行工具箱容器
工具箱容器 工具箱 提供了一个脚本。但是,从您首先在容器中运行管理工具的位置访问OpenShift节点。
可以使用 OC 调试 命令或SSH。
--- Access node with SSH ---
$ ssh [email protected]
--- Access node with oc debug command ---
$ oc debug node/
使用oc调试示例进行访问。
$ oc debug node/node01.ocp.computingforgeeks.com
Starting pod/node01ocpcomputingforgeekscom-debug ...
To use host binaries, run `chroot /host`
提示节点的根文件系统 /主机 使用文件夹可以检查节点中的文件。
您需要在/ host文件夹中启动chroot shell,如命令输出所示。这将允许外壳程序使用主机二进制文件。
chroot /host
您应该看到类似于以下内容的输出:
chroot /host
Pod IP: 10.10.30.235
If you don't see a command prompt, try pressing enter.
sh-4.2# chroot /host
sh-4.4#
要启动工具箱容器,请使用以下命令:
$ /usr/bin/toolbox
第一次运行脚本时,工具箱容器映像将下载到该节点。
Trying to pull registry.redhat.io/rhel8/support-tools...
Getting image source signatures
Copying blob ec1681b6a383 done
Copying blob c4d668e229cd done
Copying blob 6b1688d3542f done
Copying config 50b63c2aff done
Writing manifest to image destination
Storing signatures
50b63c2aff8c13f9f8594c9eaf5fc961f39c74df6d9c6ddde8ca705f78f3c14d
接下来,用Podman旋转容器。
Spawning a container 'toolbox-core' with image 'registry.redhat.io/rhel8/support-tools'
Detected RUN label in the container image. Using that as the default...
command: podman run -it --name toolbox-core --privileged --ipc=host --net=host --pid=host -e HOST=/host -e NAME=toolbox-core -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
在OpenShift v4 CoreOS服务器上运行telnet / tcpdump
一旦进入容器外壳,就可以使用yum Package Manager安装所需的调试和管理工具。
--- Install network tools ---
# yum -y install iproute net-tools
--- Install telnet ---
# yum -y install telnet
--- Install tcpdump ---
# yum -y install tcpdump
--- Install any other tool ---
# yum -y install
使用Telnet:
# telnet
使用tcpdump:
标识接口名称–必须安装网络工具。
# ip link show | head
1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens3: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 00:1a:4a:16:01:73 brd ff:ff:ff:ff:ff:ff
7: ovs-system: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 4e:66:b9:32:0d:26 brd ff:ff:ff:ff:ff:ff
8: br0: mtu 1450 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 72:d6:df:e8:13:48 brd ff:ff:ff:ff:ff:ff
9: vxlan_sys_4789: mtu 65000 qdisc noqueue master ovs-system state UNKNOWN mode DEFAULT group default qlen 1000
link/ether 4a:c4:7f:c1:85:f7 brd ff:ff:ff:ff:ff:ff
使用tcpdump。
# tcpdump
本示例用于从发往端口的接口捕获数据包。 443..将输出保存到Node文件系统的路径。 /主机 目录。
# tcpdump -i any port 443 -s 0 -vv -s 0 -w /host/tmp/testpacketname.pcap
可以交换 任何 具有接口名称,例如
-i ens3
按Control-C结束捕获。
从容器执行tcpdump捕获
在运行目标Pod的节点上打开调试Shell或SSH。
$ oc debug node/
--- OR ---
$ ssh [email protected]
使用crictl ps命令确定目标容器的进程ID。
# crictl ps
我的容器ID是 51a17d9a4b376..让我们将其另存为变量。
container_id="51a17d9a4b376"
获取容器的PID。
container_pid=$(crictl inspect --output yaml $container_id | grep 'pid:' | awk '{print $2}')
检查值:
# echo $container_pid
1124033
# ps 1124033
PID TTY STAT TIME COMMAND
1124033 ? Ss 0:00 /bin/sleep 3650d
您可以使用以下命令在容器的网络名称空间中启动tcpdump:
# nsenter -n -t $container_pid -- tcpdump
--- Example ---
# tcpdump -i any port 443 -s 0 -vv -s 0 -w /host/tmp/testpacketname.pcap
请注意,在运行命令之前,必须将tcpdump安装在容器中。
有关OpenShift的其他文章。
如何在OpenShift群集上安装ArgoCD
如何在OpenShift 4.x上安装Istio Service Mesh
使用Kubernetes / OpenShift运行Rook的Ceph工具箱
。
您可以通过以下链接以PDF格式下载本文来支持我们。
以PDF格式下载指南
关
。
。
。