Author: jpuyy

  • shell 生成 mac 地址

    MACADDR="52:54:$(dd if=/dev/urandom count=1 2>/dev/null | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4/')"; echo $MACADDR
  • 磁盘分区表 MBR 和 GPT

    MBR(Master Boot Record)

    最大只支持 2 TB 的盘,最多只支持 4 个主分区
    信息只存储在一个区域

    GPT(GUID partition table)
    是 MBR 的替代,属于 UEFI,磁盘的每一个分区都有唯一的识别号,支持更大的盘和更多的分区
    信息存储在多个区域,当一部分受损后可修复

    当 GPT 分区的盘在老的只支持 mbr 的工具下查看时,也会读到分区信息,只不过看到的是只有一个分区,这是为了防止用户误认为盘是空盘。

    当大于 2TB 盘安装安装 CentOS 7 时报错

    Your BIOS-based system needs a special partition to boot from a GPT disk label. To continue, please create a 1MiB 'biosboot' type partition

    对于这个问题,解决办法是在 kickstart 文件中添加

    part biosboot --fstype=biosboot --size=1
  • 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
    
  • CentOS 7 更改 interface name

    习惯于用 eth0 eth1 ,不习惯 em1, enp0s3,在 kickstart 文件中写如下脚本,使用 eth0, eth1

    # grub 的配置,关键是内核启动参数 net.ifnames=0 biosdevname=0
    
    cat << __EOT__ > /etc/default/grub
    GRUB_TIMEOUT=5
    GRUB_DEFAULT=saved
    GRUB_DISABLE_SUBMENU=true
    GRUB_TERMINAL_OUTPUT="console"
    GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet net.ifnames=0 biosdevname=0"
    GRUB_DISABLE_RECOVERY="true"
    __EOT__
    
    # 生成实际使用的 grub2.cfg
    grub2-mkconfig -o /boot/grub2/grub.cfg
    
    # 删掉不喜欢的 interface name
    rm -f /etc/sysconfig/network-scripts/ifcfg-em*
    rm -f /etc/sysconfig/network-scripts/ifcfg-en*
    
    # 创建 eth0, eth1 模板
    cat << __EOT__ > /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    BOOTPROTO="static"
    IPV6INIT="no"
    NM_CONTROLLED="yes"
    ONBOOT="yes"
    TYPE="Ethernet"
    IPADDR=192.168.x.x
    NETMASK=255.255.255.0
    GATEWAY=192.168.x.1
    __EOT__
    
    cat << __EOT__ > /etc/sysconfig/network-scripts/ifcfg-eth1
    DEVICE=eth1
    BOOTPROTO="static"
    IPV6INIT="no"
    NM_CONTROLLED="yes"
    ONBOOT="no"
    TYPE="Ethernet"
    __EOT__
    
  • npm使用淘宝的registry

    遇到过 forever 装不上的情况

    /usr/bin/npm install forever -g
    
    701 error Error: shasum check failed for /root/tmp/npm-5826-Ev6S_4GZ/1438247556786-0.7053809177596122/tmp.tgz
    701 error Expected: 4353b88b7131797fb5520e39eba263df5863cba3
    701 error Actual:   28322c7853c55e33081b19337d4e5359b8cceaae
    701 error     at /usr/lib/node_modules/sha/index.js:38:8

    换成淘宝的registry后正常。

    npm config set registry http://registry.npm.taobao.org/
  • mac terminal 查词典

    在 mac 的 terminal 下打开词典并查 blog

    open dict://blog

    要输入的命令有点长,于是在 ~/.zshrc 中添加函数

    dict(){
      open dict://$1
    }

    在 terminal 中可以这样查 dict blog