Blog

  • watch进行持续输出

    用 watch 在测试的时候可以跟进输出

    每一秒钟刷新一次

    watch -n 1 'netstat -nat | grep 211.148.19.12'

    如果想要持续性的查看,可以写到日志中

    watch -n1 'netstat -nat | grep 211.148.19.12| tee -a netstat.log'

    或者使用 sleep 来输出每一次的执行

    while sleep 1; do netstat -nat | grep 211.148.19.12; done
  • git push 多个 remote

    如果都是 master 的话

    git remote | xargs -n 1 git push

    同一个 remote 有多个 push url, git push origin branch_name

    [remote "origin"]
    	url = [email protected]:jpuyy/terraform-gke.git
    	fetch = +refs/heads/*:refs/remotes/origin/*
    	pushurl = [email protected]:jpuyy/terraform-gke.git
    	pushurl = https://self-managed-git.com/common/terraform-gke.git
    
  • git lock

    ➜  ansible-roles git:(master) ✗ git add todo.md 
    fatal: Unable to create '/Users/jpuyy/ansible-roles/.git/index.lock': File exists.
    
    If no other git process is currently running, this probably means a
    git process crashed in this repository earlier. Make sure no other git
    process is running and remove the file manually to continue.
    

    解决办法

    rm -f .git/index.lock
  • 使用 sar 查看系统监控

    安装

    yum install -y sysstat

    使用 sar 可以监控 cpu, 内存, swap, I/O, load, network实时以及历史指定时间的值

    定时任务文件

    /etc/cron.d/sysstat

    查看 cpu ,每 1 秒钟一次,共 3 次

    sar 1 3

    查看 内存使用

    sar -r

    查看 swap 使用

    sar -S

    查看 I/O,整个系统

    sar -b

    查看单个设备 I/O

    sar -d

    查看 context switch 上下文切换

    sar -w

    查看队列和负载情况

    sar -q

    查看网络情况

    sar -n DEV 1

    参考:

    10 Useful Sar (Sysstat) Examples for UNIX / Linux Performance Monitoring

  • docker使用

    pull

    docker pull centos

    build

    docker build -t jpuyy.com:master --rm=true .

    对已有 image 再打一个 tag

    docker tag jpuyy.com:master notexit.com:master

    推到远端

    docker push $REPO:$VER

    复制文件到 docker 里

    docker cp page.html elegant_noether:/user/local/apache2/htdocs

    查看端口映射

    docker port 10936519db14

    找出一批 docker 容器在系统里的 pid

    docker ps -a | grep -i demo1  | awk '{print $1}' | xargs docker inspect --format '{{.State.Pid}} {{.Name}}'
    

    docker 修剪 清理 https://docs.docker.com/config/pruning/

    docker system prune
    
  • journalctl

    查看某个 unit 的日志

    journalctl -u docker
    
    journalctl -f
    

    配置文件

    /etc/systemd/journald.conf

    重启

    systemctl restart systemd-journald.service

    清理 journal log

    只保留两天

    journalctl --vacuum-time=2d

    只保留 500M

    journalctl --vacuum-size=500M