From f2a7904c7018b3defe0a754256a0eb4b5af19703 Mon Sep 17 00:00:00 2001 From: xiaomeng79 <496096100@qq.com> Date: Thu, 6 Dec 2018 18:26:15 +0800 Subject: [PATCH] go --- ...70\347\224\250\347\232\204\345\214\205.md" | 119 +++++++++++++++--- .../1mysql/0\347\233\256\345\275\225.md" | 10 ++ ...45\350\257\242\344\274\230\345\214\226.md" | 6 + .../0\347\233\256\345\275\225.md" | 4 +- .../2k8s/2\345\221\275\344\273\244.md" | 2 +- .../0\347\233\256\345\275\225.md" | 4 + "06\345\267\245\345\205\267/list.md" | 4 +- .../0\347\233\256\345\275\225.md" | 2 + ...10\345\276\256\346\234\215\345\212\241.md" | 8 ++ ...70\350\247\201\350\256\276\350\256\241.md" | 3 +- ...37\350\275\275\345\235\207\350\241\241.md" | 16 +-- .../2\346\246\202\345\277\265.md" | 6 + ...03\347\224\250\344\274\230\345\214\226.md" | 5 + ...22\346\235\200\347\263\273\347\273\237.md" | 13 ++ 14 files changed, 172 insertions(+), 30 deletions(-) create mode 100644 "03\345\256\271\345\231\250\345\222\214\351\233\206\347\276\244/3\346\234\215\345\212\241\347\275\221\346\240\274/0\347\233\256\345\275\225.md" create mode 100644 "07\345\210\206\345\270\203\345\274\217\347\263\273\347\273\237/10\345\276\256\346\234\215\345\212\241.md" create mode 100644 "16\346\236\266\346\236\204/2\346\246\202\345\277\265.md" create mode 100644 "16\346\236\266\346\236\204/3\350\267\250\345\205\254\347\275\221\350\260\203\347\224\250\344\274\230\345\214\226.md" create mode 100644 "16\346\236\266\346\236\204/4\347\247\222\346\235\200\347\263\273\347\273\237.md" diff --git "a/01\350\257\255\350\250\200/1go/7\345\270\270\347\224\250\347\232\204\345\214\205.md" "b/01\350\257\255\350\250\200/1go/7\345\270\270\347\224\250\347\232\204\345\214\205.md" index 3961112..8f4ad03 100644 --- "a/01\350\257\255\350\250\200/1go/7\345\270\270\347\224\250\347\232\204\345\214\205.md" +++ "b/01\350\257\255\350\250\200/1go/7\345\270\270\347\224\250\347\232\204\345\214\205.md" @@ -7,18 +7,37 @@ - [heroku](https://www.heroku.com/) 持续部署 - [shields](https://shields.io/#/) 生成图标 - [katacoda](https://www.katacoda.com/) 真实模拟 +- [How-to-Make-a-Computer-Operating-System](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System) 如何做一个操作系统 + ## 包 ### 框架 -[go-micro](https://github.com/micro/go-micro) 插件话微服务框架 -[echo](https://github.com/labstack/echo) 轻量web框架 +- [go-micro](https://github.com/micro/go-micro) 插件话微服务框架 +- [echo](https://github.com/labstack/echo) 轻量web框架 +- [tango](https://github.com/lunny/tango) web中间件 +- [go-grpc-middleware](https://github.com/grpc-ecosystem/go-grpc-middleware) grpc中间件 +- [chess](https://github.com/gochenzl/chess) 棋牌游戏框架 +- [leaf](https://github.com/name5566/leaf) 游戏框架 +- [ebiten](https://github.com/hajimehoshi/ebiten) 2D游戏库 +- [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway) +- [mqtt](https://github.com/zentures/surgemq) mqtt库 +- [iris](https://github.com/kataras/iris) web框架 +- [livego](https://github.com/gwuhaolin/livego) 直播框架 +- [mqant](https://github.com/liangdas/mqant) 游戏框架 + +### 网关 + +- [traefik](https://github.com/containous/traefik) 基于容器的网关 +- [kong](https://github.com/Kong/kong) ### Metric Logging Traceing - [go-metrics](github.com/rcrowley/go-metrics) - [opentracing-go](https://github.com/opentracing/opentracing-go) +- [prometheus](https://github.com/prometheus/prometheus) +- [opencensus-go](https://github.com/census-instrumentation/opencensus-go) ### 模板 @@ -31,33 +50,95 @@ - [go-bindata](https://github.com/jteeuwen/go-bindata) 静态文件打包成二进制 -### 测试 +### 常用的库 - [testify](https://github.com/stretchr/testify) 代码测试,断言和模拟的工具包 +- [goconvey](https://github.com/smartystreets/goconvey) go测试 +- [govalidator](https://github.com/asaskevich/govalidator) 数据验证 +- [gomail](https://github.com/go-gomail/gomail) 发送邮件 +- [json](https://github.com/json-iterator/go) json编码解码 +- [configor](https://github.com/jinzhu/configor) 配置文件 +- [uuid](https://github.com/satori/go.uuid) UUID +- [mgo](https://github.com/go-mgo/mgo) mongodb +- [bolt](https://github.com/boltdb/bolt) K/V文件存储,支持事务,适合读多写少 B+树 +- [leveldb](https://github.com/golang/leveldb) [goleveldb](https://github.com/syndtr/goleveldb) K/V存储,不支持事务,适合读少写多  +- [dgraph](https://github.com/dgraph-io/dgraph) 图数据库 +- [cayley](https://github.com/cayleygraph/cayley) 图数据库 +- [influxdb](https://github.com/influxdata/influxdb) 时序数据库 +- [gohbase](https://github.com/tsuna/gohbase) hbase客户端 +- [cetus](https://github.com/Lede-Inc/cetus) mysql中间件 +- [sqlx](https://github.com/jmoiron/sqlx) 构建sql +- [sarama](https://github.com/Shopify/sarama) kafka客户端 +- [gorm](https://github.com/jinzhu/gorm) gorm +- [redigo](https://github.com/gomodule/redigo) redis客户端 -### JWT - -- [jwt](https://github.com/dgrijalva/jwt-go) JWT -### 限流 +### 算法 - [ratelimit](go.uber.org/ratelimit) 优步限流 +- [gobreaker](https://github.com/sony/gobreaker) 断路器 +- [snowflake](https://github.com/bwmarrin/snowflake) 雪花算法 -### 生成文档 +### 机器学习 -- [go-swagger](https://github.com/go-swagger/go-swagger) 生成文档,目前不支持go mod +- [CloudForest](https://github.com/ryanbressler/CloudForest) 决策树 +- [golearn](https://github.com/sjwhitworth/golearn) 机器学习 +- [goml](https://github.com/cdipaolo/goml) 机器学习 +- [gorgonia](https://github.com/gorgonia/gorgonia) 机器学习 -### 数据存储 +### 不常用的库 -- [bolt](https://github.com/boltdb/bolt) K/V文件存储,支持事务,适合读多写少 B+树 -- [leveldb](https://github.com/golang/leveldb) [goleveldb](https://github.com/syndtr/goleveldb) K/V存储,不支持事务,适合读少写多  - -### ORM - -- [gorm](https://github.com/jinzhu/gorm) - -### 验证码 +- [decimal](https://github.com/shopspring/decimal) 浮点数精度 +- [drwmutex](https://github.com/jonhoo/drwmutex) 分布式读写锁 +- [captcha](https://github.com/dchest/captcha) 验证码 +- [base64Captcha](https://github.com/mojocn/base64Captcha) 验证码 +- [jwt](https://github.com/dgrijalva/jwt-go) JWT +- [gopher-lua](https://github.com/yuin/gopher-lua) go编译lua +- [go-swagger](https://github.com/go-swagger/go-swagger) 生成文档,目前不支持go mod +- [go-socket.io](https://github.com/googollee/go-socket.io) socket.io库 +- [kcp-go](https://github.com/xtaci/kcp-go) 生产级的UDP库 +- [watcher](https://github.com/radovskyb/watcher) +- [gopsutil](https://github.com/shirou/gopsutil) go查看进程信息工具 +- [negroni](https://github.com/urfave/negroni) 原生web中间件 +- [lumberjack](https://github.com/natefinch/lumberjack) 文件滚动切分 +- [mergo](https://github.com/imdario/mergo) map和结构合并 +- [fsnotify](https://github.com/fsnotify/fsnotify) 跨平台文件变化通知 +- [httprouter](https://github.com/julienschmidt/httprouter) 路由 +- [websocket](https://github.com/gorilla/websocket) websocket库 + + +### 区块链 + +- [blockchain-tutorial](https://github.com/liuchengxu/blockchain-tutorial) + +### 需要研究的项目 + +- [gorush](https://github.com/xiaomeng79/gorush) go推送 +- [centrifugo](https://github.com/xiaomeng79/centrifugo) 语言无关的消息推送 +- [mahjong](https://github.com/jxbdlut/mahjong) 游戏麻将 + + +### 学习资料 + +- [architect-awesome](https://github.com/xingshaocheng/architect-awesome) 后端架构师技术图谱 +- [Qix](https://github.com/ty4z2008/Qix) +- [awesome-go-zh](https://github.com/chai2010/awesome-go-zh) +- [raft](https://github.com/maemual/raft-zh_cn) raft +- [DeepLearning-500-questions](https://github.com/scutan90/DeepLearning-500-questions) 深度学习 +- [nginx-book](https://github.com/taobao/nginx-book) nginx学习 +- [gonote](https://github.com/xmge/gonote) +- [golang-swaggerui-example](https://github.com/ribice/golang-swaggerui-example) +- [project-layout](https://github.com/golang-standards/project-layout) +- [php](https://github.com/JingwenTian/awesome-php) +- [night-reading-go](https://github.com/developer-learning/night-reading-go) +- [Python-100-Days](https://github.com/jackfrued/Python-100-Days) +- [project-based-learning](https://github.com/tuvtran/project-based-learning) ** +- [Halfrost-Field)](https://github.com/halfrost/Halfrost-Field) +- [CS-Notes](https://github.com/CyC2018/CS-Notes) +- [golang-open-source-projects](https://github.com/hackstoic/golang-open-source-projects) +- [awesome-blockchain-cn](https://github.com/chaozh/awesome-blockchain-cn) 区块链资料 +- [shippy](https://github.com/EwanValentine/shippy) 微服务示例 +- [The-Golang-Standard-Library-by-Example](https://github.com/polaris1119/The-Golang-Standard-Library-by-Example) go标准库 -- [captcha](https://github.com/dchest/captcha) diff --git "a/02\346\225\260\346\215\256\345\255\230\345\217\226/1mysql/0\347\233\256\345\275\225.md" "b/02\346\225\260\346\215\256\345\255\230\345\217\226/1mysql/0\347\233\256\345\275\225.md" index 7a9f4fd..74f5483 100644 --- "a/02\346\225\260\346\215\256\345\255\230\345\217\226/1mysql/0\347\233\256\345\275\225.md" +++ "b/02\346\225\260\346\215\256\345\255\230\345\217\226/1mysql/0\347\233\256\345\275\225.md" @@ -10,5 +10,15 @@ 5. [Innodb和myisam区别](./5Innodb和myisam区别.md) +6. [mysql设计规范](./6mysql设计规范.md) + +7. [数据库垂直拆分](./7数据库垂直拆分.md) + +8. [DB主从一致性架构优化](./8DB主从一致性架构优化.md) + +9. [索引](./9索引.md) + +10. [锁](./10锁.md) + diff --git "a/02\346\225\260\346\215\256\345\255\230\345\217\226/1mysql/2\346\237\245\350\257\242\344\274\230\345\214\226.md" "b/02\346\225\260\346\215\256\345\255\230\345\217\226/1mysql/2\346\237\245\350\257\242\344\274\230\345\214\226.md" index 8908a85..c49d448 100644 --- "a/02\346\225\260\346\215\256\345\255\230\345\217\226/1mysql/2\346\237\245\350\257\242\344\274\230\345\214\226.md" +++ "b/02\346\225\260\346\215\256\345\255\230\345\217\226/1mysql/2\346\237\245\350\257\242\344\274\230\345\214\226.md" @@ -13,4 +13,10 @@ myisam索引的叶子节点存储的是数据地址,innodb索引的叶子节点 如果表使用自增主键,那么每次插入新的记录,记录就会顺序添加到当前索引节点的后续位置,当一页写满,就会自动开辟一个新的页,使用非自增索引将会破坏原来的结构 +### 常见优化 + +1. 如果明确知道只有一条结果返回,limit 1能够提高效率,明确告诉数据库,让它主动停止游标移动 +2. 强制类型转换会全表扫描 +3. 只返回需要的列,能够大大的节省数据传输量,与数据库的内存使用量 +4. 负向查询肯定不能命中索引 diff --git "a/03\345\256\271\345\231\250\345\222\214\351\233\206\347\276\244/0\347\233\256\345\275\225.md" "b/03\345\256\271\345\231\250\345\222\214\351\233\206\347\276\244/0\347\233\256\345\275\225.md" index 9b8f3e8..6ec156a 100644 --- "a/03\345\256\271\345\231\250\345\222\214\351\233\206\347\276\244/0\347\233\256\345\275\225.md" +++ "b/03\345\256\271\345\231\250\345\222\214\351\233\206\347\276\244/0\347\233\256\345\275\225.md" @@ -2,4 +2,6 @@ 1. [docker](./1docker/0目录.md) -2. [k8s](./2k8s/0目录.md) \ No newline at end of file +2. [k8s](./2k8s/0目录.md) + +3. [服务网格](./3服务网格/0目录.md) \ No newline at end of file diff --git "a/03\345\256\271\345\231\250\345\222\214\351\233\206\347\276\244/2k8s/2\345\221\275\344\273\244.md" "b/03\345\256\271\345\231\250\345\222\214\351\233\206\347\276\244/2k8s/2\345\221\275\344\273\244.md" index d1c6ab5..1cf3941 100644 --- "a/03\345\256\271\345\231\250\345\222\214\351\233\206\347\276\244/2k8s/2\345\221\275\344\273\244.md" +++ "b/03\345\256\271\345\231\250\345\222\214\351\233\206\347\276\244/2k8s/2\345\221\275\344\273\244.md" @@ -3,7 +3,7 @@ #### k8s拉去私有仓库image ```shell -kubectl create secret docker-registry registry-secret --docker-server=registry.cn-shenzhen.aliyuncs.com --docker-username=mengqingfang@zingsq --docker-password=mqf19890715 --docker-email=mengqingfang@zingsq -n default +kubectl create secret docker-registry registry-secret --docker-server=registry.cn-shenzhen.aliyuncs.com --docker-username=mengqingfang@*** --docker-password= --docker-email=mengqingfang@zingsq -n default --docker-server: 仓库地址 --docker-username: 仓库登陆账号 diff --git "a/03\345\256\271\345\231\250\345\222\214\351\233\206\347\276\244/3\346\234\215\345\212\241\347\275\221\346\240\274/0\347\233\256\345\275\225.md" "b/03\345\256\271\345\231\250\345\222\214\351\233\206\347\276\244/3\346\234\215\345\212\241\347\275\221\346\240\274/0\347\233\256\345\275\225.md" new file mode 100644 index 0000000..5761455 --- /dev/null +++ "b/03\345\256\271\345\231\250\345\222\214\351\233\206\347\276\244/3\346\234\215\345\212\241\347\275\221\346\240\274/0\347\233\256\345\275\225.md" @@ -0,0 +1,4 @@ +## 目录 + +- [istio](https://github.com/istio/istio) +- [官网](https://istio.io) diff --git "a/06\345\267\245\345\205\267/list.md" "b/06\345\267\245\345\205\267/list.md" index a1782f4..fb00248 100644 --- "a/06\345\267\245\345\205\267/list.md" +++ "b/06\345\267\245\345\205\267/list.md" @@ -1 +1,3 @@ -1. https://asciinema.org/ 命令行记录 \ No newline at end of file +1. https://asciinema.org/ 命令行记录 +2. https://github.com/buger/goreplay 流量重放 +3. https://github.com/erguotou520/electron-ssr \ No newline at end of file diff --git "a/07\345\210\206\345\270\203\345\274\217\347\263\273\347\273\237/0\347\233\256\345\275\225.md" "b/07\345\210\206\345\270\203\345\274\217\347\263\273\347\273\237/0\347\233\256\345\275\225.md" index b69c214..82a6d4c 100644 --- "a/07\345\210\206\345\270\203\345\274\217\347\263\273\347\273\237/0\347\233\256\345\275\225.md" +++ "b/07\345\210\206\345\270\203\345\274\217\347\263\273\347\273\237/0\347\233\256\345\275\225.md" @@ -23,3 +23,5 @@ 8. [一致性协议](./8一致性协议.md) 9. [服务发现](./9服务发现.md) + +10. [微服务](./10微服务.md) diff --git "a/07\345\210\206\345\270\203\345\274\217\347\263\273\347\273\237/10\345\276\256\346\234\215\345\212\241.md" "b/07\345\210\206\345\270\203\345\274\217\347\263\273\347\273\237/10\345\276\256\346\234\215\345\212\241.md" new file mode 100644 index 0000000..67ad357 --- /dev/null +++ "b/07\345\210\206\345\270\203\345\274\217\347\263\273\347\273\237/10\345\276\256\346\234\215\345\212\241.md" @@ -0,0 +1,8 @@ +## 微服务 + +### 解决什么问题 +1. 代码到处拷贝 +2. 消除复杂性扩散(一处BUG处处修改,专注性,屏蔽底层复杂度) +3. SQL质量得不到保障,业务相互影响(拒绝其他业务直接操作数据层) +4. 调用方爽(像操作一个本地函数) +5. 提供有限接口,无限性能 \ No newline at end of file diff --git "a/16\346\236\266\346\236\204/000\345\270\270\350\247\201\350\256\276\350\256\241.md" "b/16\346\236\266\346\236\204/000\345\270\270\350\247\201\350\256\276\350\256\241.md" index 7efb9a2..72daacd 100644 --- "a/16\346\236\266\346\236\204/000\345\270\270\350\247\201\350\256\276\350\256\241.md" +++ "b/16\346\236\266\346\236\204/000\345\270\270\350\247\201\350\256\276\350\256\241.md" @@ -1,3 +1,4 @@ ## 常见设计 -1. [商品SKU设计](https://blog.csdn.net/wwwdc1012/article/details/71774280/) \ No newline at end of file +1. [商品SKU设计](https://blog.csdn.net/wwwdc1012/article/details/71774280/) + diff --git "a/16\346\236\266\346\236\204/1\350\264\237\350\275\275\345\235\207\350\241\241.md" "b/16\346\236\266\346\236\204/1\350\264\237\350\275\275\345\235\207\350\241\241.md" index 87687a2..9d75463 100644 --- "a/16\346\236\266\346\236\204/1\350\264\237\350\275\275\345\235\207\350\241\241.md" +++ "b/16\346\236\266\346\236\204/1\350\264\237\350\275\275\345\235\207\350\241\241.md" @@ -4,6 +4,8 @@ [参考](http://lobert.iteye.com/blog/2159970) +[架构之家](https://mp.weixin.qq.com/s/4dzqbh2wfzbQzgFodP2_6Q) + 根据服务器的能力(硬件),承担相应的工作,是解决高性能,单点故障(高可用),扩展性(水平伸缩)的终极解决方案 ### 作用 @@ -33,15 +35,12 @@ **一般将DNS作为第一级负载均衡,A记录对应着内部负载均衡的IP地址** -##### 特性 - -1. 可以根据用户IP来进行智能解析。DNS服务器可以在所有可用的A记录中寻找离用记最近的一台服务器。 -2. 动态DNS:在每次IP地址变更时,及时更新DNS服务器。当然,因为缓存,一定的延迟不可避免。 ##### 缺点 -1. 各级节点的DNS服务器不同程序的缓存会让你晕头转向 -2. 无法根据实际服务器的实时负载差异来调整调度策略 +1. 扩容非实时 +2. 非高可用,只负责解析ip,不负责探活 +3. 暴露太多外网ip #### 反向代理负载均衡 @@ -55,7 +54,10 @@ ##### 缺陷 -对反向代理服务器要求高,需要keeplive监控心跳 +对反向代理服务器要求高,需要keeplive监控心跳,单机有上限和时延增加 + +#### LVS +lvs:Linux Virtual Server,使用集群技术,实现在linux操作系统层面的一个高性能、高可用、负载均衡服务器 #### IP负载均衡(LVS-NAT) diff --git "a/16\346\236\266\346\236\204/2\346\246\202\345\277\265.md" "b/16\346\236\266\346\236\204/2\346\246\202\345\277\265.md" new file mode 100644 index 0000000..e97b988 --- /dev/null +++ "b/16\346\236\266\346\236\204/2\346\246\202\345\277\265.md" @@ -0,0 +1,6 @@ +## 概念 + +### 高可用 +通过设计减少程序不可访问的时间 +### 高并发 +通过设计让程序能够在单位时间内处理更多的请求 \ No newline at end of file diff --git "a/16\346\236\266\346\236\204/3\350\267\250\345\205\254\347\275\221\350\260\203\347\224\250\344\274\230\345\214\226.md" "b/16\346\236\266\346\236\204/3\350\267\250\345\205\254\347\275\221\350\260\203\347\224\250\344\274\230\345\214\226.md" new file mode 100644 index 0000000..e2364b2 --- /dev/null +++ "b/16\346\236\266\346\236\204/3\350\267\250\345\205\254\347\275\221\350\260\203\347\224\250\344\274\230\345\214\226.md" @@ -0,0 +1,5 @@ +## 跨公网调用第三方服务 + +- 业务能接受旧数据:读取本地数据,异步代理定期更新数据 +- 有多个第三方服务提供商:多个第三方互备(短信) +- 向第三方同步数据:本地写成功就算成功,异步向第三方同步数据 \ No newline at end of file diff --git "a/16\346\236\266\346\236\204/4\347\247\222\346\235\200\347\263\273\347\273\237.md" "b/16\346\236\266\346\236\204/4\347\247\222\346\235\200\347\263\273\347\273\237.md" new file mode 100644 index 0000000..6a44d11 --- /dev/null +++ "b/16\346\236\266\346\236\204/4\347\247\222\346\235\200\347\263\273\347\273\237.md" @@ -0,0 +1,13 @@ +## 秒杀系统: + +### 思路 + +1. 将请求拦截在上游 +2. 充分利用缓存 + +#### 具体方案 + +- 客户端层: 按钮置灰,禁止用户重复提交请求; +- 客户端层:JS限制用户在x秒之内只能提交一次请求 +- 站点层: 页面缓存,返回同一个页面,同一个用户限流 +- 服务层: 请求队列,超量直接返回"已售完" \ No newline at end of file