VMware vSphere 6.7中,允许登录 SSH登录ESXi主机后,我试着运行了一下esxtop,没有看到类似Linux top相似的结果,却看到满屏幕的乱码。如下:
no termcap entry for a `xterm-256color' terminal"(PDH-CSV 4.0) (UTC)(0)",
"\\172.localdomain\Memory\Memory Overcommit (1 Minute Avg)",
"\\172.localdomain\Memory\Memory Overcommit (5 Minute Avg)",
"\\172.localdomain\Memory\Memory Overcommit (15 Minute Avg)",
"\\172.localdomain\Physical Cpu Load\Cpu Load (1 Minute Avg)",
"\\172.localdomain\Physical Cpu Load\Cpu Load (5 Minute Avg)",
"\\172.localdomain\Physical Cpu Load\Cpu Load (15 Minute Avg)",
"\\172.localdomain\Physical Cpu(0)\% Processor Time",
"\\172.localdomain\Physical Cpu(1)\% Processor Time",
"\\172.localdomain\Physical Cpu(_Total)\% Processor Time",
"\\172.localdomain\Physical Cpu(0)\% Util Time",
"\\172.localdomain\Physical Cpu(1)\% Util Time",
"\\172.localdomain\Physical Cpu(_Total)\% Util Time",
"\\172.localdomain\Memory\Machine MBytes","
\\172.localdomain\Memory\Kernel MBytes",
"\\172.localdomain\Memory\NonKernel MBytes",
"\\172.localdomain\Memory\Free MBytes",
"\\172.localdomain\Memory\Kernel Managed MBytes",
"\\172.localdomain\Memory\Kernel MinFree MBytes",
"\\172.localdomain\Memory\Kernel Reserved MBytes",
"\\172.localdomain\Memory\Kernel Unreserved MBytes",
"\\172.localdomain\Memory\Kernel State",
"\\172.localdomain\Memory\PShare Shared MBytes",
"\\172.localdomain\Memory\PShare Common MBytes",
"\\172.localdomain\Memory\PShare Savings MBytes",
"\\172.localdomain\Memory\Swap Used MBytes",
"\\172.localdomain\Memory\Swap Target MBytes",
"\\172.localdomain\Memory\Swap MBytes Read/sec",
"\\172.localdomain\Memory\Swap MBytes Write/sec",
"\\172.localdomain\Memory\Total Compressed MBytes",
"\\172.localdomain\Memory\Total Saved By Compression MBytes",
"\\172.localdomain\Memory\Memctl Current MBytes",
"\\172.localdomain\Memory\Memctl Target MBytes",
"\\172.localdomain\Memory\Memctl Max MBytes",
"\\172.localdomain\Power\Power Usage Now Watts",
"\\172.localdomain\Power\Power Usage Cap Watts",
"\\172.localdomain\VSAN\Enabled?",
"\\172.localdomain\Group Cpu(1:system)\Members",
"\\172.localdomain\Group Cpu(1:system)\% Used",
"\\172.localdomain\Group Cpu(1:system)\% Run",
"\\172.localdomain\Group Cpu(1:system)\% System",
"\\172.localdomain\Group Cpu(1:system)\% Wait",
"\\172.localdomain\Group Cpu(1:system)\% Ready",
"\\172.localdomain\Group Cpu(1:system)\% Idle",
"\\172.localdomain\Group Cpu(1:system)\% Overlap",
"\\172.localdomain\Group Cpu(1:system)\% CoStop",
"\\172.localdomain\Group Cpu(1:system)\% Max Limited",
"\\172.localdomain\Group Cpu(1:system)\% Swap Wait",
"\\172.localdomain\Vcpu(1:system:2097153:idle1)\% Used",
"\\172.localdomain\Vcpu(1:system:2097153:idle1)\% Run",
"\\172.localdomain\Vcpu(1:system:2097153:idle1)\% System",
"\\172.localdomain\Vcpu(1:system:2097153:idle1)\% Wait",
"\\172.localdomain\Vcpu(1:system:2097153:idle1)\% VmWait",
"\\172.localdomain\Vcpu(1:system:2097153:idle1)\% Ready",
"\\172.localdomain\Vcpu(1:system:2097153:idle1)\% Idle",
本来vSphere还得依靠它来查看系统信息呢,esxtop却乱成一团,这可如何是好?去网上搜一搜,居然也有人经历过相同的遭遇,VMware官网上有解决方法,如下:
第1步 查看终端变量的设置
[root@172:~] echo $TERM
xterm-256color
第1行中的no termcap entry for a `xterm-256color' terminal就是告诉我们:对于xterm-256color这种控制终端,在本机的数据库里没有找到,所以就显示不出来正确的格式。既然不支持,就找一个能支持的终端吧。
第2步 查找ESXi主机支持的格式
[root@172:~] find /usr/share/terminfo/ -type f
/usr/share/terminfo/v/vt102
/usr/share/terminfo/x/xterm
/usr/share/terminfo/s/screen
/usr/share/terminfo/l/linux
/usr/share/terminfo/a/ansi
看吧,terminfo数据里能被ESXi主机支持的控制终端有5个,随便选一个来试试。
第3步 设置终端格式
# TERM=XTERM esxtop
设为第2种xterm。马上就好了!另外几种,也都可以。问题暂时解决了。要是下一次登录,又不能显示,怎么办?
那就在/etc/bashrc里添加这个TERM变量。不行,没有这个文件。/etc/profile倒是有,不过是只读的,root也没有权限修改。倒是有个/etc/profile.local的权限是1644,root是用户,可以修改。打开来看,里面有一句说:
This file is not used when UEFI secure boot is enabled.
意思是说,要是使用UEFI安全启动,这个文件就废了。不管那么多了,修改一下,在里面添加这么两句:
TERM=xterm
export $TERM
然后,再引用一下这个文件。
# source /etc/profile.local
测试一下。先把TERM设为别的变量。
# TERM=test
# source /etc/profile.local
# echo $TERM
显示的是xterm。下次vSphere重新启动的时候,会读这个文件吗?我还没有试过。
参考资料:https://kb.vmware.com/s/article/2001448