Category: linux

  • 如何用iftop查看某一个进程的tcp流量

    背景

    写的存储系统平常是3个节点部署。 每个节点都会部署volume-node, meta-node, storage-node三个服务。

    volume-node 和meta-node 服务都会和storage-node 建立多个tcp连接, 并且往2222端口写数据。

    现在希望观察storage-node 上2222端口来自于meta node 服务的流量情况。

    实现

    ps -ef |grep meta
    
    ### 获取过滤的端口。
    netstat -anp \
    |grep (meta_node_pid) |grep :2222 \
    |awk '{print $4}'|awk -F ':' '{print $2}' \
    |xargs -i echo "src port {} or" \
    |tr '\n' ' '
    

    示例iftop 过滤流量

    [root@node3 ~]# netstat -anp |grep 2222|grep $(cat /var/run/octopus/meta-node.pid ) |awk '{print $4}'|awk -F ':' '{print $2}' |xargs -i echo "src port {} or" |tr '\n' ' '
    src port 40696 or src port 36020 or src port 36026 or src port 36030 or src port 36022 or src port 41066 or src port 41064 or src port 36034 or src port 36028 or src port 41062 or src port 41070 or src port 41058 or src port 40692 or src port 36032 or src port 41068 or src port 40694 or src port 40698 or src port 36024 or src port 40706 or src port 41056 or src port 40690 or src port 41060 or src port 40688 or src port 40700 or [root@node3 ~]#
    
    #得到过滤的src 端口。去掉最后一个'or', 然后使用iftop -f 过滤流量。
    iftop -i enp101s0f0 -P -B -N \
     -f "src port 40696 or src port 36020 or src port 36026 or src port 36030 or src port 36022 or src port 41066 or src port 41064 or src port 36034 or src port 36028 or src port 41062 or src port 41070 or src port 41058 or src port 40692 or src port 36032 or src port 41068 or src port 40694 or src port 40698 or src port 36024 or src port 40706 or src port 41056 or src port 40690 or src port 41060 or src port 40688 or src port 40700"
    
    
  • linux使用 storcli 查询raid卡情况.

    下载storcli

    https://www.broadcom.com/products/storage/raid-controllers/megaraid-9560-8i

    安装storcli

    root@debian:~# dpkg -i storcli_007.3007.0000.0000_all.deb
    
    root@debian:~# dpkg -l | grep -i storcli
    ii  storcli                         007.3007.0000.0000             all          Storage Command Line Tool, manages storage controllers.
    

    查看有哪些控制器

    /opt/MegaRAID/storcli/storcli64 show all
    
    CLI Version = 007.3007.0000.0000 May 16, 2024
    Operating system = Linux 6.1.0-22-amd64
    Status Code = 0
    Status = Success
    Description = None
    
    Number of Controllers = 1
    Host Name = debian
    Operating System  = Linux 6.1.0-22-amd64
    
    System Overview :
    ===============
    
    ------------------------------------------------------------------------------------
    Ctl Model                   Ports PDs DGs DNOpt VDs VNOpt BBU sPR DS  EHS ASOs Hlth
    ------------------------------------------------------------------------------------
      0 AVAGOMegaRAIDSAS9361-8i     8  13   2     0   2     0 Opt On  1&2 Y      3 Opt
    ------------------------------------------------------------------------------------
    
    Ctl=Controller Index|DGs=Drive groups|VDs=Virtual drives|Fld=Failed
    PDs=Physical drives|DNOpt=Array NotOptimal|VNOpt=VD NotOptimal|Opt=Optimal
    Msng=Missing|Dgd=Degraded|NdAtn=Need Attention|Unkwn=Unknown
    sPR=Scheduled Patrol Read|DS=DimmerSwitch|EHS=Emergency Spare Drive
    Y=Yes|N=No|ASOs=Advanced Software Options|BBU=Battery backup unit/CV
    Hlth=Health|Safe=Safe-mode boot|CertProv-Certificate Provision mode
    Chrg=Charging | MsngCbl=Cable Failure
    ...
    

    查看第一个控制器

    /opt/MegaRAID/storcli/storcli64 /c0 show
    

    一些使用storcli的例子

    如何在新的 VxRack 节点上使用 Storcli 配置虚拟磁盘

  • debian12 最小化安装后,配置静态ip

    debian12 最小化安装后,配置静态ip

    配置静态ip

    1. 检查那个网口是配置好线路的.
    2. 给目标网口配置ip
    root@debian:~# cat  /etc/network/interfaces.d/ifcfg-enp59s0f0
    auto enp59s0f0
    iface enp59s0f0 inet static
        address 192.168.11.53
        netmask 255.255.248.0
        gateway 192.168.8.254
    
    1. 重启网络
    systemctl restart networking.service
    
    1. 检查ip
    root@debian:~# ip addr
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host noprefixroute
           valid_lft forever preferred_lft forever
    2: enp63s0f2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
        link/ether 2c:f0:5d:bc:1b:56 brd ff:ff:ff:ff:ff:ff
    3: enp63s0f3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
        link/ether 2c:f0:5d:bc:1b:57 brd ff:ff:ff:ff:ff:ff
    4: enp59s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
        link/ether 58:53:c0:66:03:d0 brd ff:ff:ff:ff:ff:ff
        inet 192.168.11.53/21 brd 192.168.15.255 scope global enp59s0f0
           valid_lft forever preferred_lft forever
        inet6 fe80::5a53:c0ff:fe66:3d0/64 scope link
           valid_lft forever preferred_lft forever
    5: enp59s0f1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
        link/ether 58:53:c0:66:03:d1 brd ff:ff:ff:ff:ff:ff
    
    root@debian:~# ip route
    default via 192.168.8.254 dev enp59s0f0 onlink
    192.168.8.0/21 dev enp59s0f0 proto kernel scope link src 192.168.11.53
    root@debian:~#
    

    配置阿里云镜像源

    root@debian:~# cat /etc/apt/sources.list
    deb http://mirrors.aliyun.com/debian/ bookworm main non-free-firmware contrib
    deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free-firmware contrib
    deb http://mirrors.aliyun.com/debian-security/ bookworm-security main
    deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main
    deb http://mirrors.aliyun.com/debian/ bookworm-updates main non-free-firmware contrib
    deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main non-free-firmware contrib
    deb http://mirrors.aliyun.com/debian/ bookworm-backports main non-free-firmware contrib
    deb-src http://mirrors.aliyun.com/debian/ bookworm-backports main non-free-firmware contrib
    

    如果新安装的debian 可能没有安装 resolvconf, 无法解析域名.

    这个时候可以先在别的机器测试mirrors.aliyun.com的ip是多少,然后配置到 /etc/hosts

    root@debian:~# grep mirror /etc/hosts
    218.77.200.227 mirrors.aliyun.com
    root@debian:~#
    

    安装resolvconf

    apt update
    apt install resolvconf
    

    配置dns解析

    root@debian:~# cat /etc/resolvconf/resolv.conf.d/base
    nameserver 114.114.114.114
    root@debian:~#
    

    重启resolveconf

    systemctl restart resolvconf
    

    配置zh_CN.utf8

    # 查看可以使用的编码
    root@debian:~# locale -a
    C
    C.utf8
    en_HK.utf8
    POSIX
    root@debian:~#
    
    # 增加zh_CN.utf8 编码
    dpkg-reconfigure locales
    # 选择zh_CN.utf8,然后ok回车.
    
    # 再次查看
    root@debian:~# locale -a
    C
    C.utf8
    en_HK.utf8
    POSIX
    zh_CN.utf8
    
  • chrony 同步系统时间

    chrony 配置文件使用腾讯外网ntp

    grep tencent /etc/chrony.conf  -A 2 -B 2
    # Use public servers from the pool.ntp.org project.
    # Please consider joining the pool (http://www.pool.ntp.org/join.html).
    server ntp1.tencent.com iburst
    server ntp2.tencent.com iburst
    server ntp3.tencent.com iburst
    server ntp4.tencent.com iburst
    server ntp5.tencent.com iburst
    
    # Record the rate at which the system clock gains/losses time.
    

    (more…)

  • 如何使用nologin用户执行命令

    nologin 用户执行命令

    [root@node1 ~]# ls -al /tmp/qemu-user-test
    ls: cannot access '/tmp/qemu-user-test': No such file or directory
    
    [root@node1 ~]# su -s /bin/bash -c 'echo "i am nologin user." > /tmp/qemu-user-test' qemu
    
    [root@node1 ~]# ls -al /tmp/qemu-user-test
    -rw-r--r-- 1 qemu qemu 19 Jan 31 11:29 /tmp/qemu-user-test
    
    [root@node1 ~]# cat /tmp/qemu-user-test
    i am nologin user.