Category: linux

  • centos7编译打包keepalived-2.2.8

    keepalived 虚拟机环境内存泄露

    centos7 自动的keepalived 版本是1.3.5 , 在虚拟机下运行时存在vrrp 导致的内存泄漏.

    Memory leak on raw vrrp socket ? #839

    下载编译打包 keepalived 2.2.8

     yum install rpm-build
     yum install wget
     yum install kernel-devel
     yum install rpm-build make gcc openssl-devel popt-devel kernel-devel ipvsadm
     yum install aclocal autoheader automake autoreconf
     yum install net-snmp-devel
     yum install net-snmp-devel -y
     yum install openssl-devel
     yum install kernel-headers
     yum install gcc rpm-build rpm-devel rpmlint make coreutils diffutils patch rpmdevtools
     yum install net-snmp-devel
     yum install libnl-devel
     yum install net-snmp net-snmp-utils net-snmp-libs
     yum install  kmod-devel  systemd-devel
    
    
    rpmdev-setuptree
    
    cp keepalived-2.2.8.tar.gz rpmbuild/SOURCES/
    
    #下载keepalived 2.2.8
    wget https://www.keepalived.org/software/keepalived-2.2.8.tar.gz  --no-check-certificate
    tar xf keepalived-2.2.8.tar.gz
    
    cd keepalived-2.2.8
    #configure
    ./autogen.sh
    ./configure  --enable-snmp
    #compile and create rpm
    rpmbuild -ba keepalived.spec
    

    keepalived-2.2.8-1.el7.x86_64.rpm 位置

    [root@d1918be059ac ~]# find rpmbuild/ |grep rpm$
    rpmbuild/RPMS/x86_64/keepalived-2.2.8-1.el7.x86_64.rpm
    rpmbuild/RPMS/x86_64/keepalived-debuginfo-2.2.8-1.el7.x86_64.rpm
    rpmbuild/SRPMS/keepalived-2.2.8-1.el7.src.rpm
    
    #安装
    yum install keepalived-2.2.8-1.el7.x86_64.rpm
    
  • 统计linux系统进程内存使用百分比

    打印一次所有进程情况

    top -b -n 1

    忽略前面8行

    tail -n +8

    统计

    top -b -n 1  \
    |awk '{print $10}'\
    |tail -n +8 \
    |xargs  -i echo "{} +" \
    |xargs -r \
    |xargs -i python -c "print( {} 0)"
    

    统计2

    ps axu --sort -rss \
    |awk '{print $6}'|tail -n +2 \
    |xargs  -i echo "{} +"|xargs -r \
    |xargs -i python -c "print( {} 0)"
    
  • linux原生支持的格式化文件方法

    利用python格式json

    python -m json.tool

    echo '{"list":[{"a":"1"},{"b":"2"}]}' |python -m json.tool
    
    cat x.json
    {"list":[{"a":"1"},{"b":"2"}]}
    
    python -m json.tool  x.json
    {
        "list": [
            {
                "a": "1"
            },
            {
                "b": "2"
            }
        ]
    }
    

    利用python计算

    python -c ‘print(123+456+7.89)’

    xmllint格式化xml文件

    xmllint –format pom.xml

  • centos7使用接入iscsi设备

    centos7 安装Open ISCSI 启动器 软件包

    yum install iscsi-initiator-utils -y

    查看 iscsi 启动器名称

    [root@mulangcloud ~]# cat /etc/iscsi/initiatorname.iscsi
    InitiatorName=iqn.1994-05.com.redhat:a5c39efe925
    

    扫描 iscsi target

    192.168.8.73 iscsi 服务器.

    [root@mulangcloud ~]#  iscsiadm -m discovery -t st -p 192.168.8.73
    192.168.8.73:3260,1 iqn.2020-03.com.ml:target
    

    扫描 open iscsi 客户端已经登陆的 session

    在完成目标发现后,即可以登录到相应的节点,使用目标设备提供的存储空间.
    -T后面跟target名称,--login等同于-l

    [root@mulangcloud ~]#  iscsiadm -m session
    tcp: [4] 192.168.8.73:3260,1 iqn.2020-03.com.ml:target (non-flash)
    
    [root@mulangcloud ~]#  iscsiadm -m session -r 4  --rescan
    Rescanning session [sid: 4, target: iqn.2020-03.com.ml:target, portal: 192.168.8.73,3260]
    
    [root@mulangcloud ~]# ls -l /dev/disk/by-path/
    total 0
    lrwxrwxrwx 1 root root  9 Jul 24 09:27 ip-192.168.8.73:3260-iscsi-iqn.2020-03.com.ml:target-lun-0 -> ../../sdd
    lrwxrwxrwx 1 root root 10 Jul 24 09:27 ip-192.168.8.73:3260-iscsi-iqn.2020-03.com.ml:target-lun-0-part1 -> ../../sdd1
    lrwxrwxrwx 1 root root 10 Jul 24 09:27 ip-192.168.8.73:3260-iscsi-iqn.2020-03.com.ml:target-lun-0-part2 -> ../../sdd2
    lrwxrwxrwx 1 root root  9 Jul 24 09:25 ip-192.168.8.73:3260-iscsi-iqn.2020-03.com.ml:target-lun-1 -> ../../sde
    lrwxrwxrwx 1 root root  9 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0 -> ../../sda
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part1 -> ../../sda1
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part2 -> ../../sda2
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part3 -> ../../sda3
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part4 -> ../../sda4
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part5 -> ../../sda5
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part6 -> ../../sda6
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part7 -> ../../sda7
    lrwxrwxrwx 1 root root  9 Jul 19 08:40 pci-0000:00:1f.2-ata-2.0 -> ../../sdb
    lrwxrwxrwx 1 root root  9 Jul 19 08:40 pci-0000:00:1f.2-ata-3.0 -> ../../sdc
    
    [root@mulangcloud ~]# echo 1 > /sys/block/sdd/device/delete
    [root@mulangcloud ~]# echo 1 > /sys/block/sde/device/delete
    
    [root@mulangcloud ~]# ls -l /dev/disk/by-path/
    total 0
    lrwxrwxrwx 1 root root  9 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0 -> ../../sda
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part1 -> ../../sda1
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part2 -> ../../sda2
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part3 -> ../../sda3
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part4 -> ../../sda4
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part5 -> ../../sda5
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part6 -> ../../sda6
    lrwxrwxrwx 1 root root 10 Jul 19 08:40 pci-0000:00:1f.2-ata-1.0-part7 -> ../../sda7
    lrwxrwxrwx 1 root root  9 Jul 19 08:40 pci-0000:00:1f.2-ata-2.0 -> ../../sdb
    lrwxrwxrwx 1 root root  9 Jul 19 08:40 pci-0000:00:1f.2-ata-3.0 -> ../../sdc
    
    [root@mulangcloud ~]# iscsiadm -m node -T iqn.2020-03.com.ml:target -u
    Logging out of session [sid: 4, target: iqn.2020-03.com.ml:target, portal: 192.168.8.73,3260]
    Logout of [sid: 4, target: iqn.2020-03.com.ml:target, portal: 192.168.8.73,3260] successful.
    

    other

    列出所有target
    iscsiadm -m node
    
    连接所有target
    iscsiadm -m node -L all
    
    连接指定target
    iscsiadm -m node -T iqn.... -p 172.29.88.62 --login
    
    使用如下命令可以查看配置信息
    iscsiadm -m node -o show -T iqn.2000-01.com.synology:rackstation.exservice-bak
    
    查看目前 iSCSI target 连接状态
    iscsiadm -m session
    iscsiadm: No active sessions.
    (目前没有已连接的 iSCSI target)
    
    断开所有target
    iscsiadm -m node -U all
    
    断开指定target
    iscsiadm -m node -T iqn... -p 172.29.88.62 --logout
    
    删除所有node信息
    iscsiadm -m node --op delete
    
    删除指定节点(/var/lib/iscsi/nodes目录下,先断开session)
    iscsiadm -m node -o delete -name iqn.2012-01.cn.nayun:test-01
    
    删除一个目标(/var/lib/iscsi/send_targets目录下)
    iscsiadm --mode discovery -o delete -p 172.29.88.62:3260
    
  • 编译ldmtool

    想在linux环境上挂载windows的动态磁盘.启动容器运行centos7, 编译ldmtool.

    下载版本

    https://github.com/mdbooth/libldm/archive/refs/tags/libldm-0.2.5.zip

    编译步骤

    sh autogen.sh
    make
    make install
    

    需要安装的库

    yum install make
    
    #autogen.sh: line 26: gtkdocize: command not found
    yum install gtk-doc
    #autogen.sh: line 29: autoreconf: command not found
    yum install autoconf
    
    #autoreconf: failed to run aclocal: No such file or directory
    yum install automake
    
    #autoreconf: failed to run libtoolize: No such file or directory
    yum install libtool
    
    #configure: error: readline library is missing
    yum install readline-devel
    
    #No package 'gobject-2.0' found
    yum install glib2-devel
    
    #No package 'json-glib-1.0' found
    yum install json-glib-devel
    
    #No package 'zlib' found
    yum install zlib-devel
    
    #No package 'uuid' found
    yum install libuuid-devel
    
    #No package 'devmapper' found
    yum install device-mapper-libs  device-mapper-devel