├── .gitignore ├── .image ├── io_perf.png ├── iostat.png ├── mem.png ├── mem_tool.png ├── perf.png ├── perf_tool.png ├── 数组存储完全二叉树.png ├── 时间复杂度.png └── 逆领接表.png ├── 00操作系统 ├── 0目录.md ├── 1概念.md ├── 2进程与线程.md ├── 3存储管理.md ├── 4文件系统.md ├── 5输入输出.md ├── 6多处理机.md ├── 7windows.md └── image │ ├── page_tran_al.png │ └── 内存层次结构.png ├── 01语言 ├── 0目录.md ├── 1go │ ├── 0目录.md │ ├── 10内存管理.md │ ├── 11pprof.md │ ├── 12优化.md │ ├── 13协程.md │ ├── 14timer使用.md │ ├── 15map.md │ ├── 16channel.md │ ├── 17interface.md │ ├── 18context.md │ ├── 19反射.md │ ├── 1http.md │ ├── 20defer.md │ ├── 21锁.md │ ├── 2mysql.md │ ├── 3分布式跟踪.md │ ├── 4命令和工具.md │ ├── 5测试.md │ ├── 6注意点.md │ ├── 7常用的包.md │ ├── 8使用问题.md │ ├── 9GPM.md │ ├── code │ │ ├── elastic │ │ │ └── main.go │ │ ├── fragment │ │ │ ├── callback.go │ │ │ └── chan.go │ │ ├── makefile │ │ │ ├── README.md │ │ │ ├── go-tool.make │ │ │ └── setPath.sh │ │ ├── tmp │ │ │ └── stackorheap.go │ │ ├── web │ │ │ └── main.go │ │ └── write │ │ │ └── zip.go │ ├── pkg │ │ ├── 0目录.md │ │ └── 1unsafe.md │ └── rpc │ │ ├── 0目录.md │ │ ├── cli │ │ └── rpc_client.go │ │ └── srv │ │ └── rpc_server.go ├── 2c │ └── 0目录.md ├── 3shell │ ├── 0目录.md │ ├── 1概念.md │ └── 3命令.md ├── 4python │ ├── 0目录.md │ ├── 1常见问题.md │ ├── 2常用的库.md │ ├── 3工具使用.md │ └── lib │ │ ├── README.md │ │ ├── matplotlib.md │ │ ├── numpy.md │ │ ├── pandas.md │ │ └── seaborn.md ├── 5webassembly │ ├── 0目录.md │ └── 1概念.md ├── 6javascript │ └── 0目录.md ├── 7rust │ ├── mod理解.md │ ├── 宏.md │ ├── 工具.md │ ├── 常用库 │ │ └── log4rs.md │ ├── 所有权.md │ ├── 智能指针.md │ ├── 点.md │ └── 目录.md ├── 8node │ ├── 关键点.md │ ├── 命令.md │ └── 目录.md └── 9dart-flutter.md ├── 02数据存取 ├── 0目录.md ├── 10clickhouse.md ├── 11starocks.md ├── 1mysql │ ├── 0目录.md │ ├── 10快照读.md │ ├── 1基本架构.md │ ├── 2执行计划.md │ ├── 3日志.md │ ├── 4索引.md │ ├── 5事务和锁.md │ ├── 6优化.md │ ├── 7配置.md │ ├── 8工具.md │ ├── 9其他.md │ ├── full.sh │ └── mysql_jg.png ├── 2bolt │ └── 0目录.md ├── 3influxdb.md ├── 4Hbase.md ├── 5Redis.md ├── 6TiDB.md ├── 7oracle │ ├── 0目录.md │ ├── 1执行计划.md │ ├── 2常用的命令.md │ ├── 3窗口函数.md │ └── 4数据库创建.md ├── 8postgres │ ├── .images │ │ ├── jg.jpeg │ │ └── postgresSQL流程.png │ ├── 0目录.md │ ├── 10压力测试.md │ ├── 11特殊类型操作.md │ ├── 12全文检索.md │ ├── 13窗口函数和with语法.md │ ├── 14分区表.md │ ├── 15测试数据.md │ ├── 16数据库之间的比较.md │ ├── 17FDW的使用.md │ ├── 18数据库监控.md │ ├── 19插件.md │ ├── 1版本迭代.md │ ├── 20配置.md │ ├── 2核心架构.md │ ├── 3日志.md │ ├── 4索引.md │ ├── 5事务和锁.md │ ├── 6优化.md │ ├── 7执行计划.md │ ├── 8应用场景.md │ ├── 9数据复制订阅.md │ ├── fdw_dockerfile │ │ ├── README.md │ │ └── docker-compose-redis.yaml │ └── 数据复制订阅 │ │ ├── config │ │ ├── mysql │ │ │ ├── init.sql │ │ │ ├── my.cnf │ │ │ └── user.sql │ │ └── postgres │ │ │ ├── createdb.sql │ │ │ ├── pg_hba.conf │ │ │ └── postgresql.conf │ │ ├── docker-compose.yml │ │ ├── 数据同步与订阅.md │ │ └── 数据同步与订阅第三方程序 │ │ ├── .gitignore │ │ ├── README.md │ │ ├── config.json │ │ ├── docker-compose.yaml │ │ ├── pg_config.sh │ │ ├── pgconfig │ │ ├── createdb.sql │ │ ├── pg_hba.conf │ │ └── postgresql.conf │ │ └── preconfig │ │ ├── alertmanager.yml │ │ ├── node_down.yml │ │ └── prometheus.yml ├── 9分布式文件系统.md ├── mongo.md └── starocks_chain.md ├── 03容器和集群 ├── 0目录.md ├── 1docker │ ├── 0目录.md │ └── 1常见问题.md ├── 2k8s │ ├── 0目录.md │ ├── 1安装.md │ ├── 2命令.md │ ├── service.md │ └── 配置文件 │ │ ├── rbac.yaml │ │ └── 资源限制.yaml ├── 3服务网格 │ ├── 0目录.md │ ├── 1概念.md │ ├── 2常用命令.md │ └── 3k3s安装istio.md ├── 4helm.md └── 5virt-manager.md ├── 04linux ├── 0目录.md ├── 1常用命令.md ├── 2优化.md ├── 3概念.md ├── 4工具.md ├── 5显(N)卡安装.md ├── 6nfs安装.md └── 7iptables.md ├── 05大数据 ├── 0Hadoop.md ├── 0目录.md ├── 1Hive.md ├── 2Sqoop.md ├── 3Spark.md ├── 4HBase.md ├── hadoop2.png ├── hadoop2.xml ├── hbase_01.png ├── hbase_data.png ├── hbase_memstore.png └── 数据同步.md ├── 06工具 ├── 0目录.md ├── 1git │ ├── 0目录.md │ ├── 1命令.md │ ├── 2生成changelog.md │ └── 3常见问题.md ├── 2UML │ ├── 0目录.md │ ├── 1用例图.md │ └── 2类图.md ├── 3Makefile │ ├── 0目录.md │ └── 1概念.md ├── 5wget.md ├── 6ssr.md ├── 7bazel.md ├── 8markdown.md ├── 9vscode.md ├── ai.md ├── chatgpt.md ├── dockerimage.md ├── list.md ├── mac.md ├── 实用工具.md ├── 有趣的项目.md └── 运维工具.md ├── 07分布式系统 ├── 0目录.md ├── 10微服务.md ├── 11调度器.md ├── 12熔断.md ├── 1事务.md ├── 2限流.md ├── 3分布式锁.md ├── 4分布式Id生成器.md ├── 5延时任务系统.md ├── 6分布式搜索.md ├── 7负载均衡.md ├── 8一致性协议.md └── 9服务发现.md ├── 08测试 ├── 0目录.md └── 1jmeter │ ├── 0目录.md │ ├── jmeter使用.md │ └── jmeter测试mysql.md ├── 09消息队列 ├── 0目录.md ├── 1概念和特性.md ├── 2对比.md ├── 3RabbitMQ.md ├── 4Kafka.md └── 5Plusar.md ├── 10ELK ├── 01es │ ├── 0目录.md │ ├── 1概念特性.md │ ├── 2curl操作.md │ ├── 3聚合分析.md │ ├── 4并发控制.md │ ├── 5特性操作.md │ ├── 6数据同步.md │ └── 7使用的问题.md └── 0目录.md ├── 11机器学习 ├── 0目录.md ├── 1学习资料.md ├── 2概念.md ├── 3神经网络.md ├── 4图像识别.md ├── jq.png └── sklearn │ ├── 0目录.md │ ├── 1数据处理.md │ ├── 2特征选择.md │ ├── 3模型建立.md │ ├── 4模型验证和参数选择.md │ ├── 5模型打分.md │ ├── code │ └── 50_start.ipynb │ ├── data │ └── 50_start.csv │ └── image │ └── scikit_learn.jpeg ├── 12协议和概念 ├── 0目录.md ├── 10Iass-Pass-Sass.md ├── 1protobuf.md ├── 2http.md ├── 3JWT.md ├── 4Raft.md ├── 5CAS机制.md ├── 6同步异步阻塞非阻塞.md ├── 7TCP协议.md ├── 8IPC.md ├── 9OSI模型.md └── image │ ├── four.png │ └── three.png ├── 13区块链 ├── 0目录.md ├── 1概念.md ├── 2资料.md ├── Rosetta.md ├── coins │ ├── btc.md │ ├── cosmos.md │ ├── dot.md │ ├── eos.md │ ├── eth.md │ ├── kda.md │ ├── polygon.md │ ├── solana.md │ ├── sui.md │ ├── ton.md │ ├── tron.md │ └── xrp.md ├── contract │ ├── eth.md │ ├── solidity.md │ ├── 合约安全.md │ ├── 合约示例.md │ ├── 开发工具.md │ └── 闪兑.md ├── go-package.md ├── images │ ├── bc.jpg │ ├── block-hash.jpg │ ├── blockchainlayer.png │ ├── compressed-address.jpg │ ├── gs.jpeg │ └── l2.png ├── infura.csv ├── layer2 │ ├── Readme.md │ └── zksync.md ├── p2p.md ├── socialFi.md ├── staking.md ├── substrate.md ├── 交易所钱包.md ├── 侧链.md ├── 原理 │ ├── p2p.md │ ├── 共识.md │ ├── 原理.md │ ├── 原理2.md │ └── 原理3.md ├── 存储.md ├── 开发工具.md ├── 数据恢复和溯源设计 │ ├── 数据恢复与数据溯源设计.md │ ├── 日志上链.png │ └── 日志上链.xml ├── 数据解析 │ ├── eth.md │ └── solana.md ├── 第三方节点.md ├── 讲解.md ├── 重要概念.md ├── 钱包.md └── 链上分析.md ├── 14数据结构和算法 ├── 0目录.md ├── 1数据结构.md ├── 2一致性哈希算法.md ├── 3算法.md └── 4算法思路.md ├── 15密码学 ├── 0目录.md ├── 1概念.md ├── 2对称加密.md ├── 3非对称加密.md ├── 4数字签名.md └── 5单向加密.md ├── 16架构 ├── 000常见设计.md ├── 0目录.md ├── 1负载均衡.md ├── 2概念.md ├── 3接口高可用.md ├── 4秒杀系统.md ├── 5缓存.md ├── 6qps和tps.md ├── 7设计模式.md ├── 8处理连锁故障.md ├── 9低代码平台.md └── 架构.xml ├── 17基础设施 ├── 0目录.md ├── 1Logging.md ├── 2Tracing.md ├── 3Metrics.md ├── 4Gateway.md ├── 5PKI.md ├── monitor │ ├── README.md │ ├── docker-compose.yml │ └── etc │ │ ├── blackbox │ │ └── blackbox.yml │ │ ├── grafana │ │ ├── dashboards │ │ │ ├── blackbox-exporter-9965.json │ │ │ ├── clickhouse-13606.json │ │ │ └── node-exporter-8919.json │ │ └── grafana.ini │ │ ├── node_exporter │ │ ├── install.sh │ │ └── node_exporter.service │ │ ├── port │ │ ├── README.md │ │ └── listen.sh │ │ ├── prometheus │ │ └── prometheus.yml │ │ └── prometheusalert │ │ ├── app.conf │ │ ├── email.tpl │ │ └── feisu.tpl └── nginx.conf ├── 18安全与加密 ├── 0目录.md ├── 1CSRF.md ├── 2XSS.md ├── 3重放攻击.md ├── 4数据过滤.md ├── 5SQL注入.md ├── 6密码加密.md └── 7反爬虫.md ├── 19程序数学 ├── 0目录.md ├── 1原码反码补码.md ├── 2位运算.md ├── 3数学概念.md └── 4贝叶斯定理.md ├── 20自动化 ├── .gitignore ├── .gitlab-ci.yml ├── Dockerfile ├── FAQ.md ├── Jenkinsfile ├── Jenkinsfile.script ├── KubernetesPod.yaml ├── Makefile ├── README.md ├── dev.yaml ├── gitlab-runner-0.18.1.tgz ├── go.mod ├── go.sum ├── main.go └── main_test.go ├── 21机器学习算法 ├── 0目录.md ├── 10隐马尔科夫模型.md ├── 11条件随机场.md ├── 12线性回归.md ├── 13随机梯度下降.md ├── 14xgboost.md ├── 15关联分析.md ├── 1概念.md ├── 2感知机.md ├── 3K近邻法.md ├── 4朴素贝叶斯法.md ├── 5决策树.md ├── 6逻辑斯谛回归和最大熵模型.md ├── 7支持向量机.md ├── 8集成学习.md └── image │ └── 方差.jpg ├── 22英语学习 ├── 0目录.md └── 1资料.md ├── 23哲学 ├── 0目录.md ├── 1资料.md ├── 2经典语句.md └── 易经.md ├── 24深度学习 ├── .image │ └── lstm.jpeg ├── 0目录.md ├── 10度量.md ├── 11距离度量.md ├── 12名词理解.md ├── 1资料.md ├── 2概念.md ├── 3激活函数.md ├── 4反向传播算法.md ├── 5卷积神经网络.md ├── 6迁移学习.md ├── 7循环神经网络.md ├── 8优化器.md ├── 9损失函数.md └── tensorflow │ ├── 0目录.md │ ├── 1名称解释.md │ └── 2常用参数解释.md ├── 25AI应用 ├── 0目录.md ├── 0资料.md ├── 1视觉处理.md ├── 2语言处理.md ├── 3人脸识别.md ├── 4文字处理.md ├── 5目标检测.md ├── 6注意力机制.md ├── 7GAN.md ├── 8sd.md ├── cv │ └── README.md ├── image │ ├── conv2wndows.png │ └── full2conv.png ├── 医疗 │ └── README.md └── 框架 │ ├── README.md │ ├── paddlepaddle.md │ ├── sbert.md │ ├── transformers.md │ └── 模型蒸馏.md ├── 26AI优化 ├── 0目录.md ├── 1过拟合和欠拟合.md ├── 2梯度下降.md ├── 3正交化.md ├── 4卷积网络.md ├── 5残差网络.md ├── 6迁移学习.md ├── 7数据增强.md └── image │ └── full2conv.png ├── 27书籍资料 ├── 0目录.md ├── 从一到无穷大.md └── 投资.md ├── 28物联网 ├── db.png ├── 协议.md ├── 特点.md └── 目录.md ├── 29规范 ├── api.md ├── 工程化.md └── 目录.md ├── 30音视频 ├── webrtc.md └── 目录.md ├── 31个人创业 └── 目录.md ├── 32旅行 ├── 常备清单.md └── 目录.md ├── 33科学上网 └── 目录.md ├── 34中医 ├── README.md └── 好言.md ├── 35失业指南 └── README.md ├── LICENSE ├── README.md └── _config.yml /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | .vscode 14 | .DS_Store 15 | -------------------------------------------------------------------------------- /.image/io_perf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/.image/io_perf.png -------------------------------------------------------------------------------- /.image/iostat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/.image/iostat.png -------------------------------------------------------------------------------- /.image/mem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/.image/mem.png -------------------------------------------------------------------------------- /.image/mem_tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/.image/mem_tool.png -------------------------------------------------------------------------------- /.image/perf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/.image/perf.png -------------------------------------------------------------------------------- /.image/perf_tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/.image/perf_tool.png -------------------------------------------------------------------------------- /.image/数组存储完全二叉树.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/.image/数组存储完全二叉树.png -------------------------------------------------------------------------------- /.image/时间复杂度.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/.image/时间复杂度.png -------------------------------------------------------------------------------- /.image/逆领接表.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/.image/逆领接表.png -------------------------------------------------------------------------------- /00操作系统/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | [通俗讲解操作系统](https://tech.hqew.com/news_2060764) 3 | 4 | - [概念](1概念.md) 5 | 6 | - [进程与线程](2进程与线程.md) 7 | 8 | - [存储管理](3存储管理.md) 9 | 10 | - [文件系统](4文件系统.md) 11 | 12 | - [输入输出](5输入输出.md) 13 | 14 | - [多处理机](6多处理机.md) 15 | 16 | - [windows](7windows.md) 17 | -------------------------------------------------------------------------------- /00操作系统/1概念.md: -------------------------------------------------------------------------------- 1 | ## 概念 2 | 3 | ##### RAM(Random Access Memory) 4 | 随机存取存储器,也叫主存,特点:随机存取/易失性/对静电敏感/读写速度快 5 | 6 | ##### ROM(Read-Only Memory) 7 | 只读内存,如:BIOS -------------------------------------------------------------------------------- /00操作系统/2进程与线程.md: -------------------------------------------------------------------------------- 1 | ## 进程与线程 2 | 3 | - [进程线程协程的区别](https://mp.weixin.qq.com/s/vW5n_JWa3I-Qopbx4TmIgQ) 4 | 5 | ### 进程 6 | 每一个进程有一个地址空间和一个控制线程 7 | 8 | ##### 进程层次结构 9 | unix系统是以init为root的一颗层次树,windows进程之间是平等的 10 | 11 | ##### 进程的状态 12 | 1. 运行态(正在占用CPU) 13 | 2. 就绪态(可运行,没CPU资源,等待调度) 14 | 3. 阻塞态(比如磁盘I/O) 15 | 16 | ##### 进程调度 17 | 操作系统的底层是调度程序,在它上面有许多进程,所有关于中断处理,启动进程,停止进程的具体细节都隐藏在调度程序中 18 | 19 | ##### 进程的实现 20 | 通过一个进程表来维护进程的信息(寄存器,程序计数器,优先级,进程ID,堆栈指针等) 21 | 22 | ### 线程 23 | 24 | ##### 种类 25 | 1. 用户级线程(由运行时系统管理,维护一个线程表) {go的协程} 线程切换快 26 | 2. 内核级线程 27 | 28 | ### 区别 29 | 1. 线程共享同一个地址空间和所有可用数据的能力 30 | 2. 线程比进程更轻量,创建和销毁更快 31 | 32 | ### 竞态 33 | 当多个线程同时操作一个变量时,无法确定谁获得操作权限,出现竞争 34 | 一般解决就是加锁,轮循(忙等待),可以通过生产-消费者模型,使用睡眠和唤醒模式,解决忙等待,通过TSL(硬件锁)+信号量来解决原子性,类似go的通道 35 | -------------------------------------------------------------------------------- /00操作系统/4文件系统.md: -------------------------------------------------------------------------------- 1 | ## 文件系统 2 | 3 | 对磁盘等存储系统的抽象 4 | 5 | ### 目录项 6 | 包含文件名和inode,相当于一个映射 7 | 8 | ### 磁盘空间管理 9 | - 块大小:分配的大,浪费空间(小文件,占一个块),分配的小,浪费时间(增加寻道次数) 10 | 11 | ##### 固态硬盘 12 | 固态硬盘每个块可写入有限的次数,所以要分散写入,并不需要碎片整理,这样会减少磁盘寿命 13 | -------------------------------------------------------------------------------- /00操作系统/5输入输出.md: -------------------------------------------------------------------------------- 1 | ## 输入输出 2 | 3 | ### I/O的实现方式 4 | - 程序控制 5 | - 中断驱动 6 | - DMA(单独的芯片控制着完整的数据块) 7 | 8 | ### 时钟 9 | - 硬件时钟 10 | - 根据电压周期50Hz(60Hz)产生一个中断 11 | - 晶体振荡器,计数器,存储寄存器 12 | - 软件时钟 13 | 14 | ##### 时钟硬件的任务 15 | 根据已知的时间间隔产生中断 16 | 17 | ##### 时钟软件的任务 18 | - 维护日时间 19 | - 防止进程超时运行 20 | - 对CPU的使用记账 21 | - 监视定时器 22 | -------------------------------------------------------------------------------- /00操作系统/6多处理机.md: -------------------------------------------------------------------------------- 1 | ## 多处理机 2 | 3 | ### 多处理机的类型 4 | - 共享存储器多处理机 5 | - 消息传递多处理机 6 | - 广域分布式系统 7 | 8 | ##### 共享存储器多处理机 9 | 基于单一总线访问内存,很容易造成总线繁忙,添加高速缓存可解决读的问题,写数据需要独占 10 | 11 | ### 并发机制 12 | 13 | [CSP和Actor模型](https://blog.csdn.net/qq_32702033/article/details/104415434) 14 | 15 | - CSP(Communicating Sequential Processes) 16 | 17 | 是依赖于一个通道channel完成两个通信实体之间协调的并发模型。它基于不共享内存的消息传递 18 | 19 | - 优点: 使用通道避免生产者和消费者之间的耦合,消息是按照它们被发送的顺序发送的 20 | - 缺点: CSP通常用于单机,它不如分布式编程的Actor模型那么好 21 | - CSP是完全同步的。通道写入器必须阻塞,直到通道读取器读取为止。这种基于阻塞的机制的优点是,一个通道只需要保存一条消息 22 | - CSP模型在一台机器上工作得最好 23 | 24 | - Actor模型 25 | 26 | 就是两个消息实体之间通过发送消息进行协调 27 | 28 | - 用Actor发送是异步的。无论读取器是否准备好从mailbox取出,消息发送方都不会阻塞,而是将消息放入通常称mailbox的队列中 29 | - Actor更适合于分布式系统,多台机器/运行 30 | 31 | - 一些编程语言 32 | - Actors Model — Erlang, Scala, Rust 33 | - CSP — Golang 34 | - 多线程 — Java, C#, C++ 35 | -------------------------------------------------------------------------------- /00操作系统/7windows.md: -------------------------------------------------------------------------------- 1 | ## windows 2 | 3 | - 查看TCP连接数 4 | ```bash 5 | # 查看ESTABLISHED数量 6 | netstat -na -p tcp | find "ESTABLISHED" /c 7 | 8 | # 查看TIME_WAIT数量 9 | netstat -na -p tcp | find "TIME_WAIT" /c 10 | ``` -------------------------------------------------------------------------------- /00操作系统/image/page_tran_al.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/00操作系统/image/page_tran_al.png -------------------------------------------------------------------------------- /00操作系统/image/内存层次结构.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/00操作系统/image/内存层次结构.png -------------------------------------------------------------------------------- /01语言/0目录.md: -------------------------------------------------------------------------------- 1 | ## 语言 2 | 3 | [styleguide](https://github.com/google/styleguide) 各种语言的风格指南 4 | 5 | ### 目录 6 | 7 | - [go](./1go/0目录.md) 8 | 9 | - [c](./2c/0目录.md) 10 | 11 | - [shell](./3shell/0目录.md) 12 | 13 | - [python](./4python/0目录.md) 14 | 15 | - [webassembly](./5webassembly/0目录.md) 16 | 17 | - [javascript](./6javascript/0目录.md) 18 | 19 | - [rust](./7rust/目录.md) 20 | 21 | - [node](./8node/目录.md) 22 | 23 | - [dart-flutter](./9dart-flutter.md) -------------------------------------------------------------------------------- /01语言/1go/0目录.md: -------------------------------------------------------------------------------- 1 | ## go 2 | 3 | 参考资料: 4 | 5 | - [go高级编程](https://github.com/chai2010/advanced-go-programming-book) 6 | - [user-go风格指南](https://github.com/Allenxuxu/uber-go-guide) 7 | - [编写可维护Go语言代码建议](https://github.com/llitfkitfk/go-best-practice) 8 | - [go语言问题集](https://www.bookstack.cn/read/qcrao-Go-Questions/README.md) 9 | - [golang修养之路](https://github.com/aceld/golang) 10 | - [golang面试题](https://github.com/lifei6671/interview-go) 11 | 12 | ### 目录 13 | 14 | 1. [http相关](./1http.md) 15 | 16 | 2. [mysql相关](./2mysql.md) 17 | 18 | 3. [分布式跟踪](./3分布式跟踪.md) 19 | 20 | 4. [命令和工具](4命令和工具.md) 21 | 22 | 5. [测试](./5测试.md) 23 | 24 | 6. [注意点](./6注意点.md) 25 | 26 | 7. [常用的包](./7常用的包.md) 27 | 28 | 8. [使用的问题](./8使用问题.md) 29 | 30 | 9. [GPM](./9GPM.md) 31 | 32 | 10. [内存管理](./10内存管理.md) 33 | 34 | 11. [pprof](./11pprof.md) 35 | 36 | 12. [优化](./12优化.md) 37 | 38 | 13. [协程](./13协程.md) 39 | 40 | 14. [timer使用](./14timer使用.md) 41 | 42 | 15. [map](./15map.md) 43 | 44 | 16. [channel](./16channel.md) 45 | 46 | 17. [interface](./17interface.md) 47 | 48 | 18. [context](./18context.md) 49 | 50 | 19. [reflact](./19反射.md) 51 | 52 | #### [pkg](./pkg/0目录.md) 53 | 54 | #### [rpc](./rpc/0目录.md) 55 | 56 | #### [code](./code) -------------------------------------------------------------------------------- /01语言/1go/12优化.md: -------------------------------------------------------------------------------- 1 | ## 优化 2 | 3 | #### go 内存优化 4 | 5 | 1. ​​减少堆内存分配​,尽量到栈上。 6 | 2. 复用对象(对象池)​ 7 | 3. 预分配切片/Map​ 8 | 4. 数据结构优化 9 | 1. 调整字段顺序​​:利用内存对齐减少填充空隙。 10 | 2. 使用unsafe 手动管理内存,如解析协议时避免类型转换。 11 | 5. 调整GC触发阈值 12 | 6. 长期存活的对象提升为全局变量,避免反复分配。 13 | 14 | 15 | #### 参数化分析 16 | 17 | - -gcflags=-m :查看编译器的逃逸分析和内联决定 18 | - GODEBUG=gctrace=1 :开启gc跟踪 19 | 20 | #### 具体优化 21 | 1. string与byte的转化,会在底层发生内存拷贝,直接修改指针 22 | 23 | ```go 24 | func Str2bytes(s string) []byte { 25 | x := (*[2]uintptr)(unsafe.Pointer(&s)) 26 | h := [3]uintptr{x[0],x[1],x[1]} 27 | return*(*[]byte)(unsafe.Pointer(&h)) 28 | } 29 | 30 | func Bytes2str(b []byte) string { 31 | return *(*string)(unsafe.Pointer(&b)) 32 | } 33 | 34 | ``` 35 | 2. map 会按需扩张,但须付出数据拷贝和重新哈希成本。如有可能,应尽可能预设足够容量空间,避免此类行为发生 36 | 37 | ```go 38 | m := make(map[string]int,10) 39 | ``` 40 | 41 | 3. 对于小对象,直接将数据交由 map 保存,远比用指针高效。这不但减少了堆内存分配,关键还在于垃圾回收器不会扫描非指针类型 key/value 对象 42 | 43 | ```go 44 | m := make(map[string]int,10) //值数据 45 | m := make(map[string]*int,10) //指针数据 46 | ``` 47 | 48 | 4. 对于map类型,delete不会减少内存占用,只有将map至为nil才会释放内存 49 | 50 | 6. 闭包会导致变量逃逸到堆上,造成GC负担,同时闭包会增加开销 51 | 52 | 7. 对于压力很大的内部组件之间,用接口有些得不偿失,普通调用用内联 53 | 54 | -------------------------------------------------------------------------------- /01语言/1go/14timer使用.md: -------------------------------------------------------------------------------- 1 | ## timer的使用 2 | 3 | [timer的调度](https://mp.weixin.qq.com/s/iseiQ20eIUR9i02fy1tFhg) 4 | 5 | ### 如何存储 6 | 7 | - Go 1.9 版本之前,所有的计时器由全局唯一的四叉堆维护,协程间竞争激烈。 8 | - Go 1.10 - 1.13,全局使用 64 个四叉堆维护全部的计时器,没有本质解决 1.9 版本之前的问题。 9 | - Go 1.14 版本之后,每个 P 单独维护一个四叉堆。 10 | 11 | ### 使用的问题 12 | 13 | - 错误创建很多的 timer,导致资源浪费。 14 | ```go 15 | func main() { 16 | for { 17 | // xxx 一些操作 18 | timeout := time.After(30 * time.Second) // timer.After 底层是调用的 timer.NewTimer 19 | select { 20 | case <- someDone: 21 | // do something 22 | case <-timeout: 23 | return 24 | } 25 | } 26 | } 27 | // 解决办法: 使用 time.Reset 重置 timer,重复利用 timer。 28 | ``` 29 | - 由于 Stop 时不会主动关闭 C,导致程序阻塞。 30 | ```go 31 | func main() { 32 | timer1 := time.NewTimer(2 * time.Second) 33 | go func() { 34 | timer1.Stop() 35 | }() 36 | <-timer1.C // goroutine 泄露,内存泄露 37 | 38 | println("done") 39 | } 40 | ``` 41 | 42 | -------------------------------------------------------------------------------- /01语言/1go/17interface.md: -------------------------------------------------------------------------------- 1 | # Interface 2 | 3 | ## iface 和 eface的区别 4 | iface 和 eface 都是 Go 中描述接口的底层结构体,区别在于 iface 描述的接口包含方法,而 eface 则是不包含任何方法的空接口:interface{} 5 | 6 | ## iface 7 | ```go 8 | type iface struct { 9 | tab *itab // 接口类型和方法表 10 | data unsafe.Pointer // 指向实际数据的指针 11 | } 12 | type itab struct { 13 | inter *interfacetype // 接口的类型信息 14 | _type *_type // 动态类型(具体类型的元信息) 15 | link *itab 16 | hash uint32 // 类型哈希值(用于类型断言) 17 | bad bool // type does not implement interface 18 | inhash bool // has this itab been added to hash? 19 | unused [2]byte 20 | fun [1]uintptr // 方法地址数组(动态派发入口) 21 | } 22 | ``` 23 | - iface包含两个字段:tab 是接口表指针,指向类型信息;data 是数据指针,则指向具体的数据。它们分别被称为动态类型和动态值。而接口值包括动态类型和动态值。 24 | - 其中 itab 由具体类型 _type 以及 interfacetype 组成。_type 表示具体类型,而 interfacetype 则表示具体类型实现的接口类型。 25 | 26 | ## eface 27 | 28 | ```go 29 | type eface struct { 30 | _type *_type 31 | data unsafe.Pointer 32 | } 33 | ``` 34 | - 只维护了一个 _type 字段,表示空接口所承载的具体的实体类型。data 描述了具体的值。 35 | 36 | ### 注意点 37 | - ​​接口定义​​:明确方法签名,确保实现类型完全匹配 38 | - ​​nil处理​​:区分接口变量为nil还是动态值为nil。 39 | - ​​空接口慎用​​:优先使用具体类型,必要时配合类型断言。 40 | - ​​类型安全​​:通过编译检查和运行时断言保障逻辑正确性。 -------------------------------------------------------------------------------- /01语言/1go/1http.md: -------------------------------------------------------------------------------- 1 | #### 一个简单的文件系统 2 | 3 | ``` 4 | #使用默认的defaultServeMux 5 | http.Handle("/c/",http.StripPrefix("/c/",http.FileServer(http.Dir("/home/meng/a")))) 6 | log.Println("Listening...") 7 | http.ListenAndServe(":3000",nil) 8 | 9 | ``` 10 | 11 | #### 页面跳转 12 | 13 | ``` 14 | th := http.RedirectHandler("https://www.baidu.com",307) 15 | http.Handle("/r",th) 16 | log.Println("Listening...") 17 | http.ListenAndServe(":3000",nil) 18 | 19 | ``` 20 | 21 | #### http 库的 Handler,HandlerFunc 和 ServeHTTP 的关系 22 | 23 | ```go 24 | 25 | type Handler interface { 26 | ServeHTTP(ResponseWriter, *Request) 27 | } 28 | 29 | type HandlerFunc func(ResponseWriter, *Request) 30 | 31 | func (f HandlerFunc) ServeHTTP(w ResponseWriter, r *Request) 32 | f(w, r) 33 | } 34 | 35 | ``` -------------------------------------------------------------------------------- /01语言/1go/20defer.md: -------------------------------------------------------------------------------- 1 | # defer 2 | 3 | ## 核心结构 4 | 每个函数的 defer 语句都会存储在 _defer 结构体 中,并且与 goroutine 绑定。 5 | ```go 6 | // _defer 结构体本质上是一个 单向链表 7 | type _defer struct { 8 | sp uintptr // 栈指针(保存 `defer` 发生时的栈状态) 9 | pc uintptr // 程序计数器(用于执行 `defer` 时的跳转) 10 | fn *funcval // `defer` 指向的函数 11 | link *_defer // 链接下一个 `defer` 形成链表 12 | } 13 | ``` 14 | 15 | ## 执行 16 | 后进先出 17 | defer 在 return 后执行 ,但函数的最终返回发生在所有 defer 执行完毕之后。 18 | 19 | ## 性能影响 20 | - 高频调用、循环中的 defer 可能影响性能,需谨慎使用。 21 | - Go 1.14+ 优化了 defer,一般情况下性能影响较小。 -------------------------------------------------------------------------------- /01语言/1go/2mysql.md: -------------------------------------------------------------------------------- 1 | ## mysql 2 | 3 | 4 | ### 协程不能使用事务 5 | 6 | [官方](http://go-database-sql.org/) 7 | 8 | 1. tx会从连接池中取一个空闲的连接,直至调用 commit 或者 rollback 才会释放 9 | 10 | 2. 事务只有 一个连接 ,事务内的操作是 串行 的 11 | 12 | 3. tx执行完 Query 方法之后,连接转移到 rows 上,在 Next 方法中, tx.QueryRow 将尝试获取该连接进行操作。因为还没有调用 rows.Close() ,因此连接还处于 busy 状态, tx 无法进行 QueryRow 操作。这时候使用 JOIN 语句可以规避这个问题。 13 | 14 | ```mysql 15 | rows, _ := tx.Query("SELECT id FROM tt_users") 16 | 17 | for rows.Next(){ 18 | var ( 19 | user_id int 20 | openid string 21 | ) 22 | rows.Scan(&user_id) 23 | tx.QueryRow("SELECT openid FROM tt_users_third WHERE user_id = ?", user_id).Scan(&openid) 24 | } 25 | ``` 26 | 27 | *如果2个协程同时操作一个tx,一个有查询,这个时候就会报错,buffer busy* 28 | 29 | #### 乱记 30 | 31 | [不同数据库间迁移](https://github.com/golang-migrate/migrate) 32 | 33 | 34 | -------------------------------------------------------------------------------- /01语言/1go/4命令和工具.md: -------------------------------------------------------------------------------- 1 | #### 格式化代码 2 | 3 | 4 | ``` 5 | go fmt ./*/ 格式化当前目录下的代码 6 | -s:简化代码 7 | 8 | ``` 9 | 10 | #### 编译代码 11 | 12 | GODEBUG=gctrace=1 开启gc跟踪 13 | 14 | ``` 15 | CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-s -w' -i -o main ./main.go 16 | -o:生成的位二进制名称 17 | 18 | ``` 19 | 20 | #### 工具集 21 | 22 | ##### go generate 23 | 24 | 运行go generate时,它将扫描与当前包相关的源代码文件,找出所有包含"//go:generate"的特殊注释,提取并执行该特殊注释后面的命令,命令为可执行程序,形同shell下面执行 25 | 26 | ```go 27 | // 在文件里面添加以下内容,自动生成 28 | //go:generate protoc --go_out=. entry.proto 29 | 30 | ``` 31 | 32 | ##### go build 33 | 34 | -gcflags: 传递给编译器的参数 35 | 36 | -ldflags: 传递给链接器的参数 37 | 38 | -work: 查看编译临时目录 39 | 40 | -race: 允许数据竞争检测(仅支持amd64) 41 | 42 | -n: 查看但不执行编译指令 43 | 44 | -x: 查看并执行编译命令 45 | 46 | -a: 强制重新编译所有依赖包 47 | 48 | -v: 查看被编译的包名,包括依赖包 49 | 50 | -p n:并行编译所使用的CPU数,默认为全部 51 | 52 | -o:输出文件名 53 | 54 |   55 | 56 | ##### gcflags: 57 | 58 | -B 禁用边界检查 59 | 60 | -N 禁用优化 61 | 62 | -l 禁用函数内联 63 | 64 | -u 禁用unsafe代码 65 | 66 | -m 输出优化信息 67 | 68 | -S 输出汇编代码 69 | 70 |   71 | 72 | ##### ldflags: 73 | 74 | -w 禁用DRAWF调试信息,但不包括符号表 75 | 76 | -s 禁用符号表 77 | 78 | -X 修改字符串符号值  -X main.VER ‘0.99’  -X main.S ‘abc’ 79 | 80 | -H 链接文件类型,其中包括windowsgui.   cmd/ld/doc.go 81 | 82 | ##### upx 83 | 84 | - [upx](https://github.com/upx/upx)可以压缩包大小 85 | -------------------------------------------------------------------------------- /01语言/1go/7常用的包.md: -------------------------------------------------------------------------------- 1 | # 常用的包 2 | 3 | ## sort 4 | ```go 5 | type Interface interface { 6 | // 序列长度 7 | Len() int 8 | // 两个元素比较结果 9 | Less(i, j int) bool 10 | // 两个元素交换方式 11 | Swap(i, j int) 12 | } 13 | ``` 14 | 使用`pdqsort`算法排序,根据数据量选择 插入排序、快速排序、堆排序。 15 | 16 | ## heap 17 | ```go 18 | type Interface interface { 19 | sort.Interface 20 | Push(x any) 21 | Pop() any 22 | } 23 | // 使用 heap.Init 初始化堆。 24 | ``` -------------------------------------------------------------------------------- /01语言/1go/8使用问题.md: -------------------------------------------------------------------------------- 1 | ## 使用中的问题 2 | 3 | 1. gorotine的指针传递是不安全的,gorotine的无序性,会导致变量修改达不到预期,[文章](https://www.cnblogs.com/yjf512/archive/2012/06/30/2571247.html#4067585) 4 | 5 | -------------------------------------------------------------------------------- /01语言/1go/code/elastic/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "gopkg.in/olivere/elastic.v5" 5 | //"github.com/olivere/elastic" 6 | "time" 7 | "context" 8 | "fmt" 9 | "os" 10 | "log" 11 | ) 12 | 13 | var client *elastic.Client 14 | func cfgInit() { 15 | var err error 16 | client, err = elastic.NewClient( 17 | elastic.SetURL("http://192.168.37.130:9200"), 18 | elastic.SetSniff(false), 19 | elastic.SetHealthcheckInterval(10*time.Second), 20 | elastic.SetGzip(true), 21 | elastic.SetErrorLog(log.New(os.Stderr, "ELASTIC ", log.LstdFlags)), 22 | elastic.SetInfoLog(log.New(os.Stdout, "", log.LstdFlags)), 23 | ) 24 | 25 | if err != nil { 26 | panic(err.Error()) 27 | } 28 | } 29 | type Tweet struct { 30 | User string `json:"user"` 31 | Message string `json:"message"` 32 | Retweets int `json:"retweets"` 33 | Image string `json:"image,omitempty"` 34 | Created time.Time `json:"created,omitempty"` 35 | Tags []string `json:"tags,omitempty"` 36 | Location string `json:"location,omitempty"` 37 | } 38 | 39 | //PUT1 40 | func insert() { 41 | ctx := context.Background() 42 | tweet1 := Tweet{User: "olivere", Message: "Take Five", Retweets: 0} 43 | put1, err := client.Index(). 44 | Index("twitter"). 45 | Type("tweet"). 46 | Id("1"). 47 | BodyJson(tweet1). 48 | Do(ctx) 49 | 50 | if err != nil { 51 | panic(err) 52 | return 53 | } 54 | fmt.Printf("Indexed tweet %s to index %s, type %s\n", put1.Id, put1.Index, put1.Type) 55 | } 56 | 57 | func main() { 58 | cfgInit() 59 | //使用 60 | insert() 61 | //停止 62 | defer client.Stop() 63 | } 64 | -------------------------------------------------------------------------------- /01语言/1go/code/fragment/callback.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | //回调函数类型 9 | type Callback func() 10 | 11 | //客户端接口 12 | type IClient interface { 13 | Register(cbs ...Callback) 14 | Run() 15 | } 16 | 17 | //客户端 18 | type Client struct { 19 | cbs []Callback 20 | mu sync.Mutex 21 | } 22 | 23 | // 24 | func NewClient() *Client { 25 | return &Client{cbs: []Callback{}} 26 | } 27 | 28 | //实现注册 29 | func (c *Client) Register(cbs ...Callback) { 30 | c.mu.Lock() 31 | c.cbs = append(c.cbs, cbs...) 32 | c.mu.Unlock() 33 | } 34 | 35 | //实现运行 36 | func (c *Client) Run() { 37 | for _, _cb := range c.cbs { 38 | _cb() 39 | } 40 | } 41 | 42 | //实现回调类型函数 43 | func a() { 44 | //fmt.Println("a") 45 | } 46 | 47 | func b() { 48 | //fmt.Println("b") 49 | } 50 | 51 | func main() { 52 | c := NewClient() 53 | wg := sync.WaitGroup{} 54 | wg.Add(2000) 55 | for i := 0; i < 1000; i++ { 56 | go func() { 57 | c.Register(a) 58 | wg.Done() 59 | }() 60 | } 61 | 62 | for i := 0; i < 1000; i++ { 63 | go func() { 64 | c.Register(b) 65 | wg.Done() 66 | }() 67 | } 68 | wg.Wait() 69 | fmt.Println(len(c.cbs)) 70 | c.Run() 71 | } 72 | -------------------------------------------------------------------------------- /01语言/1go/code/fragment/chan.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type Int int 6 | type V interface { 7 | Iter() <-chan Int 8 | } 9 | 10 | func (t *Int) Get() V { 11 | iter := func() <-chan Int { 12 | ch := make(chan Int) 13 | go func() { 14 | for i:=0; i< 5 ; i++ { 15 | ch<-Int(i) 16 | } 17 | close(ch) 18 | }() 19 | return ch 20 | } 21 | return V(&Vhelp{iterFunc:iter}) 22 | } 23 | 24 | type Vhelp struct { 25 | iterFunc func() <-chan Int 26 | } 27 | 28 | func (v *Vhelp) Iter() <-chan Int { 29 | return v.iterFunc() 30 | } 31 | 32 | func main() { 33 | t := new(Int) 34 | ss := t.Get().Iter() 35 | for s := range ss { 36 | fmt.Println(s) 37 | } 38 | 39 | 40 | } -------------------------------------------------------------------------------- /01语言/1go/code/makefile/README.md: -------------------------------------------------------------------------------- 1 | # Makefile 2 | 3 | ## go工具自动安装(go-tool.make) 4 | 5 | 工具包含:golang govendor cloc gocyclo protoc go-torch debugcharts dep等,可以增加添加 6 | 默认:golang govendor(包管理) cloc(代码统计) gocyclo(圈复杂度) protoc(protobuf protoc-gen-go protoc-gen-micro) go-torch (火焰图) 7 | 可以自定义设置: 修改all:后面的标签 8 | #### 安装 9 | 10 | ```shell 11 | #新建目录存放go包和第三方插件(这里目录为gopkg) 12 | mkdir -p ${HOME}/gopkg/bin ${HOME}/gopkg/src 13 | #下载makefile 14 | git clone https://github.com/xiaomeng79/Makefile.git && cd Makefile 15 | #更改makefile中soft_dir和go_path的路径为自定义的路径(默认为一下设置) 16 | vi go-tool.make 17 | soft_dir=${HOME}/gopkg/third 18 | go_path=${HOME}/gopkg 19 | #安装软件(默认安装all下面的软件,可以单独安装一个软件) 20 | make -f go-tool.make 21 | #安装一个软件(以govendor为例) 22 | make -f go-tool.make govendor 23 | #设置环境变量 24 | make -f go-tool.make setpath 25 | #清空安装包 26 | make -f go-tool.make clean 27 | 28 | ``` 29 | >| 安装过程由于网络问题,可能安装不好,需要重试几次 30 | -------------------------------------------------------------------------------- /01语言/1go/code/makefile/setPath.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #设置GOPATH 3 | f=".bashrc" 4 | go_path="" 5 | path="" 6 | if test "$#" -eq 3;then 7 | f=$1;go_path=$2;path=$3; 8 | else 9 | print "参数不正确,共三个参数,第一个参数是:修改环境变量的文件路径,第二个参数是,GOPATH的路径,第三个参数是,PATH路径"; 10 | exit -1; 11 | fi 12 | path=${PATH}:${path}; 13 | sed -i '/export GOPATH=/d' $f; 14 | echo "export GOPATH=${go_path}" >>$f; 15 | sed -i '/export PATH=/d' $f; 16 | echo "export PATH=${path}" >>$f; 17 | 18 | source $f; 19 | -------------------------------------------------------------------------------- /01语言/1go/code/tmp/stackorheap.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func main() { 4 | a := make([]int,0,20) 5 | 6 | b := make([]int,0,20000) 7 | 8 | l := 20 9 | 10 | c := make([]int,0,l) 11 | } 12 | 13 | //查看编译申请空间 go build -gcflags='-m' . 2>&1 14 | func f() { 15 | a := make([]int,0,20) 16 | 17 | b := make([]int,0,20000) 18 | 19 | l := 20 20 | 21 | c := make([]int,0,l) 22 | } 23 | -------------------------------------------------------------------------------- /01语言/1go/code/web/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | "log" 6 | ) 7 | 8 | //实现一个httpHandleFunc 9 | func test(w http.ResponseWriter,r *http.Request) { 10 | w.Write([]byte("hello")) 11 | } 12 | 13 | //实现一个日志中间件 14 | func logMiddleware(next http.Handler) http.Handler { 15 | return http.HandlerFunc(func(w http.ResponseWriter,r *http.Request) { 16 | log.Println("start request") 17 | next.ServeHTTP(w,r) 18 | }) 19 | } 20 | 21 | //使用net/http实现web服务 22 | func main() { 23 | 24 | //http.Handle("/test",http.HandlerFunc(test)) //将http.Handler 转换为http.HandlerFunc 25 | 26 | http.Handle("/test",logMiddleware(http.HandlerFunc(test)))//引用中间件 27 | http.ListenAndServe(":8889",nil) 28 | 29 | } 30 | 31 | 32 | //http 库的 Handler,HandlerFunc 和 ServeHTTP 的关系: 33 | 34 | //type Handler interface { 35 | // ServeHTTP(ResponseWriter, *Request) 36 | //} 37 | // 38 | //type HandlerFunc func(ResponseWriter, *Request) 39 | // 40 | //func (f HandlerFunc) ServeHTTP(w ResponseWriter, r *Request) 41 | //f(w, r) 42 | //} 43 | -------------------------------------------------------------------------------- /01语言/1go/code/write/zip.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "archive/zip" 5 | "bytes" 6 | "fmt" 7 | "os" 8 | ) 9 | 10 | func main() { 11 | // 创建一个缓冲区用来保存压缩文件内容 12 | buf := new(bytes.Buffer) 13 | // 创建一个压缩文档 14 | w := zip.NewWriter(buf) 15 | // 将文件加入压缩文档 16 | var files = []struct { 17 | Name, Body string 18 | }{ 19 | {"Golang.txt", "http://c.biancheng.net/golang/"}, 20 | } 21 | for _, file := range files { 22 | f, err := w.Create(file.Name) 23 | if err != nil { 24 | fmt.Println(err) 25 | } 26 | _, err = f.Write([]byte(file.Body)) 27 | if err != nil { 28 | fmt.Println(err) 29 | } 30 | } 31 | // 关闭压缩文档 32 | err := w.Close() 33 | if err != nil { 34 | fmt.Println(err) 35 | } 36 | // 将压缩文档内容写入文件 37 | f, err := os.OpenFile("file.zip", os.O_CREATE|os.O_WRONLY, 0666) 38 | if err != nil { 39 | fmt.Println(err) 40 | } 41 | buf.WriteTo(f) 42 | } 43 | -------------------------------------------------------------------------------- /01语言/1go/pkg/0目录.md: -------------------------------------------------------------------------------- 1 | ## PKG 2 | 3 | 1. [unsafe](./1unsafe.md) -------------------------------------------------------------------------------- /01语言/1go/rpc/0目录.md: -------------------------------------------------------------------------------- 1 | ## RPC 2 | -------------------------------------------------------------------------------- /01语言/1go/rpc/cli/rpc_client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/rpc" 5 | "log" 6 | "fmt" 7 | ) 8 | 9 | func main() { 10 | conn, err := rpc.Dial("tcp","localhost:1234") 11 | if err != nil { 12 | log.Fatal("dialing:",err) 13 | } 14 | //client := rpc.NewClientWithCodec(jsonrpc.NewClientCodec(conn)) //使用json编码的客户端 15 | var reply string 16 | err = conn.Call("HelloService.Hello","hello",&reply) 17 | if err != nil { 18 | log.Fatal(err) 19 | } 20 | fmt.Println(reply) 21 | } 22 | -------------------------------------------------------------------------------- /01语言/1go/rpc/srv/rpc_server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/rpc" 5 | "net" 6 | "log" 7 | ) 8 | 9 | type HelloService struct { 10 | 11 | } 12 | 13 | //其中Hello方法必须满足Go语言的RPC规则:方法只能有两个可序列化的参数,其中第二个参数是指针类型,并且返回一个error类型,同时必须是公开的方法。 14 | 15 | func (p *HelloService) Hello(request string,reply *string) error { 16 | *reply = "hello:" + request 17 | return nil 18 | } 19 | 20 | 21 | func main() { 22 | //rpc.Register函数调用会将对象类型中所有满足RPC规则的对象方法注册为RPC函数,所有注册的方法会放在“HelloService”服务空间之下 23 | rpc.RegisterName("HelloService",new(HelloService)) 24 | listener, err := net.Listen("tcp",":1234") 25 | if err != nil { 26 | log.Fatal("listener error:",err) 27 | } 28 | for { 29 | conn,err := listener.Accept() 30 | if err != nil { 31 | log.Fatal("accept error:",err) 32 | } 33 | go rpc.ServeConn(conn) //默认使用gob编码 34 | //go rpc.ServeCodec(jsonrpc.NewServerCodec(conn)) //使用json编解码器 35 | } 36 | } 37 | 38 | 39 | /* 40 | //http 版本 41 | //调用方法: 42 | //curl localhost:1234/jsonrpc -X POST --data '{"method":"HelloService.Hello","params":["hello"],"id":0}' 43 | func main() { 44 | rpc.RegisterName("HelloService", new(HelloService)) 45 | http.HandleFunc("/jsonrpc", func(w http.ResponseWriter, r *http.Request) { 46 | var conn io.ReadWriteCloser = struct { 47 | io.Writer 48 | io.ReadCloser 49 | }{ 50 | ReadCloser: r.Body, 51 | Writer: w, 52 | } 53 | 54 | rpc.ServeRequest(jsonrpc.NewServerCodec(conn)) 55 | }) 56 | 57 | http.ListenAndServe(":1234", nil) 58 | } 59 | */ 60 | -------------------------------------------------------------------------------- /01语言/2c/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 -------------------------------------------------------------------------------- /01语言/3shell/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | 参考资料: 4 | 5 | [shell基本](https://blog.csdn.net/qq_22075977/article/details/75209149) 6 | 7 | 1. [概念](./1概念.md) 8 | 9 | 3. [命令](./3命令.md) -------------------------------------------------------------------------------- /01语言/3shell/3命令.md: -------------------------------------------------------------------------------- 1 | ## 重要命令 2 | 3 | 1. 替换目录下面匹配的字符串 4 | 5 | ```shell 6 | #sed grep 7 | sed -i 's/xiaomeng/wangba/g' `grep xiaomeng -rl ./` 8 | ``` 9 | 10 | 2. set exu 11 | 12 | ```shell 13 | 14 | set -ex 15 | x:跟踪代码 -x:打开 +x:关闭 -o查看 16 | e:非正常是否退出 -e:退出 +e:继续执行 17 | u:不存在的变量忽略 18 | 19 | ``` 20 | 3. 替换匹配的下一行 21 | 22 | ```shell 23 | #!/bin/bash 24 | sed -i "/- name: RAND_NUM/{ n;s/\(value: \).*/\1num$RANDOM/ }" account_api.yaml 25 | 26 | \1:匹配的第一个字符串 27 | n:下一行 28 | 29 | ``` -------------------------------------------------------------------------------- /01语言/4python/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | - [常见问题](./1常见问题.md) 4 | - [常用的库](./2常用的库.md) 5 | - [工具使用](./3工具使用.md) -------------------------------------------------------------------------------- /01语言/4python/1常见问题.md: -------------------------------------------------------------------------------- 1 | ## 常见问题 2 | 3 | - 国内源 4 | 5 | ```python 6 | 豆瓣(douban) https://pypi.douban.com/simple 7 | 阿里云 https://mirrors.aliyun.com/pypi/simple 8 | 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple 9 | 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple 10 | 官方源 https://pypi.python.org/simple 11 | ``` 12 | - matplotlib.pyplot依赖模块"tkinter" 13 | 14 | ```shell 15 | 16 | sudo apt-get install tcl-dev tk-dev python3-tk 17 | sudo apt-get install python3 18 | 19 | ``` -------------------------------------------------------------------------------- /01语言/4python/2常用的库.md: -------------------------------------------------------------------------------- 1 | ## 常用的库 2 | 3 | [常用的库](https://www.jianshu.com/nb/34356339) 4 | 5 | #### 包管理 6 | - pip freeze (单虚拟环境的情况) 7 | ```bash 8 | pip freeze > requirements.txt 9 | ``` 10 | 11 | - [pipreqs](https://github.com/bndr/pipreqs) 12 | ```bash 13 | # 安装 14 | pip install pipreqs 15 | # 在当前目录生成 --force为覆盖 16 | pipreqs . --encoding=utf8 --force 17 | ``` 18 | 19 | - 使用requirements.txt安装依赖 20 | ```bash 21 | pip install -r requirements.txt 22 | 23 | ``` 24 | 25 | #### 源地址 26 | ```bash 27 | 阿里云 http://mirrors.aliyun.com/pypi/simple/ 28 | 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 29 | douban http://pypi.douban.com/simple 30 | Python官方 https://pypi.python.org/simple 31 | v2ex http://pypi.v2ex.com/simple 32 | 中国科学院 http://pypi.mirrors.opencas.cn/simple/ 33 | 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ 34 | ``` 35 | 36 | #### 常用的库 37 | 38 | - [常用库总结](./lib/README.md) 39 | -------------------------------------------------------------------------------- /01语言/4python/3工具使用.md: -------------------------------------------------------------------------------- 1 | ## 工具使用 2 | 3 | #### jupyter 4 | 5 | ```bash 6 | #启动 7 | jupyter notebook 8 | # 转换ipynb为python 9 | jupyter nbconvert --to script next.ipynb 10 | ``` 11 | 12 | #### 虚拟环境 13 | 14 | ```bash 15 | # 安装 16 | pip install virtualenv 17 | 18 | # 创建虚拟环境 19 | virtualenv venv -p /usr/bin/python3 # -p指定环境 20 | # 进入虚拟环境 21 | source venv/bin/activate 22 | # 退出虚拟环境 23 | deactivate 24 | ``` -------------------------------------------------------------------------------- /01语言/4python/lib/README.md: -------------------------------------------------------------------------------- 1 | ## 常用的库 2 | 3 | #### 库列表 4 | 5 | - [numpy](./numpy.md) 6 | - [pandas](./pandas.md) 7 | - [matplotlib](./matplotlib.md) 2D绘图库 8 | - [seaborn](./seaborn.md) 基于matplotlib,封装好的 9 | - [imgaug](https://github.com/aleju/imgaug) 图像数据增强 10 | - [Beautiful Soup](https://www.crummy.com/software/BeautifulSoup/) html解析 11 | - [lxml](https://lxml.de/index.html) 解析xml html 12 | 13 | -------------------------------------------------------------------------------- /01语言/4python/lib/matplotlib.md: -------------------------------------------------------------------------------- 1 | ## matplotlib 2 | 3 | #### 参考资料 4 | 5 | - [官网](https://matplotlib.org) 6 | - [中文文档](https://www.matplotlib.org.cn/) 7 | - [matplotlib-tutorial](https://github.com/rougier/matplotlib-tutorial) 8 | 9 | 10 | #### 对比 11 | 12 | |视图| Matplotlib| Seaborn| 13 | |---|---|---| 14 | |散点| pyplot.scatter| jointplot(x=’’,y=’’,data=,kind=‘scatter’)| 15 | 折线 |pyplot.plot(x,y)| lineplot(x=’’,y=’’,data=)| 16 | |直方图| pyplot.hist(x,bin=) |distplot(x,kde=True)| 17 | |条形图| pyplot.bar(x,height)| barplot(x=’’,y=’’,data=)| 18 | |箱线图| pyplot.boxplot(x,labels=)| boxplot(data=)| 19 | |饼图| pyplot.pie(x,labels=) || 20 | |热力图| | heatmap(data)| 21 | |蜘蛛图| figure+add_subplot+plot+fill| | 22 | |二元变量分布 | |jointplot(x=’’,y=’’,data=,kind=) (散点:‘scatter’,核密度:‘kde’,Hexbin:‘hex’)| 23 | |成对关系| |pairplot(data)| -------------------------------------------------------------------------------- /01语言/4python/lib/numpy.md: -------------------------------------------------------------------------------- 1 | ## numpy 2 | 3 | #### 参考资料 4 | 5 | - [中文文档](https://www.numpy.org.cn/) -------------------------------------------------------------------------------- /01语言/4python/lib/pandas.md: -------------------------------------------------------------------------------- 1 | ## pandas 2 | 3 | #### 参考资料 4 | 5 | - [中文文档](https://www.pypandas.cn/) -------------------------------------------------------------------------------- /01语言/4python/lib/seaborn.md: -------------------------------------------------------------------------------- 1 | ## seaborn 2 | 3 | - [seaborn](http://seaborn.pydata.org) 官网 -------------------------------------------------------------------------------- /01语言/5webassembly/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | [资料](https://github.com/chai2010/awesome-wasm-zh) 3 | [awesome-wasm](https://github.com/mbasso/awesome-wasm) 4 | 5 | - [概念](1概念.md) -------------------------------------------------------------------------------- /01语言/5webassembly/1概念.md: -------------------------------------------------------------------------------- 1 | ## 概念 2 | 3 | #### 介绍 4 | [介绍](https://www.cnblogs.com/detectiveHLH/p/9928915.html) -------------------------------------------------------------------------------- /01语言/6javascript/0目录.md: -------------------------------------------------------------------------------- 1 | ## javascript 2 | 3 | #### 跨端框架 4 | 5 | - [uni-app](https://github.com/dcloudio/uni-app) 6 | 7 | - [taro](https://github.com/NervJS/taro) 8 | 9 | - [electronjs](http://www.electronjs.org/) 构建跨平台应用 -------------------------------------------------------------------------------- /01语言/7rust/mod理解.md: -------------------------------------------------------------------------------- 1 | ## mod理解 2 | 3 | 1. [mod理解](https://zhuanlan.zhihu.com/p/113038358) -------------------------------------------------------------------------------- /01语言/7rust/宏.md: -------------------------------------------------------------------------------- 1 | # 宏 2 | 3 | ## 资料 4 | - [Rust 宏](https://github.com/veykril/tlborm/) 5 | - [Rust宏:教程与示例](https://www.cnblogs.com/praying/p/14457360.html) [原文](https://blog.logrocket.com/macros-in-rust-a-tutorial-with-examples/) 6 | 7 | ## 特点 8 | 9 | - 编译器展开。 10 | - Rust 宏会被应用于词法树(token tree),而 C 语言里的宏则是文本替换。 11 | 12 | ## 类型 13 | 14 | - 声明式宏(Declarative macros)使得你能够写出类似 match 表达式的东西,来操作你所提供的 Rust 代码。它使用你提供的代码来生成用于替换宏调用的代码。 15 | - 过程宏(Procedural macros)允许你操作给定 Rust 代码的抽象语法树(abstract syntax tree, AST)。过程宏是从一个(或者两个)TokenStream到另一个TokenStream的函数,用输出的结果来替换宏调用。 16 | 17 | 18 | -------------------------------------------------------------------------------- /01语言/7rust/工具.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/01语言/7rust/工具.md -------------------------------------------------------------------------------- /01语言/7rust/常用库/log4rs.md: -------------------------------------------------------------------------------- 1 | ## log4rs 2 | 3 | #### 配置文件 4 | 5 | [参数解释](https://blog.csdn.net/wyansai/article/details/105186331) 6 | [参数说明](https://segmentfault.com/a/1190000021681959) 7 | 8 | ```yaml 9 | refresh_rate: 30 seconds 10 | 11 | appenders: 12 | stdout: 13 | kind: console 14 | requests: 15 | kind: rolling_file 16 | path: "log/requests.log" 17 | encoder: 18 | kind: json 19 | policy: 20 | kind: compound 21 | trigger: 22 | kind: size 23 | limit: 10 mb 24 | roller: 25 | kind: fixed_window 26 | pattern: '{0}/requests.log.{{}}' 27 | base: 1 28 | count: 5 29 | 30 | root: 31 | level: info 32 | appenders: 33 | - stdout 34 | - requests 35 | ``` -------------------------------------------------------------------------------- /01语言/7rust/所有权.md: -------------------------------------------------------------------------------- 1 | ## 所有权 2 | 3 | [所有权和生命周期](https://lotabout.me/2016/rust-lifetime/) 4 | 5 | ### 所有权 6 | 7 | 变量的所有权总是遵循相同的模式:将值赋给另一个变量时移动它。当持有堆中数据值的变量离开作用域时,其值将通过 drop 被清理掉,除非数据被移动为另一个变量所有。 8 | 9 | 10 | 1. 变量与数据交互的方式(一):移动 11 | 12 | - 基本数据类型,直接复制 13 | 14 | ```rust 15 | // 所有整数类型,例如 i32 、 u32 、 i64 等。 16 | // 布尔类型 bool,值为 true 或 false 。 17 | // 所有浮点类型,f32 和 f64。 18 | // 字符类型 char。 19 | // 仅包含以上类型数据的元组(Tuples)。 20 | let x = 5; 21 | let y = x; 22 | ``` 23 | 24 | Rust 永远也不会自动创建数据的 “深拷贝” 25 | 26 | ```rust 27 | // 堆中的数据 28 | let s1 = String::from("hello"); 29 | let s2 = s1; 30 | // 此时s1就无效了,防止函数结束`}`时候内存释放(drop),造成二次释放,只释放一次, 31 | ``` 32 | 33 | 2. 变量与数据交互的方式(二):克隆 34 | 35 | ```rust 36 | let s1 = String::from("hello"); 37 | let s2 = s1.clone(); 38 | ``` 39 | 40 | ### 引用 41 | 42 | - 在任意给定时间,要么 只能有一个可变引用,要么 只能有多个不可变引用。 43 | - 引用必须总是有效的。 44 | 45 | ### Sync和Send 46 | 47 | - Send trait允许线程间转移所有权 **独占访问是线程安全的** 48 | - Sync trait允许引用可以在不同的线程间共享 **共享访问是线程安全的** -------------------------------------------------------------------------------- /01语言/7rust/智能指针.md: -------------------------------------------------------------------------------- 1 | # 智能指针 2 | 3 | ## 如下为选择 Box,Rc 或 RefCell 的理由: 4 | 5 | - Rc 允许相同数据有多个所有者;Box 和 RefCell 有单一所有者。 6 | - Box 允许在编译时执行不可变或可变借用检查;Rc仅允许在编译时执行不可变借用检查;RefCell 允许在运行时执行不可变或可变借用检查。 7 | - 因为 RefCell 允许在运行时执行可变借用检查,所以我们可以在即便 RefCell 自身是不可变的情况下修改其内部的值。 -------------------------------------------------------------------------------- /01语言/7rust/点.md: -------------------------------------------------------------------------------- 1 | # 点 2 | 3 | - self 4 | 5 | ```rust 6 | // &self实际上是 的缩写self: &Self 7 | impl Rectangle { 8 | fn area(&self) -> u32 { 9 | self.width * self.height 10 | } 11 | } 12 | ``` 13 | - Rust 有一个称为自动引用和取消引用的功能 14 | 15 | 是因为方法有一个明确的接收者—— self. 给定方法的接收者和名称,Rust 可以明确地确定该方法是读取 ( &self)、变异 ( &mut self) 还是消费 ( self) 16 | 17 | - [异步 Rust:协作与抢占式调度](https://github.com/rustlang-cn/Rustt/blob/main/Articles/%5B2022-04-12%5D%20%E5%BC%82%E6%AD%A5%20Rust%EF%BC%9A%E5%8D%8F%E4%BD%9C%E4%B8%8E%E6%8A%A2%E5%8D%A0%E5%BC%8F%E8%B0%83%E5%BA%A6.md) 18 | 19 | - 异步运行时 20 | - [tokio](https://tokio.rs/) I/O密集 21 | - [rayon](https://github.com/rayon-rs/rayon) CPU密集 -------------------------------------------------------------------------------- /01语言/7rust/目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | ### 参考文档 4 | 5 | - [官网](https://www.rust-lang.org/) 6 | - [Rust 程序设计语言](https://kaisery.github.io/trpl-zh-cn/title-page.html) 7 | - [通过例子学习rust](https://rust-by-example.budshome.com) 8 | - [rust相关的张文](https://budshome.com/books.html) 9 | 10 | ### 概念理解 11 | 12 | - [所有权](./所有权.md) 13 | - [mod理解](./mod理解.md) 14 | - [点](./%E7%82%B9.md) 15 | - [宏](./%E5%AE%8F.md) 16 | 17 | 18 | ### 工具 19 | 20 | - [rsproxy](https://rsproxy.cn/) 字节镜像源 -------------------------------------------------------------------------------- /01语言/8node/命令.md: -------------------------------------------------------------------------------- 1 | ## 命令 2 | 3 | - 切换国内源 4 | ```bash 5 | # 切换国内源 6 | npm install -g cnpm --registry=https://registry.npm.taobao.org 7 | cnpm install hexo-cli -g 8 | ``` 9 | -------------------------------------------------------------------------------- /01语言/8node/目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | - [命令](./命令.md) 4 | 5 | -------------------------------------------------------------------------------- /01语言/9dart-flutter.md: -------------------------------------------------------------------------------- 1 | # dart-flutter 2 | 3 | ## 工具 4 | 5 | - [sentry](https://sentry.io/) 日志收集 6 | - [imgcook](https://www.imgcook.com/) 设计稿生成代码 7 | - [supernova](https://www.supernova.io/) 设计稿生成代码 -------------------------------------------------------------------------------- /02数据存取/0目录.md: -------------------------------------------------------------------------------- 1 | # 目录 2 | 3 | 1. [mysql](./1mysql/0目录.md) 4 | 5 | 2. [bolt](./2bolt/0目录.md) 6 | 7 | 3. [influxdb](./3influxdb.md) 8 | 9 | 4. [hbase](./4Hbase.md) 10 | 11 | 5. [Redis](./5Redis.md) 12 | 13 | 6. [TiDB](6TiDB.md) 14 | 15 | 7. [oracle](./7oracle/0目录.md) 16 | 17 | 8. [postgres](./8postgres/0目录.md) 18 | 19 | 9. [分布式文件系统](./9分布式文件系统.md) 20 | 21 | 10. [clickhouse](10clickhouse.md) 22 | -------------------------------------------------------------------------------- /02数据存取/1mysql/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | [MYSQL常用概念](https://mp.weixin.qq.com/s?__biz=MzI4NjI1OTI4Nw==&mid=2247488721&idx=1&sn=eead82d2b7a0fdf993beacc4dfd60313&chksm=ebdef5e9dca97cff9d638877e5855850727ae26ebcfd60c7700ae53e311fa6ddb64b63bb9552&scene=132#wechat_redirect) 4 | 5 | 1. [基本架构](1基本架构.md) 6 | 7 | 2. [执行计划](2执行计划.md) 8 | 9 | 3. [日志](3日志.md) 10 | 11 | 4. [索引](4索引.md) 12 | 13 | 5. [事务和锁](5事务和锁.md) 14 | 15 | 6. [优化](6优化.md) 16 | 17 | 7. [配置](7配置.md) 18 | 19 | 8. [工具](8工具.md) 20 | 21 | 9. [其他](9其他.md) 22 | 23 | 10. [快照读](10快照读.md) 24 | 25 | -------------------------------------------------------------------------------- /02数据存取/1mysql/10快照读.md: -------------------------------------------------------------------------------- 1 | # 当前读、快照读、MVCC 2 | 3 | ## 当前读 4 | 5 | - 当前读, 读取的是最新版本, 并且对读取的记录加锁, 阻塞其他事务同时改动相同记录,避免出现安全问题。 6 | - 操作: 7 | - select...lock in share mode (共享读锁) 8 | - select...for update 9 | - update , delete , insert 10 | - 实现方式:行锁+间隙锁 11 | - 加锁 12 | - 对主键或唯一索引,如果当前读时,where条件全部精确命中(=或者in),这种场景本身就不会出现幻读,所以只会加行记录锁。 13 | - 没有索引的列,当前读操作时,会加全表gap锁,生产环境要注意。 14 | - 非唯一索引列,如果where条件部分命中(>、<、like等)或者全未命中,则会加附近Gap间隙锁。例如,某表数据如下,非唯一索引2,6,9,9,11,15。如下语句要操作非唯一索引列9的数据,gap锁将会锁定的列是(6,11],该区间内无法插入数据。 15 | 16 | ## 快照读 17 | - 读取快照数据,也就是说当某个数据正在被修改的时候,也可以进行读取该数据,保证读写不冲突。 18 | - 实现方式: undolog和多版本并发控制(MVCC) 19 | 20 | ### 如何实现快照读 21 | - 快照”不是全量拷贝,而是利用了数据多版本的特性,也就是MVCC 22 | - MVCC的核心在于每个事务自己维护的一个事务ID数组 23 | - 只有“快照读”的sql语句,才会生成快照,比如不加锁的select语句; 24 | - 而“当前读”的sql语句,是不会生成快照的,比如update,select … for update, select .. lock in share mode等; 25 | - Read Committed隔离级别:每次select都生成一个快照读。 26 | - Read Repeatable隔离级别:开启事务后第一个select语句才是快照读的地方,而不是一开启事务就快照读。 27 | - 可见性的原则 28 | - 版本未提交,不可见; 29 | - 版本已提交,但是是在快照创建后提交的,不可见; 30 | - 版本已提交,而且是在快照创建前提交的,可见。 31 | 32 | ## MVCC 33 | MVCC 主要依赖 数据行的多个版本 和 隐藏字段 来实现事务的可见性控制。在 InnoDB 中,每一行数据在其后面都存储了一些 隐藏的系统字段,其中最重要的是: 34 | - DB_TRX_ID(事务 ID):记录最后一次修改该行的事务 ID。 35 | - DB_ROLL_PTR(回滚指针):指向该行数据的上一个版本(即 undo log 记录),用于事务回滚或快照读取。 36 | - DB_ROW_ID(行 ID):自增 ID,仅在没有主键时才存在。 -------------------------------------------------------------------------------- /02数据存取/1mysql/1基本架构.md: -------------------------------------------------------------------------------- 1 | ## 基本架构 2 | 3 | [参考文章](https://www.cnblogs.com/yuyue2014/p/3826941.html) 4 | 5 | ![执行过程](mysql_jg.png) 6 | -------------------------------------------------------------------------------- /02数据存取/1mysql/mysql_jg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/02数据存取/1mysql/mysql_jg.png -------------------------------------------------------------------------------- /02数据存取/2bolt/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | 1. [介绍](https://github.com/boltdb/bolt) 4 | 5 | 2. [对比](https://github.com/boltdb/bolt#postgres-mysql--other-relational-databases) -------------------------------------------------------------------------------- /02数据存取/3influxdb.md: -------------------------------------------------------------------------------- 1 | ## influxdb 2 | 3 | [官方文档](https://docs.influxdata.com/influxdb/v1.7/) 4 | 5 | ## 与传统数据库的比较 6 | 7 | - 存储成本大:对于时序数据压缩不佳,需占用大量机器资源 8 | - 维护成本高:单机系统,需要在上层人工的分库分表,维护成本高 9 | - 写入吞吐低:单机写入吞吐低,很难满足时序数据千万级的写入压力 10 | - 查询性能差:适用于交易处理,海量数据的聚合分析性能差 11 | 12 | ## 与Hadoop的比较 13 | 14 | - 数据延迟高:离线批处理系统,数据从产生到可分析,耗时数小时、甚至天级 15 | - 查询性能差:不能很好的利用索引,依赖MapReduce任务,查询耗时一般在分钟级 16 | 17 | ## 时序数据库需要解决的问题 18 | 19 | - 时序数据的写入:如何支持每秒钟上千万上亿数据点的写入 20 | - 时序数据的读取:如何支持在秒级对上亿数据的分组聚合运算 21 | - 成本敏感:由海量数据存储带来的是成本问题。如何更低成本的存储这些数据,将成为时序数据库需要解决的重中之重 22 | 23 | ## 如何解决 24 | 25 | - 存储成本:利用时间递增、维度重复、指标平滑变化的特性,合理选择编码压缩算法,提高数据压缩比 26 | - 高并发写入:数据先写入内存,再周期性的dump为不可变的文件存储 27 | - 低查询延时,高查询并发:优化常见的查询模式,通过索引等技术降低查询延时;通过缓存、routing等技术提高查询并发 28 | 29 | ## 存储的原理 30 | 31 | - 索引:由于其在查询和顺序插入时有利于减少寻道次数的组织形式,传统的数据库采用B Tree, 32 | - TSM存储引擎:根据LSM Tree针对时间序列数据优化而来 33 | 34 | ## 概念 35 | 36 | [InfluxDB详解之TSM存储引擎解析](http://blog.fatedier.com/2016/08/05/detailed-in-influxdb-tsm-storage-engine-one/) 37 | 38 | ### 数据格式 39 | - database:数据库名称 物理隔离数据文件 40 | - retention policy:存储策略,用于定期清除过期数据 41 | - measurement: 测量指标名(表名),例如 cpu_usage 表示 cpu 的使用率 42 | - tag sets: tags 在 InfluxDB 中会按照字典序排序,索引 43 | - field sets: 字段值,可以设置多个,底层是当做多条数据存储 44 | - timestamp: 每一条数据都需要指定一个时间戳 45 | 46 | ### Point 47 | InfluxDB 中单条插入语句的数据结构,series + timestamp 可以用于区别一个 point,也就是说一个 point 可以有多个 field name 和 field value 48 | 49 | ### Series 50 | 相当于是 InfluxDB 中一些数据的集合,series 的key为measurement + 所有 tags 的序列化字符串 51 | 52 | ### Shard 53 | 根据 retention policy 分割数据,存储成一个shard,每个shard就是一个tsm存储引擎 54 | 55 | -------------------------------------------------------------------------------- /02数据存取/6TiDB.md: -------------------------------------------------------------------------------- 1 | ## TiDB 2 | 3 | [中文文档](https://pingcap.com/docs-cn/) 4 | 5 | #### 特性 6 | 7 | - 高度兼容Mysql 8 | - 水平弹性拓展 9 | - 分布式事物 10 | - 真正金融级高可用 11 | - 一站式HTAP解决方案 12 | - 云原生SQL数据库 13 | 14 | #### 组件 15 | 16 | 1. TiDB Server : TiDB Server 负责接收 SQL 请求,处理 SQL 相关的逻辑,并通过 PD 找到存储计算所需数据的 TiKV 地址,与 TiKV 交互获取数据,最终返回结果 17 | 2. PD Server : Placement Driver (简称 PD) 是整个集群的管理模块 18 | 3. TiKV Server : TiKV Server 负责存储数据 -------------------------------------------------------------------------------- /02数据存取/7oracle/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | - [ora2pg](https://github.com/darold/ora2pg) 4 | 5 | - [go-oci8](https://github.com/wendal/go-oci8) go安装oracle 6 | 7 | 1. [执行计划](1执行计划.md) 8 | 9 | 2. [常用的命令](2常用的命令.md) -------------------------------------------------------------------------------- /02数据存取/7oracle/1执行计划.md: -------------------------------------------------------------------------------- 1 | ## 执行计划 2 | 3 | 4 | ### 执行sql 5 | ```bash 6 | #生成执行计划 7 | explain plan for 8 | select * from table_name where id=123; 9 | #查看执行计划 10 | select * from table(dbms_xplan.display); 11 | ``` 12 | 13 | ##### 几种常见的索引类型扫描: 14 | 15 | 第一种:index unique  scan 16 | 17 |     索引唯一扫描,当可以优化器发现某个查询条件可以利用到主键、唯一键、具有外键约束的列,或者只是访问其中某行索引所在的数据的时候,优化器会选择这种扫描类型。 18 | 19 | 第二种:index range scan 20 | 21 |     索引范围扫描,当优化器发现在UNIQUE列上使用了大于、小于、大于等于、小于等于以及BETWEEN等就会使用范围扫描,在组合列上只使用部分进行查询,导致查询出多行数据。对非唯一的索引列上进行任何活动都会使用index range scan。 22 | 23 | 第三种:index full scan 24 | 25 |     全索引扫描,如果要查询的数据可以全部从索引中获取,则使用全索引扫描。 26 | 27 | 第四种:index fast full scan 28 | 29 |     索引快速扫描,扫描索引中的全部的数据块,与全索引扫描的方式基本上类似。两者之间的明显的区别是,索引快速扫描对查询的数据不进行排序,数据返回的时候不是排序的。“在这种存取方法中,可以使用多块读功能,也可以使用并行读入,从而得到最大的吞吐量和缩短执行时间”。 30 | 31 | order by、group by使用索引的前提条件: 32 | 33 | 1.order by、group by中所有的列必须包含在相同的索引中并保持在索引中的排列顺序; 34 | 35 | 2.order by、group by中所有的列必须定义为非空 36 | 37 | ##### 不走索引的几种情况: 38 | 39 | 1.where子句中使用 is null 和 is not null 40 | 41 | 2.where子句中使用函数 42 | 43 | 3.使用like ‘%T’ 进行模糊查询 44 | 45 | 4.where子句中使用不等于操作(包括:<>, !=, not colum >= ?, not colum <= ? ,可以使用or代替) 46 | 47 | 5.比较不匹配数据类型,例如:select * from tablewhere jlbh = 1;jlbh为varchar2类型字段 48 | 49 | 50 | -------------------------------------------------------------------------------- /02数据存取/7oracle/3窗口函数.md: -------------------------------------------------------------------------------- 1 | ## 窗口函数 2 | 3 | #### 分类 4 | 5 | 1. 能够作为窗口函数的聚合函数(sum,avg,count,max,min) 6 | 2. rank,dense_rank,row_number等专用窗口函数 7 | 8 | ##### 专用函数的种类 9 | 10 | 1. rank函数:计算排序时,如果存在相同位次的记录,则会跳过之后的位次。 11 | 2. dense_rank函数:同样是计算排序,即使存在相同位次的记录,也不会跳过之后的位次。 12 | 3. row_number函数:赋予唯一的连续位次。 13 | 14 | #### 语法 15 | 16 | <窗口函数> over ([partition by <列清单>] 17 | order by <排序用列清单>) 18 | 19 | ```sql 20 | select product_name, product_type, sale_price, 21 | rank () over (partition by product_type 22 | order by sale_price) as ranking 23 | from Product; 24 | ``` -------------------------------------------------------------------------------- /02数据存取/7oracle/4数据库创建.md: -------------------------------------------------------------------------------- 1 | ## 数据库操作 2 | 3 | - 创建表空间 4 | ```sql 5 | -- Create TableSpace 表空间名称 DataFile 表空间数据文件路径 Size 表空间初始大小 Autoextend on; 6 | create tablespace db_test datafile 'D:\oracle\product\10.2.0\userdata\db_test.dbf' size 50m autoextend on; 7 | 8 | ``` 9 | 10 | - 创建用户 11 | ```sql 12 | -- CREATE USER 用户名 IDENTIFIED BY 密码 DEFAULT TABLESPACE 表空间(默认USERS) TEMPORARY TABLESPACE 临时表空间(默认TEMP) ; 13 | CREATE USER utest IDENTIFIED BY utestpwd DEFAULT TABLESPACE db_test TEMPORARY TABLESPACE temp; 14 | 15 | ``` 16 | 17 | - 分配权限 18 | ```sql 19 | GRANT CONNECT TO utest; 20 | GRANT RESOURCE TO utest; 21 | GRANT dba TO utest;--dba为最高级权限,可以创建数据库,表等。 22 | ``` -------------------------------------------------------------------------------- /02数据存取/8postgres/.images/jg.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/02数据存取/8postgres/.images/jg.jpeg -------------------------------------------------------------------------------- /02数据存取/8postgres/.images/postgresSQL流程.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/02数据存取/8postgres/.images/postgresSQL流程.png -------------------------------------------------------------------------------- /02数据存取/8postgres/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | [德哥的博客](https://github.com/digoal/blog) 4 | 5 | [10.0中文文档](http://www.postgres.cn/docs/10/index.html) 6 | 7 | 1. [版本迭代](./1版本迭代.md) 8 | 9 | 2. [2核心架构](./2核心架构.md) 10 | 11 | 3. [日志](./3日志.md) 12 | 13 | 4. [索引](./4索引.md) 14 | 15 | 5. [事务和锁](./5事务和锁.md) 16 | 17 | 6. [优化](./6优化.md) 18 | 19 | 7. [执行计划](./7执行计划.md) 20 | 21 | 8. [应用场景](./8应用场景.md) 22 | 23 | 9. [数据复制订阅](9数据复制订阅.md) 24 | 25 | 10. [压力测试](./10压力测试.md) 26 | 27 | 11. [11特殊类型操作](./11特殊类型操作.md) 28 | 29 | 12. [全文检索](./12全文检索.md) 30 | 31 | 13. [窗口函数和with语法](./13窗口函数和with语法.md) 32 | 33 | 14. [分区表](./14分区表.md) 34 | 35 | 15. [测试数据](15测试数据.md) 36 | 37 | 16. [数据库之间的比较](16数据库之间的比较.md) 38 | 39 | 17. [FDW的使用](17FDW的使用.md) 40 | 41 | 18. [数据库监控](18数据库监控.md) 42 | 43 | 19. [插件](19%E6%8F%92%E4%BB%B6.md) 44 | 20. 45 | 21. [配置](./20%E9%85%8D%E7%BD%AE.md) -------------------------------------------------------------------------------- /02数据存取/8postgres/11特殊类型操作.md: -------------------------------------------------------------------------------- 1 | ## 特殊类型操作 2 | 3 | #### jsonb 4 | 5 | ```sql 6 | -- 查看元素信息 7 | test=# select * from t_arr where id=4; 8 | id | arr 9 | ----+-------------------------------------- 10 | 4 | {"foo": ["f0032", "f0045", "f0047"]} 11 | 12 | -- 修改一个元素 13 | update t_arr set arr = jsonb_set(arr,'{foo}',(arr->'foo') - 'f0032') where id=4; 14 | 15 | ``` -------------------------------------------------------------------------------- /02数据存取/8postgres/16数据库之间的比较.md: -------------------------------------------------------------------------------- 1 | ## 数据库之间的比较 2 | 3 | - [pg和mysql比较](https://www.biaodianfu.com/mysql-vs-postgresql.html) 4 | 5 | 6 | ### 比较 7 | 8 | |比较项|Oracle|Mysql|Postgres| 9 | |---|:---|:---|:---| 10 | |表类型|堆表(默认)和索引组织表|Innodb(索引组织表) MyISAM(堆表)|堆表| 11 | |运行模式|多进程|多线程|多进程| 12 | |使用协议|闭源|GPL和商业双重协议|BSD协议| 13 | |数据类型|空间类型,json|json,基础空间类型|jsonb,网络地址,空间类型,全文检索等| 14 | |支持索引|b-tree,hash,reverse,bitmap,gist,表达式|full-text,b-tree,hash,r-tree|b-tree,hash,gin,gist,spgist,brin,bloom,rum,zombodb| 15 | |异构外部表|支持不完全|不支持|几乎支持任意外部数据源(FDW方式)| 16 | |并行|支持不完全|不支持|创建btree索引,hash join,扫描分区表| 17 | |拓展编程|不支持|不支持|大部分语言| 18 | |易上手|难|简单|中等| 19 | 20 | 21 | ### 名称解释 22 | 1. 表类型 23 | - 堆表(Heap Table): 数据是散放的,索引和表的数据是分离的,获取按照命中率获取 24 | - 索引组织表(IOT): 表是一个B树,按照索引来存放,数据存放在叶子节点,与插入的顺序没有关系 25 | - 溢出段(OVERFLOW):当表的行数据量很大的时候,会降低查询性能,将溢出数据分开存放.2种方式:PCTTHRESHOLD n(百分比) 和 INCLUDING column_name(指定列) 26 | - 对比: 27 | - HP: 插入更新频繁 不经常使用主键查找 28 | - IOT: 主键递增 主键(唯一键)查找 查找频繁 29 | 2. 运行模式 30 | - 随着硬件越来越便宜,多进程更能利用资源 31 | 32 | 33 | ## 基于PG,拓展的项目 34 | - [PostGIS](http://www.postgis.org/): 提供空间对象、空间索引、空间操作函数和空间操作符。同时,PostGIS遵循OpenGIS的规范 35 | - [pipelinedb](https://www.pipelinedb.com/): 所有的接口都是SQL操作的流式计算数据库 36 | - [postBIS](https://colab.mpi-bremen.de/postbis/svn/trunk/) :基因测序 37 | 38 | 39 | -------------------------------------------------------------------------------- /02数据存取/8postgres/17FDW的使用.md: -------------------------------------------------------------------------------- 1 | ## FDW的使用 2 | 3 | [pgspider](https://github.com/pgspider/pgspider) 4 | 5 | #### 一些镜像 6 | [一些镜像](./fdw_dockerfile/README.md) 7 | 8 | - 查看可以使用的拓展 9 | ```sql 10 | select * from pg_available_extensions 11 | ``` 12 | 13 | - 查看正在使用的拓展 14 | ```bash 15 | postgres=# \dx 16 | List of installed extensions 17 | Name | Version | Schema | Description 18 | -----------+---------+------------+-------------------------------- 19 | plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language 20 | redis_fdw | 1.0 | public | foreign-data wrapper for Redis 21 | 22 | ``` -------------------------------------------------------------------------------- /02数据存取/8postgres/18数据库监控.md: -------------------------------------------------------------------------------- 1 | ## 数据库监控 2 | 3 | #### 工具 4 | - [pgwatch2](https://github.com/cybertec-postgresql/pgwatch2) -------------------------------------------------------------------------------- /02数据存取/8postgres/19插件.md: -------------------------------------------------------------------------------- 1 | # 插件 2 | 3 | ## smlar(数组相似度计算) 4 | 5 | - [PostgreSQL扩展之smlar](https://www.modb.pro/db/45322) 海明距离 6 | 7 | ## PASE(基于IVFFlat或HNSW算法)实现高效向量检索 8 | -------------------------------------------------------------------------------- /02数据存取/8postgres/1版本迭代.md: -------------------------------------------------------------------------------- 1 | ## 版本迭代 2 | 3 | - 7.2(2002年) 4 | 5 | 支持postgis插件,原来clob大小8kb,限制了存储复杂的字段 6 | 7 | - 8.4 8 | 9 | 窗口查询 并行恢复 递归查询 10 | 11 | - 9.0 12 | 13 | 异步流式复制(基于redo record) 14 | 15 | - 9.1 16 | 17 | 同步流式复制(支持事务主从复制) KNN查询索引支持(根据经纬度查询最近用户,根据数值查询最近邻数值,根据文本相似度查询最相似文本) 18 | 距离排序 FDW接口 19 | - 9.2 20 | 21 | SP-GIST索引 范围类型 JSON 支持plv8 级联流式复制 22 | 23 | - 9.3 24 | 25 | 物化视图 可写FDW 事件触发器(保护DBA) 26 | 27 | - 9.4 28 | 29 | 支持JSONB 增量物化视图 逻辑流式复制 缓存预热 正则查询(中文,gin索引查询,中文分词400万/s) ~秒级返回,性能接近elastic 30 | 31 | - 9.5 32 | 33 | 支持适合流式数据的索引{块级索引BRIN} 多核性能加强 OLAP增强 GPU并行加速 34 | 35 | - 9.6 36 | 37 | 多核并行计算(bits) 多副本同步流式复制 38 | 39 | - 17.4 40 | 41 | 42 | 43 | #### 安装 44 | 45 | [官方安装地址](http://www.postgresql.org/download/) 46 | 47 | 如果想要安装pg_config, postgresql[版本号]-devel 48 | -------------------------------------------------------------------------------- /02数据存取/8postgres/20配置.md: -------------------------------------------------------------------------------- 1 | # 配置 2 | 3 | - 设置只读账号 4 | 5 | ```sql 6 | CREATE USER read_only_sdp WITH ENCRYPTED PASSWORD 'read_only_pw'; 7 | ALTER USER read_only SET default_transaction_read_only=on; 8 | GRANT USAGE ON SCHEMA public to read_only; 9 | GRANT SELECT ON ALL TABLES IN SCHEMA public TO read_only; 10 | ``` -------------------------------------------------------------------------------- /02数据存取/8postgres/3日志.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/02数据存取/8postgres/3日志.md -------------------------------------------------------------------------------- /02数据存取/8postgres/6优化.md: -------------------------------------------------------------------------------- 1 | ## 优化 2 | 3 | [坑和优化](https://www.cnblogs.com/zhangeamon/p/8269295.html) 4 | 5 | 1. 历史数据的清理 6 | ```sql 7 | --未优化语句 8 | delete from line_queue where created_time < '2019-01-01' and status = 'deleted'; 9 | --优化语句,查找符合条件的5000条语句,每1秒执行一次,直到没有符合的语句 10 | delete from line_queue where id in (select id from line_queue where created_time < '2019-01-01' and status = 'deleted' limit 5000); \watch 1 11 | 12 | ``` 13 | 14 | 2. PostgreSQL 12支持ctid(物理行号)的nestloop join。使得表自关联的性能大幅度提升 15 | 16 | 3. 使用`pgfincore`能够直接把磁盘内容刷到内存,又不占用pg的buffer 17 | 18 | 4. json和jsonb 19 | 20 | | 特性 | JSON | JSONB | 21 | |---------------|-----------------------------------|------------------------------------| 22 | | 存储格式 | 纯文本(保留原始格式) | 二进制(解析后的结构化格式) | 23 | | 空格/格式 | 保留所有空格、键顺序、重复键 | 去除空格,键顺序不固定,去重键 | 24 | | 写入速度 | 快(无需解析) | 稍慢(需解析并转换为二进制) | 25 | | 存储空间 | 较大(保留原始格式) | 较小(优化后的二进制格式) | -------------------------------------------------------------------------------- /02数据存取/8postgres/7执行计划.md: -------------------------------------------------------------------------------- 1 | ## 执行计划 2 | 3 | [explain 输出及详解](https://dreamer-yzy.github.io/2014/12/23/PostgreSQL%E6%89%A7%E8%A1%8C%E8%AE%A1%E5%88%92%E5%92%8C%E6%88%90%E6%9C%AC%E5%9B%A0%E5%AD%90%E8%AF%A6%E8%A7%A3/) 4 | 5 | - analyze: 查看实际执行 6 | - verbose: 显示详细信息 7 | - costs: 显示代价信息 8 | - buffers: 显示缓存信息 9 | - timing: 显示时间信息 10 | 11 | -------------------------------------------------------------------------------- /02数据存取/8postgres/8应用场景.md: -------------------------------------------------------------------------------- 1 | ## 应用场景 2 | 3 | #### 地理位置 4 | - [postgres+postgis镜像地址](https://github.com/appropriate/docker-postgis) 5 | - [开源地图](https://www.openstreetmap.org) 6 | - [docker-postgis](https://github.com/appropriate/docker-postgis) 7 | - [gcoord 前端JS库](https://github.com/hujiulong/gcoord) 地理坐标系转换工具,支持WGS84/GCJ02/BD09等常用坐标系互转 8 | 9 | ##### 概念 10 | 11 | 目前用得最多的有SRID=4326球坐标,SRID为EPSG:3857的墨卡托投影坐标 12 | 13 | [引用](https://github.com/digoal/blog/blob/master/201709/20170911_01.md) 14 | 15 | - 地理坐标系(球面坐标系)(Geographic coordinate system) 16 | 单位:度 17 | 18 | - 投影坐标系(平面坐标系) 19 | 投影的条件: 20 | a、球面坐标 21 | b、转化过程(也就是算法) 22 | 23 | 单位:米 24 | 将球面坐标转化为平面坐标的过程便称为投影 25 | -------------------------------------------------------------------------------- /02数据存取/8postgres/9数据复制订阅.md: -------------------------------------------------------------------------------- 1 | ## 数据复制订阅 2 | 3 | [数据同步与订阅](数据复制订阅/数据同步与订阅.md) 4 | [数据同步与订阅第三方程序](数据复制订阅/数据同步与订阅第三方程序/README.md) 5 | 6 | #### 数据复制 7 | 8 | 1. 物理复制 9 | 好处:物理层面一致,延迟低 坏处:主备块级一致,无法覆盖场景(复制部分数据,从多个数据源复制,不同版本之间数据复制) 10 | 11 | 2. 流复制 12 | 所谓流复制,就是从服务器通过tcp流从主服务器中同步相应的数据,流WAL记录到从服务器, 13 | PostgreSQL流复制默认是异步的,延迟1秒之内,如果主服务器崩溃,少量数据丢失, 14 | 同步流复制:等主服务器和从服务器都写完WAL后才能提交事务。这样在一定程度上会增加事务的响应时间。**配置参数synchronous_commit=on** 15 | 16 | 复制流程:当用户连接进行数据操作,产生对应的WAL日志记录后,walwriter会周期性地把产生的WALpage刷新到磁盘中,如果配置了备库,则walsender会不断将WAL page发给备库的walreceiver进程,walreceiver进程会把对应WAL page直接写到本地磁盘,同时slave上的startup辅助进程会不断地应用xlog日志,改变本地数据,实现与主库之间的数据同步。而且,通过配置,备库是可以接受用户的只读请求 17 | 18 | 19 | 20 | 3. 逻辑复制 21 | 基于WAL实现表级别的复制 22 | 23 | 24 | #### 数据订阅 25 | 26 | [amazonriver](https://github.com/hellobike/amazonriver) pg数据到kafka es 27 | 28 | [bottledwater-pg](https://github.com/confluentinc/bottledwater-pg) pg到kafka -------------------------------------------------------------------------------- /02数据存取/8postgres/fdw_dockerfile/README.md: -------------------------------------------------------------------------------- 1 | ## FDW的一下实践 2 | 3 | - docker镜像 4 | - [pgspider](https://hub.docker.com/r/dalongrong/pgspider) pg fdw各种镜像 5 | - [pg-redis](docker-compose-redis.yaml) pg redis docker-compose 6 | - [pgspider-docker](https://github.com/rongfengliang/pgspider-docker) pgspider-docker 7 | 8 | 9 | ## 使用文档 10 | - [rw_redis_fdw](https://github.com/nahanni/rw_redis_fdw) redis fdw仓库 11 | - [pg-es-fdw](https://github.com/Mikulas/pg-es-fdw) pg es fdw仓库 -------------------------------------------------------------------------------- /02数据存取/8postgres/fdw_dockerfile/docker-compose-redis.yaml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | redis: 4 | image: redis 5 | ports: 6 | - "6379:6379" 7 | pg-redis: 8 | image: dalongrong/pgspider:redis 9 | ports: 10 | - "5432:5432" 11 | environment: 12 | - "POSTGRES_PASSWORD:dalong" 13 | -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/config/mysql/init.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/02数据存取/8postgres/数据复制订阅/config/mysql/init.sql -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/config/mysql/my.cnf: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | user=mysql 3 | default-storage-engine=INNODB 4 | server-id=11 5 | log_bin=/var/lib/mysql/mysql-bin 6 | character-set-server=utf8 7 | [client] 8 | default-character-set=utf8 9 | [mysql] 10 | default-character-set=utf8 11 | -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/config/postgres/createdb.sql: -------------------------------------------------------------------------------- 1 | -- 创建数据库 2 | create database test with template template0 lc_collate "zh_CN.UTF8" lc_ctype "zh_CN.UTF8" encoding 'UTF8'; 3 | \c test 4 | 5 | -- 增加表 6 | CREATE TABLE public.info 7 | ( 8 | id serial PRIMARY KEY NOT NULL, 9 | name varchar(50) DEFAULT '' NOT NULL 10 | ); 11 | 12 | -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/config/postgres/pg_hba.conf: -------------------------------------------------------------------------------- 1 | # TYPE DATABASE USER ADDRESS METHOD 2 | 3 | # "local" is for Unix domain socket connections only 4 | local all all trust 5 | # IPv4 local connections: 6 | host all all 127.0.0.1/32 trust 7 | # IPv6 local connections: 8 | host all all ::1/128 trust 9 | # Allow replication connections from localhost, by a user with the 10 | # replication privilege. 11 | local replication all trust 12 | host replication all 127.0.0.1/32 trust 13 | host replication all ::1/128 trust 14 | 15 | host all all all md5 16 | host replication postgres all md5 17 | -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | mysqldbt: 4 | image: 'mysql/mysql-server:5.7' 5 | restart: always 6 | command: --default-authentication-plugin=mysql_native_password 7 | environment: 8 | MYSQL_ROOT_PASSWORD: root 9 | MYSQL_DATABASE: user 10 | MYSQL_USER: test 11 | MYSQL_PASSWORD: test 12 | volumes: 13 | - mysql-data-test:/var/lib/mysql 14 | - ./config/mysql/my.cnf:/etc/my.cnf 15 | - ./config/mysql/:/docker-entrypoint-initdb.d/ 16 | ports: 17 | - '3307:3306' 18 | postgres-send: 19 | image: 'postgres:11.4-alpine' 20 | restart: always 21 | environment: 22 | POSTGRES_PASSWORD: meng 23 | PGDATA: /var/lib/postgresql/data/pgdata 24 | volumes: 25 | - ./pgdata/send_data:/var/lib/postgresql/data/pgdata 26 | - ./config/postgres/:/docker-entrypoint-initdb.d/ 27 | ports: 28 | - '5432:5432' 29 | postgres-sub: 30 | image: 'postgres:11.4-alpine' 31 | restart: always 32 | environment: 33 | POSTGRES_PASSWORD: meng 34 | PGDATA: /var/lib/postgresql/data/pgdata 35 | volumes: 36 | - ./pgdata/sub_data:/var/lib/postgresql/data/pgdata 37 | - ./config/postgres/:/docker-entrypoint-initdb.d/ 38 | ports: 39 | - '5433:5432' 40 | # 这个是测试 41 | 42 | volumes: 43 | mysql-data-test: 44 | postgres-data-send: 45 | postgres-data-sub: 46 | 47 | -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/数据同步与订阅第三方程序/.gitignore: -------------------------------------------------------------------------------- 1 | syncdb 2 | -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/数据同步与订阅第三方程序/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "pg_dump_path": "", 3 | "subscribes": [{ 4 | "dump": false, 5 | "slotName": "slot_for_kafka", 6 | "pgConnConf": { 7 | "host": "192.168.10.128", 8 | "port": 5432, 9 | "database": "test", 10 | "user": "postgres", 11 | "password": "meng" 12 | }, 13 | "rules": [ 14 | { 15 | "table": "student", 16 | "pks": ["id"], 17 | "topic": "student_name_logs" 18 | } 19 | ], 20 | "kafkaConf": { 21 | "addrs": ["192.168.10.128:9092"] 22 | }, 23 | "retry": 0 24 | }], 25 | "prometheus_address": ":8080" 26 | } 27 | -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/数据同步与订阅第三方程序/pg_config.sh: -------------------------------------------------------------------------------- 1 | cp ./pgconfig/pg_hba.conf ./pg_data/pg_hba.conf 2 | cp ./pgconfig/postgresql.conf ./pg_data/postgresql.conf 3 | cp ./pgconfig/pg_hba.conf ./pg_sub_data/pg_hba.conf 4 | cp ./pgconfig/postgresql.conf ./pg_sub_data/postgresql.conf 5 | 6 | 7 | -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/数据同步与订阅第三方程序/pgconfig/createdb.sql: -------------------------------------------------------------------------------- 1 | -- 创建数据库 2 | create database test with template template0 lc_collate "zh_CN.UTF8" lc_ctype "zh_CN.UTF8" encoding 'UTF8'; 3 | \c test 4 | 5 | -- 增加 6 | CREATE TABLE public.student 7 | ( 8 | id serial PRIMARY KEY NOT NULL, 9 | name varchar(50) DEFAULT '' NOT NULL, 10 | version varchar(20) DEFAULT '0.0.0' NOT NULL 11 | ); 12 | COMMENT ON COLUMN public.sys_info.name IS '名称'; 13 | COMMENT ON COLUMN public.sys_info.version IS '版本号'; 14 | COMMENT ON TABLE public.sys_info IS '学生信息表'; 15 | 16 | -- 添加 17 | INSERT INTO public.student(name,version) values('student01','0.0.0'); 18 | -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/数据同步与订阅第三方程序/pgconfig/pg_hba.conf: -------------------------------------------------------------------------------- 1 | # TYPE DATABASE USER ADDRESS METHOD 2 | 3 | # "local" is for Unix domain socket connections only 4 | local all all trust 5 | # IPv4 local connections: 6 | host all all 127.0.0.1/32 trust 7 | # IPv6 local connections: 8 | host all all ::1/128 trust 9 | # Allow replication connections from localhost, by a user with the 10 | # replication privilege. 11 | local replication all trust 12 | host replication all 127.0.0.1/32 trust 13 | host replication all ::1/128 trust 14 | 15 | host all all all md5 16 | host replication test_rep all md5 17 | -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/数据同步与订阅第三方程序/preconfig/alertmanager.yml: -------------------------------------------------------------------------------- 1 | global: 2 | smtp_smarthost: 'smtp.mxhichina.com:465' 3 | smtp_from: '123@qq.com' 4 | smtp_auth_username: '123@qq.com' 5 | smtp_auth_password: '****' 6 | smtp_require_tls: true 7 | 8 | route: 9 | group_by: ['alertname'] 10 | group_wait: 10s 11 | group_interval: 10s 12 | repeat_interval: 10m 13 | receiver: live-monitoring 14 | 15 | receivers: 16 | - name: 'live-monitoring' 17 | email_configs: 18 | - to: 'mengqingfang@highershine.com' 19 | -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/数据同步与订阅第三方程序/preconfig/node_down.yml: -------------------------------------------------------------------------------- 1 | groups: 2 | - name: node_down 3 | rules: 4 | - alert: InstanceDown 5 | expr: up == 0 6 | for: 1m 7 | labels: 8 | user: test 9 | annotations: 10 | summary: "Instance {{ $labels.instance }} down" 11 | description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 1 minutes." 12 | -------------------------------------------------------------------------------- /02数据存取/8postgres/数据复制订阅/数据同步与订阅第三方程序/preconfig/prometheus.yml: -------------------------------------------------------------------------------- 1 | # my global config 2 | global: 3 | scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. 4 | evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. 5 | # scrape_timeout is set to the global default (10s). 6 | 7 | # Alertmanager configuration 8 | alerting: 9 | alertmanagers: 10 | - static_configs: 11 | - targets: ['192.168.10.128:9093'] 12 | # - alertmanager:9093 13 | 14 | # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. 15 | rule_files: 16 | - "node_down.yml" 17 | # - "first_rules.yml" 18 | # - "second_rules.yml" 19 | 20 | # A scrape configuration containing exactly one endpoint to scrape: 21 | # Here it's Prometheus itself. 22 | scrape_configs: 23 | # The job name is added as a label `job=` to any timeseries scraped from this config. 24 | - job_name: 'prometheus' 25 | static_configs: 26 | - targets: ['192.168.10.128:9090'] 27 | 28 | - job_name: 'syncdb' 29 | static_configs: 30 | - targets: ['192.168.10.128:8080'] 31 | -------------------------------------------------------------------------------- /02数据存取/9分布式文件系统.md: -------------------------------------------------------------------------------- 1 | ## 分布式文件系统 2 | 3 | 1. [minio](https://github.com/minio/minio) 4 | 2. [seaweedfs](https://github.com/chrislusf/seaweedfs) 5 | 3. [go-ipfs](https://github.com/ipfs/go-ipfs) -------------------------------------------------------------------------------- /02数据存取/mongo.md: -------------------------------------------------------------------------------- 1 | # Mongo 2 | 3 | ## 数据同步 4 | 5 | ### 必须项 6 | - 启用副本集(必需):Checkpoint 依赖 MongoDB 的 ​​Change Streams​​ 功能,而 Change Streams 仅在副本集或分片集群中可用。 7 | - 调整 Oplog 大小(关键)​:记录所有数据变更操作,Checkpoint 依赖 Oplog 中的操作日志恢复同步进度。 8 | ```shell 9 | mongo -u sync_user -p secure_password --authenticationDatabase admin 10 | use your_database 11 | db.getCollection("target_collection").watch() # 测试能否监听变更流 12 | ``` 13 | - 同步工具配置示例(以 SeaTunnel 为例) 14 | ```yaml 15 | execution: 16 | checkpoint: 17 | interval: 3000 # Checkpoint间隔(毫秒) 18 | timeout: 60000 # Checkpoint超时时间 19 | storage: 20 | type: filesystem 21 | path: "hdfs:///seatunnel/checkpoints" # 推荐使用HDFS或S3等可靠存储 22 | ``` 23 | - MongoDB Source 配置​ 24 | ```yaml 25 | source: 26 | MongoDB: 27 | uri: "mongodb://sync_user:secure_password@host1:27017,host2:27017/?replicaSet=rs0&authSource=admin" 28 | database: "your_database" 29 | collection: "target_collection" 30 | # 自动使用 Checkpoint 中的 Resume Token 恢复进度 31 | ``` 32 | 33 | ### 可选同步模式 34 | | 配置项 | 用途 | 依赖条件 | 35 | | ---------------------------- | ---------------------- | ------------------------------------------- | 36 | | `start_after_operation_time` | 从指定时间戳开始监听 | MongoDB ≥4.0,足够的 Oplog 容量,副本集模式 | 37 | | `resume_token` | 从精确断点恢复监听 | 需记录上一次的 Resume Token | 38 | | `Checkpoint` | 自动记录和恢复同步进度 | 需配置可靠的 Checkpoint 存储(如 HDFS) | -------------------------------------------------------------------------------- /03容器和集群/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | 4 | 1. [docker](./1docker/0目录.md) 5 | 6 | 2. [k8s](./2k8s/0目录.md) 7 | 8 | 3. [服务网格](./3服务网格/0目录.md) 9 | 10 | 4. [helm](./4helm.md) 11 | 12 | 5. [virt-manager](./5virt-manager.md) 13 | -------------------------------------------------------------------------------- /03容器和集群/1docker/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | - [国内安装](https://yq.aliyun.com/articles/110806) 4 | 5 | 1. [常见问题](./1常见问题.md) 6 | 7 | 2. docker管理 8 | ```bash 9 | docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer 10 | ``` 11 | -------------------------------------------------------------------------------- /03容器和集群/1docker/1常见问题.md: -------------------------------------------------------------------------------- 1 | ## 常见问题 2 | 3 | - 安装docker出现缺少`libsystemd-journal0` 4 | 添加源 `deb http://cz.archive.ubuntu.com/ubuntu trusty main`,然后`sudo apt-get update && sudo apt-get install libsystemd-journal0` 5 | 6 | - 国内安装 7 | 8 | [国内安装](https://yq.aliyun.com/articles/110806) 9 | [搭建mxnet-gpu docker的pyhon remote kernel](https://www.cnblogs.com/dwsun/p/7833580.html) 10 | ```shell 11 | curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun 12 | ``` 13 | - alpine镜像时区问题 14 | 15 | [构建镜像的过程参考](https://segmentfault.com/a/1190000009107014) 16 | 17 | ```shell 18 | FROM alpine:3.2 19 | #添加时区 20 | RUN set -xe && apk add --no-cache tzdata && cp -r -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 21 | ADD account_api /account_api 22 | ENTRYPOINT [ /account_api ] 23 | 24 | ``` 25 | 26 | - 镜像加速 27 | [镜像加速列表](https://xuanyuan.me/blog/archives/1154) 28 | 29 | - 国内源 30 | 31 | ```json 32 | { 33 | "registry-mirrors": [ 34 | "https://docker.1ms.run", 35 | "https://docker.xuanyuan.me" 36 | ], 37 | "insecure-registries" : [ 38 | "registry.docker-cn.com", 39 | "docker.mirrors.ustc.edu.cn" 40 | ], 41 | "debug" : true, 42 | "experimental" : true 43 | } 44 | ``` 45 | 46 | - docker-compose 创建一个子网 47 | ```yaml 48 | version: '3.2' 49 | 50 | services: 51 | metabase: 52 | restart: always 53 | image: metabase/metabase:latest 54 | container_name: metabase 55 | networks: 56 | - event-net 57 | 58 | networks: 59 | event-net: 60 | ipam: 61 | driver: default 62 | config: 63 | - subnet: "192.168.33.0/24" 64 | ``` 65 | 66 | - 如何查看docker启动命令 67 | 68 | - runlink -------------------------------------------------------------------------------- /03容器和集群/2k8s/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | - [k8s概念介绍](https://zhuanlan.zhihu.com/p/379270517) 4 | 5 | 1. [安装](./1安装.md) 6 | 7 | 2. [命令](./2命令.md) 8 | 9 | 10 | 11 | ### 安装k8s 12 | - [rke](https://rke.docs.rancher.com/) docker安装k8s 13 | - [kubesphere](https://kubesphere.io/zh/) 14 | 15 | ### 常见面试题 16 | - [20道常见面试题](https://mp.weixin.qq.com/s?__biz=Mzg3MDg5NTU3MQ==&mid=2247485343&idx=1&sn=602fe98f8c1f7974a1e027294db536f2&chksm=cf1110d2b009b6b34134a8d29fe790c5a4b65d6ebd1ce6a9578d9afbdac7af3497420f06f49e#rd) -------------------------------------------------------------------------------- /03容器和集群/2k8s/1安装.md: -------------------------------------------------------------------------------- 1 | ##### 国内源 2 | 3 | - [sealos](https://github.com/fanux/sealos) 一键安装k8s高可用集群 4 | - [KubeOperator](https://github.com/KubeOperator/KubeOperator/) 可用于生成环境的一键安装 5 | 6 | 7 | ``` 8 | #############################apt######################### 9 | cat < /etc/apt/sources.list.d/kubernetes.list 10 | deb http://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main 11 | EOF 12 | 13 | ###########################yum############################ 14 | cat < /etc/yum.repos.d/kubernetes.repo 15 | [kubernetes] 16 | name=Kubernetes 17 | baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 18 | enabled=1 19 | gpgcheck=0 20 | repo_gpgcheck=0 21 | gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg 22 | http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg 23 | EOF 24 | 25 | 26 | ``` 27 | 28 | - k3s 安装 29 | [k3d](https://github.com/rancher/k3d) docker安装k3s 30 | 31 | ```bash 32 | curl -s https://raw.githubusercontent.com/rancher/k3d/master/install.sh | bash 33 | ``` 34 | 35 | - 一键部署 36 | 37 | - [KubeOperator](https://github.com/KubeOperator/KubeOperator) -------------------------------------------------------------------------------- /03容器和集群/2k8s/service.md: -------------------------------------------------------------------------------- 1 | ## Service 2 | 3 | ### type 4 | 5 | [k8s四种port解析](https://blog.csdn.net/a772304419/article/details/113447005) 6 | 7 | - nodePort: 8 | 9 | 10 | ### kube-proxy模式 11 | 12 | - ip-tables模式:当service或者endpoints、pod发生变化时,kube-proxy会创建对应的iptables规则。 13 | - Userspace模式:这种模式时最早的,不过已经不推荐使用了,效率低,因为需要在内核态和用户态多次转换。 14 | - IPVS代理模式:当service有成千上万个的时候速度上会更占优势。而且有更多的lb策略。 15 | 16 | -------------------------------------------------------------------------------- /03容器和集群/2k8s/配置文件/rbac.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: ClusterRole 3 | metadata: 4 | name: micro-registry 5 | rules: 6 | - apiGroups: 7 | - "" 8 | resources: 9 | - pods 10 | verbs: 11 | - list 12 | - patch 13 | - watch 14 | --- 15 | apiVersion: rbac.authorization.k8s.io/v1 16 | kind: RoleBinding 17 | metadata: 18 | name: micro-registry 19 | roleRef: 20 | apiGroup: rbac.authorization.k8s.io 21 | kind: ClusterRole 22 | name: micro-registry 23 | subjects: 24 | - kind: ServiceAccount 25 | name: account-srv 26 | namespace: default 27 | - kind: ServiceAccount 28 | name: account-api 29 | namespace: default 30 | 31 | --- 32 | apiVersion: v1 33 | kind: ServiceAccount 34 | metadata: 35 | name: account-api #重点 36 | namespace: default 37 | --- 38 | apiVersion: extensions/v1beta1 39 | kind: Deployment 40 | metadata: 41 | namespace: default 42 | name: greeter 43 | spec: 44 | replicas: 1 45 | template: 46 | metadata: 47 | labels: 48 | app: greeter-srv 49 | spec: 50 | #重点 51 | serviceAccountName: greeter-srv 52 | containers: 53 | - name: greeter 54 | image: microhq/greeter-srv:kubernetes 55 | command: [ 56 | "/greeter-srv", 57 | "--server_address=0.0.0.0:8080", 58 | "--broker_address=0.0.0.0:10001" 59 | ] 60 | ports: 61 | - containerPort: 8080 62 | name: greeter-port 63 | -------------------------------------------------------------------------------- /03容器和集群/2k8s/配置文件/资源限制.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: LimitRange 3 | metadata: 4 | name: mylimits 5 | spec: 6 | limits: 7 | - max: 8 | cpu: "2" 9 | memory: 1Gi 10 | min: 11 | cpu: 200m 12 | memory: 6Mi 13 | type: Pod 14 | 15 | - default: 16 | cpu: 300m 17 | memory: 200Mi 18 | defaultRequest: 19 | cpu: 200m 20 | memory: 100Mi 21 | max: 22 | cpu: "2" 23 | memory: 1Gi 24 | min: 25 | cpu: 100m 26 | memory: 3Mi 27 | type: Container 28 | 29 | 30 | #pod 31 | #cpu最大限制2核, 最小200MHZ 32 | #内存最大限制1G, 最小6M 33 | 34 | #Container 35 | 36 | #cpu最大限制2核, 最小200MHZ 37 | #内存最大限制1G, 最小6M 38 | #默认启动cpu最大限制300MHZ, 内存最大限制200M 39 | 40 | #kubectl create -f limits.yaml -n xxx #-n:namespace 41 | --- 42 | #创建容器时候指定 43 | spec: 44 | containers: 45 | - image: gcr.io/google_containers/serve_hostname 46 | imagePullPolicy: Always 47 | name: kubernetes-serve-hostname 48 | resources: 49 | limits: 50 | cpu: "1" 51 | memory: 512Mi 52 | requests: 53 | cpu: "1" 54 | memory: 512Mi 55 | -------------------------------------------------------------------------------- /03容器和集群/3服务网格/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | - [istio](https://github.com/istio/istio) 4 | - [官网](https://istio.io) 5 | - [中文文档](https://preliminary.istio.io/zh/docs/) 6 | 7 | 1. [概念](./1概念.md) 8 | 9 | 1. [常用命令](./2常用命令.md) 10 | 11 | 1. [k3s安装istio](./3k3s安装istio.md) -------------------------------------------------------------------------------- /03容器和集群/3服务网格/1概念.md: -------------------------------------------------------------------------------- 1 | ## 概念 2 | 3 | ![说明](https://preliminary.istio.io/docs/concepts/what-is-istio/arch.svg) 4 | 5 | #### Envoy 6 | 7 | Envoy 是以 C++ 开发的高性能代理,用于调解服务网格中所有服务的所有入站和出站流量 8 | 9 | - 动态服务发现 10 | - 负载均衡 11 | - TLS 终止 12 | - HTTP/2 & gRPC 代理 13 | - 熔断器 14 | - 健康检查、基于百分比流量拆分的灰度发布 15 | - 故障注入 16 | - 丰富的度量指标 17 | 18 | Envoy 被部署为 sidecar,和对应服务在同一个 Kubernetes pod 中。这允许 Istio 将大量关于流量行为的信号作为属性提取出来,而这些属性又可以在 Mixer 中用于执行策略决策,并发送给监控系统,以提供整个网格行为的信息。 19 | 20 | #### Mixer 21 | 22 | Mixer 是一个独立于平台的组件,负责在服务网格上执行访问控制和使用策略,并从 Envoy 代理和其他服务收集遥测数据。代理提取请求级属性,发送到 Mixer 进行评估 23 | 24 | #### Pilot 25 | 26 | Pilot 为 Envoy sidecar 提供服务发现功能,为智能路由(例如 A/B 测试、金丝雀部署等)和弹性(超时、重试、熔断器等)提供流量管理功能。它将控制流量行为的高级路由规则转换为特定于 Envoy 的配置,并在运行时将它们传播到 sidecar 27 | 28 | #### Citadel 29 | 30 | Citadel 通过内置身份和凭证管理可以提供强大的服务间和最终用户身份验证。可用于升级服务网格中未加密的流量,并为运维人员提供基于服务标识而不是网络控制的强制执行策略的能力 31 | 32 | -------------------------------------------------------------------------------- /03容器和集群/3服务网格/2常用命令.md: -------------------------------------------------------------------------------- 1 | ## 常用命令 2 | 3 | ### 查看自动注入的命名空间 4 | ```bash 5 | kubectl get namespace -L istio-injection 6 | ``` 7 | ### 查看集群内部一个端口 8 | ```bash 9 | kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=kiali -o jsonpath='{.items[0].metadata.name}') 20001:20001 & 10 | ``` 11 | 12 | ### 手动注入 13 | ```bash 14 | istioctl kube-inject -f samples/sleep/sleep.yaml | kubectl apply -f - 15 | ``` -------------------------------------------------------------------------------- /03容器和集群/3服务网格/3k3s安装istio.md: -------------------------------------------------------------------------------- 1 | ## k3s安装istio 2 | 3 | 1. k3d安装k3s集群 4 | 5 | 2. 使用k3d创建安装`istio`的集群 6 | ```bash 7 | k3d create --server-arg --no-deploy --server-arg traefik --name istio-test 8 | ``` 9 | -------------------------------------------------------------------------------- /03容器和集群/5virt-manager.md: -------------------------------------------------------------------------------- 1 | ## virt-manager 2 | 3 | ### 扩展磁盘 4 | 5 | [扩展磁盘](http://pewei.cn/index.php/archives/174/) -------------------------------------------------------------------------------- /04linux/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | 1. [常用命令](1常用命令.md) 4 | 5 | 1. [优化](2优化.md) 6 | 7 | 1. [概念](3概念.md) 8 | 9 | 1. [工具](./4工具.md) 10 | 11 | 1. [显(N)卡安装](./5显(N)卡安装.md) 12 | 13 | 1. [nfs安装](./6nfs安装.md) 14 | 15 | 1. [iptables](./7iptables.md) -------------------------------------------------------------------------------- /04linux/2优化.md: -------------------------------------------------------------------------------- 1 | ## 优化 2 | 3 | [perf-tools](https://github.com/brendangregg/perf-tools) 4 | 5 | 1. 开启swap分区 6 | 7 | ```bash 8 | sudo dd if=/dev/zero of=/root/swapfile bs=1M count=4096 #增加 4G 交换空间 8G 8192 9 | sudo mkswap /root/swapfile #建立swap的文件系统 10 | sudo swapon /root/swapfile #启用swap文件 11 | echo "/root/swapfile swap swap defaults 0 0" | sudo tee -a /etc/fstab #更新 fstab 文件 12 | ``` 13 | 2. 查看进程使用内存 14 | 15 | ``` 16 | ps -e -o 'pid,comm,args,pcpu,rsz,vsz,stime,user,uid' | grep dist_game | sort -nrk5 17 | #其中rsz为实际内存,上例实现按内存排序,由大到小 18 | ``` 19 | 3. 性能测试(stress)和性能分析(sysstat) 20 | 21 | ```bash 22 | stress #--cpu cpu压测选项 -i io压测 -c 进程数 --timeout 执行时间 23 | mpstat -P ALL 2 5 #监控所有 2表示2s输出一次 5表示共输出5次 24 | pidstat -u 5 1 #查看进程状态 25 | #平均负载:单位时间内,处于可运行状态和不可中断状态的进程数,包括(正在使用CPU,等待CPU,等待I/O) 26 | # execsnoop 短时进程查看工具 27 | dstat 1 10 #查看cpu和io 28 | 29 | ``` 30 | 31 | 4. cpu使用率高异常高,查不到是那个进程,怎么办? 32 | 33 | ```bash 34 | #1. 使用top查看运行进程中,R状态的进程 35 | #2. 查看进程pid是否一直变化,是(短时间进程) 36 | #3. 使用pstree查看进程树 37 | 38 | ``` 39 | 5. 什么情况下会出现僵尸进程? 40 | - 子进程执行太快,父进程还没来得及回收 41 | - 父进程没有回收子进程的操作,父进程没结束(结束后由init进程回收) 42 | 43 | 6. 优化手段 44 | - 应用程序:编译器优化,算法优化,异步处理,多线程代替多进程,善用缓存 45 | - 系统优化:CPU绑定,CPU独占,优先级调整,进程设置资源限制,中断负载均衡 46 | 47 | 7. time_wait比较多,怎么处理? 48 | [参考文章](https://www.cnblogs.com/softidea/p/6062147.html) -------------------------------------------------------------------------------- /04linux/4工具.md: -------------------------------------------------------------------------------- 1 | ## 工具 2 | 3 | [linux基本命令查询](http://man.linuxde.net/) 4 | 5 | 1. cpu工具 6 | 7 | ![性能分析工具图](../.image/perf.png) 8 | ![工具](../.image/perf_tool.png) 9 | 10 | 2. 内存工具 11 | ![内存分析工具](../.image/mem_tool.png) 12 | 13 | 3.磁盘工具 14 | ![iostat性能指标](../.image/iostat.png) 15 | ![io](../.image/io_perf.png) 16 | 17 | 4. 网络工具 18 | 19 | 3. 外部工具 20 | 21 | - [bcc](https://github.com/iovisor/bcc) 跟踪工具 22 | - [perf-tools](https://github.com/brendangregg/perf-tools)优化工具 23 | - [pcstat](https://github.com/tobert/pcstat) 页缓存 24 | - [hping3](https://github.com/antirez/hping) 是一个可以构造 TCP/IP 协议数据包的工具,可以对系统进行安全审计、防火墙测试等。 25 | - [tcpdump]() 是一个常用的网络抓包工具,常用来分析各种网络问题 26 | - [fio]() 磁盘性能测试 27 | - [wrk](https://github.com/wg/wrk) http请求工具 28 | -------------------------------------------------------------------------------- /04linux/5显(N)卡安装.md: -------------------------------------------------------------------------------- 1 | ## 显卡安装 2 | 3 | - 查看集显 4 | ```shell script 5 | lspci | grep VGA # 查看集成显卡 6 | lspci | grep NVIDIA # 查看NVIDIA显卡 7 | ``` 8 | 9 | - 查看当前电脑的型号 10 | ```shell script 11 | lshw -numeric -C display 12 | ``` -------------------------------------------------------------------------------- /04linux/6nfs安装.md: -------------------------------------------------------------------------------- 1 | ## nfs安装 2 | 3 | #### ubuntu18.04安装 4 | [安装教程](https://www.linuxidc.com/Linux/2018-11/155331.htm) 5 | [选项说明](https://www.cnblogs.com/lykyl/archive/2013/06/14/3136921.html) 6 | ```bash 7 | # 安装服务 8 | sudo apt install nfs-kernel-server 9 | # 创建共享目录 10 | sudo mkdir -p /mnt/linuxidc 11 | # 设置目录权限(所有客户端都能访问该目录) 12 | sudo chown nobody:nogroup /mnt/linuxidc 13 | sudo chmod 777 /mnt/linuxidc 14 | # 设置导出 15 | sudo vim /etc/exports 16 | # /mnt/linuxidc *(rw,sync,no_subtree_check,no_root_squash) # *号代表任意客户端 17 | # /mnt/linuxidc 192.168.10.0/24(rw,sync,no_subtree_check,no_root_squash) # *号代表任意客户端 18 | # 重启服务 19 | sudo systemctl restart nfs-kernel-server 20 | # 开启访问防火墙 21 | sudo ufw allow from 192.168.182.0/24 to any port nfs 22 | # 查看服务状态 23 | nfsstat 24 | # 查询nfs共享目录信息 -a 显示已经于客户端连接上的目录信息 -e IP或者hostname 显示此IP地址分享出来的目录 25 | showmount 26 | ``` -------------------------------------------------------------------------------- /05大数据/0Hadoop.md: -------------------------------------------------------------------------------- 1 | ## Hadoop 2 | 3 | ![介绍](hadoop2.png) 4 | -------------------------------------------------------------------------------- /05大数据/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | ### 常见的大数据框架 4 | 5 | - 文件存储:Hadoop HDFS、Tachyon、KFS 6 | - 离线计算:Hadoop MapReduce、Spark 7 | - 流式、实时计算:Storm、Spark Streaming、S4、Heron 8 | - K-V、NOSQL数据库:HBase、Redis、MongoDB 9 | - 资源管理:YARN、Mesos 10 | - 日志收集:Flume、Scribe、Logstash、Kibana 11 | - 消息系统:Kafka、StormMQ、ZeroMQ、RabbitMQ 12 | - 查询分析:Hive、Impala、Pig、Presto、Phoenix、SparkSQL、Drill、Flink、Kylin、Druid 13 | - 分布式协调服务:Zookeeper 14 | - 集群管理与监控:Ambari、Ganglia、Nagios、Cloudera Manager 15 | - 数据挖掘、机器学习:Mahout、Spark MLLib 16 | - 数据同步:Sqoop 17 | - 任务调度:Oozie 18 | 19 | 1. [Hadoop](./0Hadoop.md) 20 | 21 | 2. [Hive](./1Hive.md) 22 | 23 | 3. [Sqoop](./2Sqoop.md) 24 | 25 | 4. [Spark](./3Spark.md) 26 | 27 | 5. [HBase](./4HBase.md) -------------------------------------------------------------------------------- /05大数据/2Sqoop.md: -------------------------------------------------------------------------------- 1 | ## Sqoop 2 | -------------------------------------------------------------------------------- /05大数据/hadoop2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/05大数据/hadoop2.png -------------------------------------------------------------------------------- /05大数据/hbase_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/05大数据/hbase_01.png -------------------------------------------------------------------------------- /05大数据/hbase_data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/05大数据/hbase_data.png -------------------------------------------------------------------------------- /05大数据/hbase_memstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaomeng79/learning_notes/2931d5339c1a171ddd58f3180930ec92b224a25e/05大数据/hbase_memstore.png -------------------------------------------------------------------------------- /06工具/0目录.md: -------------------------------------------------------------------------------- 1 | # 目录 2 | 3 | - [常用在线工具列表](./list.md) 4 | - [实用工具](./实用工具.md) 5 | - [运维工具](./运维工具.md) 6 | - [有趣的项目](./%E6%9C%89%E8%B6%A3%E7%9A%84%E9%A1%B9%E7%9B%AE.md) 7 | 8 | ## 常用 9 | - [git](./1git/0目录.md) 10 | - [UML](./2UML/0目录.md) 11 | - [Makefile](./3Makefile/0目录.md) 12 | - [markdown语法](https://blog.csdn.net/yimingsilence/article/details/78840420) **[Markdown其他](8markdown.md)** 13 | - [wget](./5wget.md) 14 | - [ssr](./6ssr.md) 15 | - [bazel](./7bazel.md) 16 | - [markdown生成文档](https://www.mkdocs.org/) 17 | - [docusaurus中文](https://www.docusaurus.cn/) 美观的文档网站 [docusaurus](https://docusaurus.io/) 18 | - [fastpages](https://github.com/fastai/fastpages) 19 | - [gotenberg](https://github.com/gotenberg/gotenberg) 文档转换成pdf 20 | - [chatgpt](./chatgpt.md) 21 | - [ai集合](https://good.xjai.top/) 22 | - [dynv6](https://dynv6.com/) 免费动态dns 23 | 24 | 25 | ## chrom插件 26 | 27 | - 沉浸式翻译: 双语对照网页翻译 & PDF文档翻译 28 | 29 | ## 镜像站 30 | 31 | - [阿里](https://developer.aliyun.com/mirror/?) 32 | - [清华](https://mirrors.tuna.tsinghua.edu.cn/) 33 | 34 | -------------------------------------------------------------------------------- /06工具/1git/0目录.md: -------------------------------------------------------------------------------- 1 | ## 目录 2 | 3 | 1. [命令](./1命令.md) 4 | 5 | 1. [生成changelog](./2生成changelog.md) -------------------------------------------------------------------------------- /06工具/1git/1命令.md: -------------------------------------------------------------------------------- 1 | ## git命令 2 | 3 | ### 删除本地缓存 4 | 5 | ```shell 6 | git rm --cache -r 路径 # -r :递归删除 7 | ``` 8 | 9 | ### clean 10 | 1. `-n` : 演习删除,查看删除什么文件 11 | 2. `-f` : 删除没有track的文件,不会删除.gitignore里面的文件 12 | 3. `-d` : 删除目录 13 | 4. `-x` : 删除全部没track的文件,不管是否在.gitignore 14 | 5. `-e` : 排除需要删除的文件 15 | 16 | 17 | ### 查看当前仓库基本信息 18 | 19 | ```bash 20 | git remote show origin 21 | ``` 22 | 23 | ### 查询当前提交的commit_id 24 | ```bash 25 | git rev-parse HEAD 26 | ``` -------------------------------------------------------------------------------- /06工具/1git/2生成changelog.md: -------------------------------------------------------------------------------- 1 | ## 生成changelog 2 | 3 | - [changelog介绍](http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html) 4 | - [git-commit-msg](http://karma-runner.github.io/5.2/dev/git-commit-msg.html) 5 | - [go生成changelog](github.com/git-chglog/git-chglog) 6 | 7 | ### 如何生成 8 | 9 | 根据git提交commit历史生成changelog 10 | 11 | ### 提交格式 12 | ```doc 13 | (): 14 | 15 | 16 | 17 |