推荐
最新
Xcode
use
https://developer.apple.com/downloads/index.action
http://alcatraz.io/
Shourtcuts
command + 0/1: toggle some barcommand + b: build, command+shift+k:clean, command + .:build stopcommand + r: build + runcommand + y: build + debugcommand + \: toggle breakpointcommand + []: tabcommand + shift + re: stop run or debugcommand + shift + n: new projectcommand + shift + o: ctrlp,定位文件或方法,支持缩写command + option + s: save allctrl + command + J: jump to definitionctrl + command + -->: forward/backwardctrl + command + Up: switch between .h or .m/.cpp fileF6: step overF7: step intoF8: step out
Snippets
singleflight
// 执行并返回给定函数的结果,确保对于给定的键+fn只执行1次
// 如果有重复的进来,重复的调用者会等待最原始的调用完成并收到相同的结果
// 返回值 shared 指示是否将 v 提供给多个调用者
// 返回值 v 是 fn 的执行结果
// 返回值 err 是 fn 返回的 err
func (g *Group) Do(key string, fn func()(any, error)) (v any, err error, shared bool)
// 和 Do 类似,但返回一个 channel, 用来接收结果. Result 是一个结构体,有3个字段(Do返回的那3个)
func (g *Group) DoChan(key string, fn func() (any, error)) <-chan Result
// 不走Do的流程,直接调用fn回调
func (g *Group) Forget(key string)
Supervisor
https://github.com/ochinchina/supervisord
http://supervisord.org/configuration.html
go generate
GOOS=linux go build -tags release -a -ldflags "-linkmode external -extldflags -static" -o supervisord
systemctl enable supervisord # supervisord -c /etc/supervisord.conf -d
# supervisor.conf
# 查找路径:
# $CWD/supervisord.conf; $CWD/etc/supervisord.conf
# /etc/supervisord.conf; /etc/supervisor/supervisord.conf
# ../etc/supervisord.conf; ../supervisord.conf
# http服务,提供web管理界面
[inet_http_server]
port=0.0.0.0:9001
username=user
password=123
[supervisord]
logfile=/tmp/supervisord.log
logfile_maxbytes=50MB # 0表示不限制大小
logfile_backups=8 # 日志备份数量,0表不备份
loglevel=info
nodaemon=false
[supervisorctl]
serverurl=http://127.0.0.1:9001 # 通过http方式连接supervisord
[include]
files=*.ini # 包含其他配置文件,如下方的程序xx
[program-default] # 公共参数
environment=ENV="/xx",VAR2=""
[program:xx] # 被管理的一个进程
command=/opt/tomcat.sh run
directory=/opt
autostart=true # supervisord启动时也自动启动
autorestart=true # 程序退出后自动重启; unexpected:进程被意外杀死后才重启
startretries=3 # 启动失败自动重试次数,默认3
startsecs=8 # 启动8s后没有异常退出旧表示正常启动,默认1s
user=tomcat # 以哪个用户启动进程
priority=9 # 进程启动的优先级,值小的优先启动
redirect_stderr=true # 把stderr重定向到stdout,默认false
stdout_logfile=/opt/tomcat.log, /dev/stdout, syslog # 也可指定stderr_logfile; 此处指定多个输出
stdout_logfile_maxbytes=20MB # 默认50MB
stdout_logfile_backups=8
stopasgroup=false # 进程被杀死时是否向这个进程组发送stop信号,默认false
killasgroup=false # 向进程发送kill信号时包括子进程,默认false
restartpause=2s # stop后再次start这之间的间隔
restart_when_binary_changed=true # 默认false
supervisorctl status # 查看所有进程的状态
supervisorctl stop es
supervisorctl start es
supervisorctl restart es
Rap
https://github.com/thx/RAP/wiki/deploy_on_centos_cn
https://github.com/thx/RAP/releases
https://www.showdoc.com.cn/
# 若要去掉验证码请下载源码,然后搜索.最后重新部署相关文件(大概4个)到下面的目录.
# 注意:运行的真是地址可能在:/var/lib/tomcat/webapps/ROOT
yum -y install nginx tomcat unzip redis
unzip -x RAP-... -d ROOT
create database rap_db default charset utf8mb4 collate utf8_general_ci;
grant all on rap_db.* to rap@localhost identified by 'password';
flush privileges;
mysql -u rap -p rap_db < ROOT/WEB-INF/classes/database/initialize.sql
vim ROOT/WEB-INF/classes/config.properties
jdbc.username=rap
jdbc.password=..
redis.host=192.168.0.2 # 注意:一定要写本机的ip不要写成127,否则外面访问不了
cp -rf ROOT /var/lib/tomcat/webapps
chown -R tomcat /var/lib/tomcat/webapps/ROOT
systemctl restart redis
systemctl restart tomcat
System
basic
uptime; lsmem(free -h); lscpu; lspci|grep -i vga; lsblk -f; fdisk -l(/etc/fstab)
df -Th # 分区信息,T:也显示分区的类型如ext4;
du -h --max-depth=1 /tmp/*
ethtool eth0 # 查看网卡信息. -i:驱动信息 -S:网卡的状态(接收或发送多少包等)
ifdown eth0 # 激活网卡!ifup.
service network restart # 重启网络服务
dhclient eth3 # 使网卡自动获取IP
ifconfig eth0 192.168.1.122 netmask 255.255.255.0 up # 临时改变并生效,但配置文件未变
route add default gw 192.168.1.1 [dev.eth0]
route # 打印路由信息,包括网关!
security
# /var/log/secure: 用户登录系统的信息.比如 ssh telnet ftp等
# /var/log/messages: 系统日志
# /var/log/cron: crontab信息
lastlog # 所有用户最后一次的登录记录; last是所有用户登录注销等记录
lastb|more # 错误登录记录: /var/log/btmp(last最后登录失败的信息,被编码过)
cat /var/log/secure|grep 'Invalid user' # 系统的详细的登录记录,如: ssh su sudu useradd userdel passwd
cat /var/log/cron # 定时任务日志
stat file # 查看某个文件的修改记录
strace exe # 跟踪下程序
# 锁定文件(禁止删除)
lsattr x # 查看属性
chattr +i x # -i:解除锁定
# 修改文件时间戳
touch -r x o # 把x的时间戳赋给o
toutch -t 1401021042 x
# 隐藏操作历史
set +o history # 注意有空格: set -o history: 恢复
history |grep "keyword"
history -d 123 # 根据上面的查询删除
# 异常端口
netstat -tnlp
# (-i:@192..:22)根据IP查看外连情况
lsof -inP # 查看使用网络的所有进程; (-i:PORT)根据端口查看外连情况或者直接iftop!
lsof fileOrdir # 查看与指定文件/目录交互的所有进程
lsof -c syslog-ng # 查看命令正在使用的文件和网络; -t:只返回PID
lsof -p PID # 查看进程已打开的内容
lsof -u root # 显示指定用户打开了什么; (-u ^root)除置顶用户外; 杀死指定用户所有动作(kill -9 `lsof -t -u lei`)
# erase disk
# -f: --force,必要时修改权限以使目标可写
# -n: 随机写多少次,默认3次.
# -u: --remove,覆盖后截断并删除文件.注意擦除/dev/sda2等设备不应使用该参数!
# -z: 最后一次使用0覆盖!
shred -f file1 file2
firewall
# -A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT
vim /etc/sysconfig/iptables
systemctl restart firewalld # start enable ...
firewall-cmd --zone=public --list-ports
firewall-cmd --zone=public --add-port=80-83/tcp --permanent
firewall-cmd --zone=public --remove-port=22/tcp --permanent
firewall-cmd --add-service vncserver --permanent
firewall-cmd --reload
iptables
/etc/sysconfig/iptables
Net Traffic
https://github.com/raboof/nethogs
https://www.nirsoft.net/utils/cports.html
| terminology | description |
|---|---|
QPS | queries per seconds. 如执行了DB的select操作qps+1. |
TPS | transaction/s. 事务,多个q的组合,业务层面的! |
PV | page view,页面被浏览的次数; 如打开/刷新一个网页那么这个网站的pv就+1 |
RV | repeat,重复访问者数量! |
UV | unique,访客数量,如一台电脑算作一个访客. |
iftop
右边三列分别是10,20,40s平均流量
Kong
openrestry(nginx+luajit) + webadmin
https://konghq.com/ https://docs.konghq.com/
https://github.com/pantsel/konga
https://github.com/kevholditch/gokong
默认他们都存储在db;service与route是最常用的两个概念!
Gateway
istio/Envoy
https://github.com/envoyproxy/envoy
https://www.envoyproxy.io/
- 服务网格,流量控制,istio也集成了网关的能力(南北流量控制)
- mesh的主要着力点还是东西流量控制(服务间流量)
- 支持ws,http2,gRPC代理; 较Nginx效率更高些
traefik 39.2k
Krakend
https://www.krakend.io/
https://github.com/devopsfaith/krakend-examples
https://github.com/devopsfaith/krakendesigner
{
"version": 2,
"name": "",
"port": 8000,
"timeout": "3s", // 也可放在endpoint中,单独限制
"tls": {
"public_key": "/path/to/cert.pem",
"private_key": "/path/to/key.pem"
}
"endpoints": [
"endpoint": "/api/v1/foo-bar",
"method": "GET",
"timeout": "800ms",
"concurrent_calls": 3, // 一般不配置,和负载host两码事,这是并发向一个后端请求,择其快者
"headers_to_pass": ["Authorization", "Content-Type"]
"extra_config": {
"maxRate": 5000, // ==0不限制!针对该endpoint的qps
"clientMaxRate": 0, // ==0不限制!针对每一个client(ip)的qps
"strategy": "header", // 默认按照ip来区分client
"key": "X-Auth-Token" // 按照header中的该key来鉴定一个client
},
"headers_to_pass": [ // 向下游传递哪些Headers,"*"表所有
"Cookies" // 默认传递"Host","User-Agent","Accept-Encoding","X-Forward-For
],
"querystring_params":[ // 向下游传递哪些请求参数
"a", "b" // 只是指定那些key的参数可以向后传递,若实际没有传递则还是没有; "*"表传递所有
]
// 添加多个backend会自动merge
// header中指示是否全部完成: X-Krakend-Completed: false
"backend": [
{
"url_pattern": "/users/{user}?name={name}" // /users/1?name=lei,强制带参数,否则返回404.除非指定querystring,此时可不指定name(自动使用前面的值)
"host": ["http://127.0.0.1:8000"],
"encoding": "json", // 改变原来的编码格式,xml,rss
"group": "newkeyname", // merge时作为rsp中一个单独的keyname
"target": "data", // 剥离原返回中的data键,里面的value作为根
"mapping": {
"email": "personal_email" // 修该rsp中的key
}
}
{
"url_pattern": "/foo",
"extra_config": {
"github.com/devopsfaith/krakend-circuitbreaker/gobreaker": {
"interval": 60, // 60s后端调用失败4次,后面的所有调用都延迟10s
"maxErrors": 4, // 当有任何一次成功时,线路恢复
"timeout": 10,
"logStatusChange": true
},
"github.com/devopsfaith/krakend/proxy": {
"shadow": true // 方便新接口线上测试,会copy一份req,当并不会rsp给client
}
}
}
]
]
}



















