Blog

  • brew 切换 python 版本

    切换 python 至 3.6.5

    brew list python --versions
    brew switch python 3.6.5
    

    升级 python3

    brew install python3
    

    link 切换

    ➜  ✗ brew link python
    Linking /usr/local/Cellar/python/3.7.7... 
    Error: Could not symlink Frameworks/Python.framework/Headers
    Target /usr/local/Frameworks/Python.framework/Headers
    is a symlink belonging to python@2. You can unlink it:
      brew unlink python@2
    解除 python@2 link
    Unlinking /usr/local/Cellar/python@2/2.7.17... 34 symlinks removed
    
    
    To force the link and overwrite all conflicting files:
      brew link --overwrite python
    
    To list all files that would be deleted:
      brew link --overwrite --dry-run python
    ➜  ✗ brew link python --overwrite python
    Linking /usr/local/Cellar/python/3.7.7... 28 symlinks created
    
  • CentOS 7 systemd 禁用 gnome 启动

    平时自己家里的 CentOS 7 不需要图形界面,所以禁用

    查看当前启动模式,发现时界面模式

    [root@192 ~]# systemctl get-default 
    graphical.target
    

    将界面模式改为多用户无界面模式,重启生效

    [root@192 ~]# systemctl set-default multi-user.target
    Removed symlink /etc/systemd/system/default.target.
    Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
    [root@192 ~]# systemctl reboot
    
  • clean_merged 清理已经合并的 git 分支

    alias clean_merged='git checkout master && git branch --merged | grep -v master | xargs git branch -D'
    
  • git 本地新建分支在远端自动创建并设置 upstream

    .git/config 添加

    [push]
        default = current
    

    push 的时候加上 -u

    git push -u
    
  • docker-compose

    sudo pip install -U docker-compose
    

    编写

    version: '3.2'
    services:
      db:
        image: mysql:5.7.21
        container_name: mysql
        hostname: mysql-test-1
        restart: always
        ports:
          - 3306:3306
        environment:
          - MYSQL_ALLOW_EMPTY_PASSWORD=YES
        volumes:
          - ./tmp:/var/lib/mysql
    
      broker:
        image: redis:3.0-alpine
        command: redis-server 
        container_name: broker
        hostname: broker-test-1
        restart: always
        ports:
          - 6379:6379
        volumes:
          - ./tmp:/var/lib/redis
    

    拉起 docker

    docker-compose up -d
    
  • 关闭 swap 操作

    检查:

    free -m # 应该 Swap 显示全是 0
    

    备份 /etc/fstab

    cp /etc/fstab /tmp/fstab.`date +%F`
    

    删除 /etc/fstab 中 swap 挂载项

    vim /etc/fstab
    

    关闭所有 swap

    swapoff -a
    

    观察进程使用 swap 和 swapoff -a 之后回收情况,对于不能回收 swap 的进程需要安排时间重启

    
    free -m
    for file in /proc/*/status ; do cat $file | awk '/Name|^Pid|VmSwap/{printf $2 " " $3 $4}END{ print ""}' | grep kB | grep -v '0 kB' ; done | sort -k 3 -n