当服务器未安装 netstat 工具时,查看端口监听状态会提示如下报错 “command not found”。
1 2 | [root@VM_0_15_linux ~] # netstat -an|grep 9200 - bash : netstat : command not found |
如果要使用 netstat 命令,需要先安装工具,安装步骤如下所示。
一、首先配置好本机的 yum 源
1 2 3 4 5 6 7 8 9 | [root@VM_0_15_linux ~] # yum repolist all Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile repo id repo name status base /1 .1 /x86_64 UPEL-1.1 - Base enabled: 7,695 !extras /1 .1 /x86_64 UPEL-1.1 - Extras disabled updates /1 .1 /x86_64 UPEL-1.1 - Updates enabled: 208 upel-media UPEL-1.1 - Media disabled repolist: 7,903 |
二、查看提供命令的工具包
执行如下命令 yum provides */netstat
可以看到提供命令的工具包:
net-tools-2.0-0.22.20131004git.el7.x86_64。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@VM_0_15_linux ~] # yum provides */netstat Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile updates /1 .1 /x86_64/filelists_db | 1.1 MB 00:00:00 ctdb-tests-4.7.1-9.el7_5.x86_64 : CTDB clustered database test suite Repo : base Matched from: Filename : /usr/share/ctdb/tests/eventscripts/stubs/netstat net-tools-2.0-0.22.20131004git.el7.x86_64 : Basic networking tools Repo : base Matched from: Filename : /bin/netstat |
三、安装工具包
执行 yum install net-tools
安装命令。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | [root@VM_0_15_linux ~] # yum install net-tools Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package net-tools.x86_64 0:2.0-0.22.20131004git.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================================= Installing: net-tools x86_64 2.0-0.22.20131004git.el7 base 305 k Transaction Summary ======================================================================================================================================================================= Install 1 Package Total download size: 305 k Installed size: 917 k Is this ok [y /d/N ]: y Downloading packages: net-tools-2.0-0.22.20131004git.el7.x86_64.rpm | 305 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : net-tools-2.0-0.22.20131004git.el7.x86_64 1 /1 [upel]: net-tools signature check ok. [upel]: net-tools signature check ok. [upel]: net-tools signature check ok. Verifying : net-tools-2.0-0.22.20131004git.el7.x86_64 1 /1 Installed: net-tools.x86_64 0:2.0-0.22.20131004git.el7 Complete! |
四、验证测试
利用本地监听的端口 9200 验证工具安装是否正常。
可以正常使用命令,说明安装正常。
1 2 | [root@VM_0_15_linux ~] # netstat -an|grep 9200 tcp6 0 0 :::9200 :::* LISTEN |
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持IT俱乐部。