polym / issues

0 stars 0 forks source link

2019 周报 #1

Open polym opened 5 years ago

polym commented 5 years ago

汇总

polym commented 5 years ago

获取视频码率技巧

直接对直播流执行 ffprobe 会出现码率 N/A 的情况

ffprobe -v error -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1

https://video.stackexchange.com/questions/16356/how-to-use-ffprobe-to-obtain-certain-information-about-mp4-h-264-files

FFprobe JSON 格式

ffprobe -v quiet -print_format json -show_format -show_streams

k8s 灰度更新

https://cloud.tencent.com/developer/article/1350892 https://www.elvinefendi.com/2018/11/25/canary-deployment-with-ingress-nginx.html

.dockerignore 忽略其他所有不相干文件或目录

**
!path/to/dir/**
!path/to/file

操作系统相关

  1. openstack 虚拟机修改 hostname
# Remove the ‘ – update_hostname’ line in  /etc/cloud/cloud.cfg

# use hostnamectl
hostnamectl set-hostname LOG --static

扩展 MYSQL 表字段

alter table applications modify column app_name varchar(64);
describe applications;

容器逃逸漏洞 CVE-2019-5736

https://blog.dragonsector.pl/2019/02/cve-2019-5736-escape-from-docker-and.html

复现方式

https://github.com/polym/cve-2019-5736-poc

结论

小知识点

polym commented 5 years ago

Golang

package main

import (
    "github.com/gin-contrib/pprof"
    "github.com/gin-gonic/gin"
)

func main() {
  router := gin.Default()
  pprof.Register(router)
  router.Run(":8080")
}
go tool pprof -http="0.0.0.0:18081" -seconds 300 ./app http://10.0.5.199:10801/debug/pprof/profile

执行上面命令行可能出现 Couldn't find a suitable web browser! Set the BROWSER environment variable to your desired browser. 忽略即可。

image

Docker/Kubernetes

MySQL

Git

Kafka

创建 topic 时,设置清理策略,保证磁盘空间充足。

kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 64 --topic app-logs --config cleanup.policy=delete --config retention.ms=3600000
polym commented 5 years ago

Golang

package utils

import (
    "runtime"
    "time"
)

// Trace function and output function execute time
type TraceTimer struct {
    startTime time.Time
    funcName  string
    log       func(format string, v ...interface{})
}

func (tt *TraceTimer) Start() {
    pc := make([]uintptr, 10) // at least 1 entry needed
    runtime.Callers(2, pc)
    tt.funcName = runtime.FuncForPC(pc[0]).Name()
    tt.startTime = time.Now()
}
func (tt *TraceTimer) Stop() {
    tt.log("[TraceTimer] %s: %s elapsed", tt.funcName, time.Now().Sub(tt.startTime))
}

func NewTraceTimer(l func(format string, v ...interface{})) *TraceTimer {
    return &TraceTimer{log: l}
}

Docker/Kubernetes

GitHub

Swagger

VIM

go clean -cache
go build -i

Bash

其他

polym commented 5 years ago

Docker/Kubernetes

Bash/Git/VIM

FFmpeg

polym commented 5 years ago

FFmpeg

Docker

MySQL

GitBook

常用命令

FROM fellah/gitbook:3.2.1

RUN apt update && apt install -y calibre

VOLUME /src/gitbook
WORKDIR /src/gitbook

CMD ["bash", "-c", "gitbook install && gitbook mobi . ./output.mobi"]

docker run -it -v $(pwd):/src/gitbook gitbook-cli

其他

sudo -u git -H /opt/gitlab/embedded/service/gitlab-shell/bin/create-hooks /var/opt/gitlab/git-data/repositories/

polym commented 5 years ago

Kubernetes/Docker

Bash

工具 🔧

wrk.method = "PUT" wrk.body = read_txt_file("data")


- tcpdump 抓取 HTTP GET 请求 报文 `tcpdump -s 0 -A 'tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420'`
- 读取目录下所有文件内容并显示文件名 `grep "" *`
polym commented 5 years ago

Linux/Kubernetes/Docker

docker inspect -f {{.State.Pid}} 44fc0f0582d9
nsenter --target 3326 --mount --uts --ipc --net --pid

cfssl 使用

ETCD

ansible

- name: do sth
  shell: |
    echo "xxx" | \
    awk '{print $1}'

其他

polym commented 5 years ago

Linux/Kubernetes/Docker

#!/bin/bash
#===================================================================================
#
# FILE: dump.sh
# USAGE: dump.sh [-i interface] [tcpdump-parameters]
# DESCRIPTION: tcpdump on any interface and add the prefix [Interace:xy] in front of the dump data.
# OPTIONS: same as tcpdump
# REQUIREMENTS: tcpdump, sed, ifconfig, kill, awk, grep, posix regex matching
# BUGS:  ---
# FIXED: - In 1.0 The parameter -w would not work without -i parameter as multiple tcpdumps are started.
#        - In 1.1 VLAN's would not be shown if a single interface was dumped.
# NOTES: ---
#        - 1.2 git initial
# AUTHOR: Sebastian Haas
# COMPANY: pharma mall
# VERSION: 1.2
# CREATED: 16.09.2014
# REVISION: 22.09.2014
#
#===================================================================================

# When this exits, exit all background processes:
trap 'kill $(jobs -p) &> /dev/null && sleep 0.2 &&  echo ' EXIT
# Create one tcpdump output per interface and add an identifier to the beginning of each line:
if [[ $@ =~ -i[[:space:]]?[^[:space:]]+ ]]; then
    tcpdump -l $@ | sed 's/^/[Interface:'"${BASH_REMATCH[0]:2}"'] /' &
else
    for interface in $(ifconfig | grep '^[a-z0-9]' | awk '{print $1}')
    do
       tcpdump -l -i $interface -nn $@ | sed 's/^/[Interface:'"$interface"']    /' &
    done
fi
# wait .. until CTRL+C
wait
cat << EOF > /tmp/data
a
b
c
EOF
CID=$1
CON_PID=$(docker inspect '--format={{ .State.Pid }}' $CID)
CON_NET_SANDBOX=$(docker inspect '--format={{ .NetworkSettings.SandboxKey }}' $CID)
rm -f /var/run/netns/$CON_PID
mkdir -p /var/run/netns
ln -s $CON_NET_SANDBOX /var/run/netns/$CON_PID
VETH_ID=$(ip netns exec $CON_PID ip link show eth0|head -n 1|awk -F'@|:' '{print $3}'|cut -c3-)
VETH_NAME=$(ip link|grep "^${VETH_ID}:"|awk '{print $2}'|awk -F@ '{print $1}')
echo $VETH_NAME
rm -f /var/run/netns/$CON_PID

Ansible

polym commented 5 years ago

Docker/Kubernetes/Linux

Ansible

polym commented 5 years ago

VIM

本周读物

polym commented 5 years ago

Golang

type context struct { r gin.Engine t testing.T }

func marshal(v interface{}) io.Reader { b, _ := json.Marshal(v) return bytes.NewReader(b) }

func unmarshal(resp *http.Response, v interface{}) error { data, _ := ioutil.ReadAll(resp.Body) resp.Body.Close() return json.Unmarshal(data, v) }

func runSimpleAPITest(ctx *context, method, uri string, code int, req, expect interface{}) { request, _ := http.NewRequest(method, uri, marshal(req)) resp := reflect.New(reflect.TypeOf(expect)).Interface()

w := httptest.NewRecorder()
ctx.r.ServeHTTP(w, request)

assert.Equal(ctx.t, w.Code, code)
err := unmarshal(w.Result(), resp)
assert.Nil(ctx.t, err)
assert.Equal(ctx.t, resp, expect)

}



## VIM

- [水平分割窗口切换成垂直分割](https://stackoverflow.com/questions/1269603/to-switch-from-vertical-split-to-horizontal-split-fast-in-vim)
![image](https://user-images.githubusercontent.com/2860926/56872940-059c1d80-6a61-11e9-817d-78f8937503a4.png)
polym commented 5 years ago

Golang

polym commented 5 years ago

VIM

polym commented 5 years ago

FFmpeg

polym commented 5 years ago

Git

其他

polym commented 5 years ago

Golang

polym commented 5 years ago

VirtualBox

图片处理

polym commented 5 years ago
polym commented 4 years ago
polym commented 4 years ago
polym commented 4 years ago

Kubernetes

polym commented 4 years ago
polym commented 4 years ago

Bash

polym commented 4 years ago

Ansible

Vagrant