Category: Life

  • linux sudo su 学习

    要添加一个 sudo 用户

    首先创建用户

    useradd ansible

    将其加入到 /etc/sudoers 中。

    检测 visudo 的语法

    visudo -cf /etc/sudoers

    visudo 使用 sudo 的原则

    有了 sudo 就尽量用 sudo
    执行命令尽量使用白名单而不是黑名单
    尽量对 sudo 所在的组进行设置

    如果一个用户 cat /etc/passwd 设置为了 /sbin/nologin
    可使用 su 强制切到对应用户

    su -l jpuyy -s /bin/bash 
    
    # su --help
    BusyBox v1.31.1 () multi-call binary.
    
    Usage: su [-lmp] [-] [-s SH] [USER [SCRIPT ARGS / -c 'CMD' ARG0 ARGS]]
    
    Run shell under USER (by default, root)
    
    	-,-l	Clear environment, go to home dir, run shell as login shell
    	-p,-m	Do not set new $HOME, $SHELL, $USER, $LOGNAME
    	-c CMD	Command to pass to 'sh -c'
    	-s SH	Shell to use instead of user's default
    
  • vim打开文件

    vim 打开文件并跳到最后一行

    vim + filename

    vim 打开文件并跳到指定行

    vim +n filename

    vim 打开两个文件,并以 vsplit 显示

    vim -O file1 file2

    vim 打开两个文件,并以 split 显示

    vim -o file1 file2

    save all

    :wqa
    

    vim can open .zip, .tar.gz files, to prview the filenames in side the package.

  • 查看nfs的挂载情况

    对于 nfs server ,查看有哪些客户端连过来

    showmount -a
  • linux desktop reboot shutdown hang处理

    linux desktop 当点击重启或关机,或通过命令,都会卡在

    restarting system
    shutting down system

    解决办法:

    centos 7 为例

    编辑

    sudo vim /etc/grub2.cfg

    在启动项一行最后添加 reboot=bios

    inux16 /boot/vmlinuz-3.10.0-123.el7.x86_64 root=UUID=e27de799-ef92-4a09-99cf-dde69fe13e88 ro vconsole.keymap=us crashkernel=auto vconsole.font=latarcyrheb-sun16 rhgb quiet reboot=bios

    参考:http://linux.koolsolutions.com/2009/08/04/howto-fix-linux-hangfreeze-during-reboots-and-restarts/

  • git clone很大的 repo

    如果一个 git 库有太长的 history,clone 一份需要好长时间,那么可以考虑不 clone 太长的 history.

    git clone --depth depth remote-url

    例如

    git clone --depth 2 https://github.com/torvalds/linux.git

    这样git log 只会看到两条记录

    参考:http://blogs.atlassian.com/2014/05/handle-big-repositories-git/

  • 多节点梯子择优脚本

    [jpuyy@jpuyy-laptop allconf]$ cat tizi.sh 
    #/bin/bash
    
    suffix='.heredance.com'
    
    locations='jp1 jp2 jp3 us1 us2 us3 us4 us5 sg1 sg2 hk1 hk2 tw1 uk1'
    
    result_file='/tmp/.result_array'
    
    > $result_file
    for location in $locations;
    do
        result=`ping -q -A -c 10 $location$suffix | grep received`
        echo "$location$suffix $result" >> $result_file
    done
    
    cat $result_file | sort -r -n -k 5 -k 11