Personnal Document
Table of Contents
Terminology
- NDA: 保密协议(Non-disclosure agreement)
- PCB: 印刷电路板(Printed circuit board)
- SCH: 原理图(schematic),是一种简化的电路图形表示
- IDH: 是上游 IC 原厂与下游整机企业之间的桥梁,它在 IC 原厂芯片的基础上开发平台、解决方案等产品,为整机产品的研发和迅速面市提供了条件
- IC: 集成电路(integrated circuit)
Information
| 网站 | 描述 |
|---|---|
| http://www.caict.ac.cn/ | 中国信通院,国家高端专业智库 产业创新发展平台 |
| https://csrc.nist.gov/ | 美国国家标准与技术研究院,计算机安全资源中心 |
| http://www.brendangregg.com/ | 系统性能分析 |
| https://www.asciiart.eu/ | 字符画 |
Computer
CPU
中央处理器 (英语:Central Processing Unit,缩写:CPU),是计算机的主要设备之一,功能主要是解释计算机指令以及处理计算机软件中的数据。计算机的可编程性主要是指对中央处理器的编程。
GPU
图形处理器(英语:graphics processing unit,缩写:GPU),又称显示核心、视觉处理器、显示芯片或绘图芯片,是一种专门在个人计算机、工作站、游戏机和一些移动设备(如平板电脑、智能手机等)上运行绘图运算工作的微处理器。
CPU/GPU AI
在 AI 中需要处理大量的数据,而根据这些数据的特点,GPU 的速度要远远快于 CPU,从而 GPU 的发展在 AI 的推动下会更快的发展.
DNS
通配符域名
Docker
ubuntu 安装
https://docs.docker.com/install/linux/docker-ce/ubuntu/
Ubuntu18.04 安装 docker
sudo apt-get remove docker docker-engine docker.io sudo apt-get update sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo apt-key fingerprint 0EBFCD88 sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" sudo apt-get update sudo apt-get install docker-ce
centos 安装
https://docs.docker.com/install/linux/docker-ce/centos/#install-docker-ce
sudo yum install -y yum-utils \ device-mapper-persistent-data \ lvm2 sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo sudo yum install docker-ce sudo systemctl enable docker sudo systemctl start docker
使用
给运行中容器增加端口映射
http://yaxin-cn.github.io/Docker/expose-port-of-running-docker-container.html
iptables -A DOCKER ! -i docker0 -o docker0 -p tcp --dport 27017 -d 172.17.0.2 -j ACCEPT iptables -t nat -A POSTROUTING -p tcp --dport 27017 -s 172.17.0.2 -d 172.17.0.2 -j MASQUERADE iptables -t nat -A DOCKER ! -i dokcer0 -p tcp --dport 27017 -j DNAT --to-destination 172.17.0.2:27017
docker run –link 说明
ETCD
每次访问 etcd 都会重定向到外网
--advertise-client-urls 外界访问当前的 url 都是通过这个参数配置的,只有出现在这个参数上的值才会被外界访问,和实际 listen 的不完全对等
v2.3.4 etcdctl unexpected status code 401
这个可以打开 debug,基本上是没有权限的
root 用户, root/guest 角色
- root 用户,在启动安全模式的时是必须的创建的,而且会被授予 root 角色
- root 角色有所有权限
- guest 没有提供认证信息的请求有那些权限
Linux
ab(apache bench)
介绍
HTTP 服务性能测试工具
awk
输出满足条件的行
awk '{if ($1 > 10) print $0}' filename # input # 1 hello # 2 world # 100 who are you # output # 100 who are you
printf
awk -F , '{printf "|%s|%s|%s|\n", $2,$4,$5}'
boot
cgroup
cpu
cgroup.clone_children cgroup.event_control cgroup.procs cpuacct.stat cpuacct.usage cpuacct.usage_percpu # 时间周期长度 cpu.cfs_period_us # 在当前 cgroup 在设置的周期长度内所能使用的 cpu 时间数 cpu.cfs_quota_us cpu.rt_period_us cpu.rt_runtime_us # cpu 的相对值 cpu.shares # cpu 统计值 cpu.stat notify_on_release tasks
memory
cgroup.clone_children cgroup.event_control # 进程 id cgroup.procs # 线程 id tasks # 内存使用量达到上限值的次数 memory.failcnt # 触发系统尽可能回收当前 cgroup 可以回收的内存 memory.force_empty # 限制内存的大小 memory.limit_in_bytes # 历史内存最大使用量 memory.max_usage_in_bytes memory.move_charge_at_immigrate memory.numa_stat memory.oom_control memory.pressure_level # 当前限制的内存软额度,当系统内存吃紧时,会回收超过 soft limit 的内存 memory.soft_limit_in_bytes # 当前内存使用情况 memory.stat memory.swappiness # 当前已使用内存 memory.usage_in_bytes # 是否将子 cgroup 的使用情况统计到当前 cgroup 中 memory.use_hierarchy notify_on_release # memsw memory.memsw.failcnt memory.memsw.limit_in_bytes memory.memsw.max_usage_in_bytes memory.memsw.usage_in_bytes # kmem memory.kmem.failcnt memory.kmem.limit_in_bytes memory.kmem.max_usage_in_bytes memory.kmem.slabinfo memory.kmem.tcp.failcnt memory.kmem.tcp.limit_in_bytes memory.kmem.tcp.max_usage_in_bytes memory.kmem.tcp.usage_in_bytes memory.kmem.usage_in_bytes
crontab
简介
主要是 linux 用来做定时任务,可以具体的分钟/小时/天/月/周
使用
- 说明
usage: crontab [-u user] file crontab [ -u user ] [ -i ] { -e | -l | -r } (default operation is replace, per 1003.2) -e (edit user's crontab) -l (list user's crontab) -r (delete user's crontab) -i (prompt before deleting user's crontab) - 备份
crontab -l > crontab.bak
- 恢复
crontab filename
- 删除
crontab -r
- 列出
crontab -l
- 编辑
crontab -e
- 间隔 2 分钟执行一次
# Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you can provide concrete values for # minute (m), hour (h), day of month (dom), month (mon), # and day of week (dow) or use '*' in these fields (for 'any').# # Notice that tasks will be started based on the cron's system # daemon's notion of time and timezones. # # Output of the crontab jobs (including errors) is sent through # email to the user the crontab file belongs to (unless redirected). # # For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command */2 * * * * command
- 间隔 5 小时执行一次
* */5 * * * command
mtr
# 分析到达特定主机的网络情况 mtr -r 8.8.8.8 # 测试到主机某个 TCP 监听端口的网络情况 mtr --tcp --port 8888 -r 8.8.8.8
netfilter
# 临时调整 conntrack table 的大小和哈希表的数量 sysctl -w net.netfilter.nf_conntrack_max=1048576 echo 262144 > /sys/module/nf_conntrack/parameters/hashsize
wireshark
sshpass -p 'xxx' ssh -o StrictHostKeyChecking=no root@hostname 'tcpdump -s 0 -U -n -w - -i br-lan not port 22' | wireshark -k -i -
nmap
# 指定网段内扫描特定端口 nmap -p 80 192.168.1.0/24
ssh
ssh config
Host github.com HostName github.com User git IdentityFile /home/haormj/.ssh/github
nslookup
解析域名指定 name server
nslookup www.baidu.com 8.8.8.8
dig
解析域名指定 name server
dig @8.8.8.8 www.baidu.com
FQA
进程内存占用分析
ubuntu18.04 无法开启 AP 热点
18.04 Ctrl Shift c 失效
直接到 Settings > Devices > KeyBoard 中对占用相关键进行修改
Performance
cpu
Nginx
FQA
workerconnections are not enough while connecting to upstream
官方文档 直接调整 worker 的连接数即可,这里的连接数是 nginx 的连接总数
events {
worker_connections 1024;
}
调整为期望大小,不过这个值调整后可能会遇到下面问题
events {
worker_connections 10000;
}
修改完配置文件后
# 测试配置文件 nginx -t # 重载配置 nginx -s reload
10000 workerconnections exceed open file resource limit: 1024
官方文档 这个问题主要是因为 nginx 支持的打开文件数量为 1024,但配置的最大连接数为 10000,可以通过在 nginx 中增加以下配置
worker_rlimit_nofile 10000;
修改完配置文件后
# 测试配置文件 nginx -t # 重载配置 nginx -s reload
Redis
FQA
aof 和 rdb 同时开启,redis 重启加载哪个文件?
https://redis.io/topics/persistence#redis-persistence
It is possible to combine both AOF and RDB in the same instance. Notice that, in this case, when Redis restarts the AOF file will be used to reconstruct the original dataset since it is guaranteed to be the most complete.
aof 文件
Cryptography
OpenSSL
RSA
# 生成 RSA 私钥 openssl genrsa -out rsa.key 2048 # 生成 RSA 公钥 openssl rsa -in rsa.key -pubout -out rsa.pub
EC
# 生成 EC 私钥 openssl ecparam -name secp256k1 -genkey -out ec.key # 生成 EC 公钥 openssl ec -in ec.key -pubout -out ec.pub
数字签名
# 签名 openssl dgst -sign private_key -out sign file # 验签 openssl dgst -verify public_key -signature sign file
校验在线证书
openssl s_client -connect haormj.xyz:443 -servername haormj.xyz -state
查看线上证书详情
openssl s_client -connect haormj.xyz:443 -servername haormj.xyz -showcerts </dev/null 2>/dev/null | sed -n '/BEGIN CERTIFICATE/,/END CERT/p' | openssl x509 -noout -text
Proxy
kcptun
profile
server
[Unit] Description=Kcptun Server Service After=storage.service After=network.target [Service] LimitNOFILE=65536 LimitNPROC=65536 Type=simple WorkingDirectory=/opt/kcptun ExecStart=/opt/kcptun/server_linux_amd64 \ -t "127.0.0.1:15789" \ -l ":28796" \ --key "it's a secrect" \ -mode fast3 \ -nocomp \ -sockbuf 16777217 \ -dscp 46 MemoryLimit=2G Restart=on-failure RestartSec=2s [Install] WantedBy=multi-user.target
client
[Unit] Description=Kcptun Client Service After=storage.service After=network.target [Service] LimitNOFILE=65536 LimitNPROC=65536 Type=simple WorkingDirectory=/opt/kcptun ExecStart=/opt/kcptun/client_linux_amd64 \ -r "x.x.x.x:28796" \ -l ":15789" \ --key "it's a secrect" \ -mode fast3 \ -nocomp \ -autoexpire 900 \ -sockbuf 16777217 \ -dscp 46 MemoryLimit=2G Restart=on-failure RestartSec=2s [Install] WantedBy=multi-user.target
shadowsocks
profile
server
[Unit] Description=Shadowsocks After=storage.service After=network.target [Service] LimitNOFILE=65536 LimitNPROC=65536 Type=simple WorkingDirectory=/opt/shadowsocks ExecStart=/opt/shadowsocks/shadowsocks-server -u Restart=on-failure RestartSec=2s [Install] WantedBy=multi-user.target
client
[Unit] Description=Shadowsocks After=storage.service After=network.target [Service] LimitNOFILE=65536 LimitNPROC=65536 Type=simple WorkingDirectory=/opt/shadowsocks ExecStart=/opt/shadowsocks/shadowsocks-local Restart=on-failure RestartSec=2s [Install] WantedBy=multi-user.target
shadowsocks2
profile
server
[Unit] Description=Shadowsocks2 After=storage.service After=network.target [Service] LimitNOFILE=65536 LimitNPROC=65536 Type=simple WorkingDirectory=/opt/shadowsocks2 ExecStart=/opt/shadowsocks2/shadowsocks2 \ -s 'ss://AEAD_CHACHA20_POLY1305:your-password@:23586' \ -verbose Restart=on-failure RestartSec=2s [Install] WantedBy=multi-user.target
client
[Unit] Description=Shadowsocks2 After=storage.service After=network.target [Service] LimitNOFILE=65536 LimitNPROC=65536 Type=simple WorkingDirectory=/opt/shadowsocks2 ExecStart=/opt/shadowsocks2/shadowsocks2 \ -c 'ss://AEAD_CHACHA20_POLY1305:your-password@[server_address]:23586' \ -verbose \ -socks :1080 \ -redir :12345 \ -u \ -udptun :8053=8.8.8.8:53,:8054=8.8.4.4:53 \ -tcptun :8053=8.8.8.8:53,:8054=8.8.4.4:53 Restart=on-failure RestartSec=2s [Install] WantedBy=multi-user.target
FQA
正向代理和反向代理?
- 正向代理: 客户端通过代理访问服务器, 由客户端发起
- 反向代理: 服务器配置代理,让客户端通过代理访问,由服务器发起
举例: 房客/中介/房东
- 正向代理: 房客->中介->房东,房客主动找中介
- 反向代理: 房客->中介<-房东,房东主动找中介
主要是主体不同,不要太过于纠结,名字而已,都称为代理也行!
Idea
- 盲目创新的背后是无知