Linux命令学习

0001【查看网卡所在的PCIe插槽宽度】

在某些场景下需要确认网关所在的PCIe插槽,保证设备的数据交互带宽,特别是高吞吐,高性能等应用场景。

[root@inst92 ~]# ifconfig
enp175s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.31.132.46  netmask 255.255.255.0  broadcast 172.31.132.255
        inet6 fe80::b696:91ff:fe88:ff6a  prefixlen 64  scopeid 0x20<link>
        ether b4:96:91:88:ff:6a  txqueuelen 1000  (Ethernet)
        RX packets 3226767  bytes 1364224393 (1.2 GiB)
        RX errors 0  dropped 537495  overruns 0  frame 0
        TX packets 1821485  bytes 589819632 (562.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xee400000-ee4fffff

enp175s0f1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b4:96:91:88:ff:6b  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xee300000-ee3fffff


[root@inst92 ~]# lspci -D | grep Eth | awk -F ' ' '{print $1}' | head -n 1 | xargs lspci -vv -s | grep LnkSta
                LnkSta: Speed 5GT/s, Width x4, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
                LnkSta2: Current De-emphasis Level: -3.5dB, EqualizationComplete-, EqualizationPhase1-

0002【echo相关命令】

(1)echo不换行

# echo -n "" > ./test.txt    清空文件不产生空行

(2)echo相同内容到多个文件中

# echo "Hello world" | tee -a 1.log 2.log 3.log    -a追加模式,不要-a是覆盖模式

0003【在线关闭CPU核】

在某些场景下需要减少CPU核数,可以通过该方式进行操作,不需要重启服务器即可生效;当然有些BIOS也是提供对CPU核开关的配置。BIOS的优点是永久生效,缺点是要重启硬件才能生效,Linux系统下操作是及时生效,重启则失效,很便捷。

查看当前CPU核的状态,命令如下:

[root@inst92 tools]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                52
On-line CPU(s) list:   0-51      当前在线的CPU核是0~51
Thread(s) per core:    1
Core(s) per socket:    26
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 85
Model name:            Intel(R) Xeon(R) Gold 6230R CPU @ 2.10GHz
Stepping:              7
CPU MHz:               2100.000
BogoMIPS:              4200.00
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              1024K
L3 cache:              36608K
NUMA node0 CPU(s):     0-25
NUMA node1 CPU(s):     26-51
 

假设我们要关闭10号CPU核,命令如下:

[root@inst92 tools]# echo 0 > /sys/devices/system/cpu/cpu10/online

查看执行效果:

[root@inst92 tools]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                52
On-line CPU(s) list:   0-9,11-51    10号核已经不是online状态了;
Off-line CPU(s) list:  10                 10号核是offline状态
Thread(s) per core:    1
Core(s) per socket:    25
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 85
Model name:            Intel(R) Xeon(R) Gold 6230R CPU @ 2.10GHz
Stepping:              7
CPU MHz:               2100.000
BogoMIPS:              4200.00
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              1024K
L3 cache:              36608K
NUMA node0 CPU(s):     0-9,11-25
NUMA node1 CPU(s):     26-51
 

恢复命令如下:

[root@inst92 tools]# echo 1 > /sys/devices/system/cpu/cpu10/online

0004【如何定位物理网口与Linux中网卡的对应关系】

在某些情况下我们需要远程告诉机房布线的同学插拔哪个网口上的线,此时我们可以通过命令点亮网口的指示灯闪烁让接线同学看到,命令参考如下:

[root@inst92 tools]# ifconfig
enp175s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.31.132.46  netmask 255.255.255.0  broadcast 172.31.132.255
        inet6 fe80::b696:91ff:fe88:ff6a  prefixlen 64  scopeid 0x20<link>
        ether b4:96:91:88:ff:6a  txqueuelen 1000  (Ethernet)
        RX packets 4111018  bytes 1934521918 (1.8 GiB)
        RX errors 0  dropped 559687  overruns 0  frame 0
        TX packets 2049442  bytes 605027614 (576.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xee400000-ee4fffff


[root@inst92 tools]# ethtool -p enp175s0f0       此时网口的状态灯会闪烁,正常情况下常亮

CTRL+c中断命令,网卡灯停止闪烁

 

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值