Blog

  • 如何使用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.
    
  • 检查ip冲突的方法

    使用arping检查ip冲突.

    [root@node1 ~]# arping -I enp4s0f0  192.168.11.3
    ARPING 192.168.11.3 from 192.168.12.196 enp4s0f0
    Unicast reply from 192.168.11.3 [18:C0:4D:1D:AA:7C]  0.683ms
    Unicast reply from 192.168.11.3 [18:C0:4D:1D:AA:7C]  0.551ms
    Unicast reply from 192.168.11.3 [18:C0:4D:1D:AA:7C]  0.562ms
    Unicast reply from 192.168.11.3 [18:C0:4D:1D:AA:7C]  0.548ms
    

    如果返回的mac 地址有多个, 说明这个局域网出现ip冲突.

  • 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)"