ChaosBlade 是阿里巴巴 2019 年开源的混沌工程项目,包含混沌工程实验工具 chaosblade 和混沌工程平台 chaosblade-box,旨在通过混沌工程帮助企业解决云原生过程中高可用问题。实验工具 chaosblade 支持 3 大系统平台,4 种编程语言应用,共涉及 200 多的实验场景,3000 多个实验参数,可以精细化的控制实验范围。混沌工程平台 chaosblade-box 支持实验工具托管,除已托管 chaosblade 外,还支持 Litmuschaos 实验工具。已登记使用企业 40 多家,其中已在工商银行、中国移动、小米、京东等企业中落地使用。

https://chaosblade.io/zh/docs/

做混沌实验、异常测试的,包含基础资源(CPU、内存、网络、磁盘、进程、内核、文件等)、多语言应用服务(Java、C++、NodeJS、Golang 等)、Kubernetes 平台(覆盖 Container、Pod、Node 资源场景,包含上述实验场景)。

安装

wget https://github.com/chaosblade-io/chaosblade/releases/download/v1.5.0/chaosblade-1.5.0-linux-amd64.tar.gz
tar -zxf chaosblade-1.5.0-linux-amd64.tar.gz
mv chaosblade-1.5.0 chaosblade# 添加环境变量或添加软链,可以直接调用chaosblade
# 个人觉得加软链比较好看,若/usr/local/bin被加到环境变量的情况下,blade可以用
ln -s /data/zy/tools/chaosblade/blade /usr/bin/blade# plan B, 如果只是在当前执行的话
export PATH=$PATH:/data/zy/tools/chaosblade

善用help

(base) darcyzhang@debian:~/tools$ blade help
An easy to use and powerful chaos engineering experiment toolkitUsage:blade [command]Available Commands:check       Check the environment for chaosbladecreate      Create a chaos engineering experiment,创建混沌实验destroy     Destroy a chaos experiment,销毁混沌实验help        Help about any commandprepare     Prepare to experimentquery       Query the parameter values required for chaos experimentsrevoke      Undo chaos engineering experiment preparationserver      Server mode starts, exposes web servicesstatus      Query preparation stage or experiment status,查看实验状态version     Print version infoFlags:-d, --debug   Set client to DEBUG mode-h, --help    help for bladeUse "blade [command] --help" for more information about a command.

先来一个Demo

sudo blade create mem load --mem-percent 50
sudo blade status --type create --status success
# 创建占用50%内存的混沌实验 blade create help
(base) darcyzhang@debian:~$ sudo blade create mem load --mem-percent 50
{"code":200,"success":true,"result":"89b439c7a0b03625"}# 查看实验状态 blade status help
(base) darcyzhang@debian:~$ sudo blade status --type create --status success
{"code": 200,"success": true,"result": [{"Uid": "acc4a866b5d1b4a1","Command": "mem","SubCommand": "load","Flag": " --mem-percent=50","Status": "Success","Error": "","CreateTime": "2022-05-15T16:03:26.234192228+08:00","UpdateTime": "2022-05-15T16:03:26.677657158+08:00"}]
}# 查看内存状态,这个内存占用需要一段时间才能创建完成
(base) darcyzhang@debian:~$ free -htotal        used        free      shared  buff/cache   available
Mem:           49Gi       424Mi        24Gi        23Gi        24Gi        24Gi
Swap:         979Mi          0B       979Mi# 删除混沌实验
(base) darcyzhang@debian:~$ sudo blade destroy acc4a866b5d1b4a1
{"code":200,"success":true,"result":{"target":"mem","action":"load","flags":{"mem-percent":"50"}}}

创建常见实验

(base) darcyzhang@debian:~$ blade create --help
Create a chaos engineering experimentUsage:blade create [command]Aliases:create, cExamples:
blade create cpu load --cpu-percent 60Available Commands:cplus       C++ chaos experimentscpu         Cpu experiment,cpu实验cri         CRI experimentdisk        Disk experiment,磁盘docker      Docker experiment,docker容器实验druid       Experiment with the Druiddubbo       Experiment with the Dubboes          ElasticSearch experiment!file        File experimentgateway     gateway experiment!hbase       hbase experiment!http        http experimentjedis       jedis experimentjvm         Experiment with the JVMk8s         Kubernetes experimentkafka       kafka experimentlettuce     redis client lettuce experimentlog         log experimentmem         Mem experiment,内存mongodb     MongoDB experimentmysql       mysql experimentnetwork     Network experiment,网络process     Process experimentpsql        Postgrelsql experimentrabbitmq    rabbitmq experimentredisson    redisson experimentrocketmq    Rocketmq experiment,can make message send or pull delay and exceptionscript      Script chaos experimentservlet     java servlet experimentstrace      strace experimentsystemd     Systemd experimenttars        tars experimentFlags:-a, --async             whether to create asynchronously, default is false-e, --endpoint string   the create result reporting address. It takes effect only when the async value is true and the value is not empty-h, --help              help for create-n, --nohup             used to internal async create, no need to config--uid string        Set Uid for the experiment, adapt to docker and criGlobal Flags:-d, --debug   Set client to DEBUG modeUse "blade create [command] --help" for more information about a command.

timeout是创建混沌实验的一个常用参数,代表实验的持续时间,或者理解为实验多久后过期,创建实验最好带上这个参数,以防忘记销毁实验影响机器的正常使用。

CPU

(base) darcyzhang@debian:~$ blade create cpu --help
Cpu experiment, for example full loadUsage:blade create cpu [flags]blade create cpu [command]Available Commands:fullload    cpu load        # cpu满载Flags:-h, --help   help for cpuGlobal Flags:-a, --async             whether to create asynchronously, default is false-d, --debug             Set client to DEBUG mode-e, --endpoint string   the create result reporting address. It takes effect only when the async value is true and the value is not empty-n, --nohup             used to internal async create, no need to config--uid string        Set Uid for the experiment, adapt to docker and criUse "blade create cpu [command] --help" for more information about a command.

创建CPU满载实验

blade create cpu load

内存

(base) darcyzhang@debian:~$ blade create mem --help
Mem experiment, for example loadUsage:blade create mem [flags]blade create mem [command]Available Commands:load        mem loadFlags:-h, --help   help for memGlobal Flags:-a, --async             whether to create asynchronously, default is false-d, --debug             Set client to DEBUG mode-e, --endpoint string   the create result reporting address. It takes effect only when the async value is true and the value is not empty-n, --nohup             used to internal async create, no need to config--uid string        Set Uid for the experiment, adapt to docker and criUse "blade create mem [command] --help" for more information about a command.
blade create mem load --help--mem-percent string       内存占用百分比(0-100), 必须正整数--mode string              burn memory mode, cache or ram.--rate string              burn memory rate, unit is M/S, only support for ram mode.--reserve string           保留内存, unit is MB. 如果有 mem-percent, 优先 mem-percent.--timeout string           set timeout for experiment,实验超时时长

网络

blade create network --helpAvailable Commands:corrupt     Corrupt experimentdelay       Delay experiment, 网络延时dns         Dns experimentdrop        Drop experimentduplicate   Duplicate experimentloss        Loss network package,网络丢包occupy      Occupy the specify port,端口占用reorder     Reorder experiment

这里就不搞具体的例子了,一步一步的help下去,chaosblade的帮助文档还是写的很详细的。还有示例可以参考。

(base) darcyzhang@debian:~$ blade create network delay --help
Delay experimentUsage:blade create network delayExamples:   # 示例# Access to native 8080 and 8081 ports is delayed by 3 seconds, and the delay time fluctuates by 1 second
blade create network delay --time 3000 --offset 1000 --interface eth0 --local-port 8080,8081# Local access to external 14.215.177.39 machine (ping www.baidu.com obtained IP) port 80 delay of 3 seconds
blade create network delay --time 3000 --interface eth0 --remote-port 80 --destination-ip 14.215.177.39# Do a 5 second delay for the entire network card eth0, excluding ports 22 and 8000 to 8080
blade create network delay --time 5000 --interface eth0 --exclude-port 22,8000-8080Flags:--destination-ip string    目标IP,destination ip. Support for using mask to specify the ip range such as 92.168.1.0/24 or comma separated multiple ips, for example 10.0.0.1,11.0.0.1.--exclude-ip string        排除掉的ip,Exclude ips. Support for using mask to specify the ip range such as 92.168.1.0/24 or comma separated multiple ips, for example 10.0.0.1,11.0.0.1--exclude-port string      排除掉的端口,Exclude local ports. Support for configuring multiple ports, separated by commas or connector representing ranges, for example: 22,8000. This flag is invalid when --local-port or --remote-port is specified--force                    Forcibly overwrites the original rules-h, --help                     help for delay--ignore-peer-port         ignore excluding all ports communicating with this port, generally used when the ss command does not exist--install-path string      install path default /opt/chaosblade,use this flag when the channel is ssh--interface string         网口,Network interface, for example, eth0 (required)--local-port string        本地端口,Ports for local service. Support for configuring multiple ports, separated by commas or connector representing ranges, for example: 80,8000-8080--offset string            延时时间浮动时长,Delay offset time, ms--override-blade-release   Override blade release,use this flag when the channel is ssh--remote-port string       远程端口,Ports for remote service. Support for configuring multiple ports, separated by commas or connector representing ranges, for example: 80,8000-8080--time string              延时时间,Delay time, ms (required)--timeout string           实验超时时间,set timeout for experiment

磁盘

blade create disk --helpAvailable Commands:burn        Increase disk read and write io load, 增加磁盘读写iofill        Fill the specified directory path,填充满指定目录

通过http远程创建实验

chaosblade提供通过http服务远程调用的方式,通过blade命令即可启动chaosblade的http服务。
在远程机器上启动chaosblade的驻守服务。

blade server start --port 8080

然后就可以本地机器远程调用了

# 创建
$ curl "http://192.168.1.106:8080/chaosblade?cmd=create%20cpu%20load%20--cpu-percent%2020"
{"code":200,"success":true,"result":"65161502e93cbe7e"}%
# 销毁
$ curl "http://192.168.1.106:8080/chaosblade?cmd=destroy%2065161502e93cbe7e"
{"code":200,"success":true,"result":{"action":"fullload","flags":{"cpu-percent":"20"},"target":"cpu"}}%

这里面的%20是空格,直接用空格不好使。

对容器的混沌实验

对容器的混沌实验也不是太复杂,只要加上docker关键字,指定容器id容器名称即可

blade create docker network delay --interface eth0 --time 300 --container-name chttper

写的个小项目test一下

把项目通过docker部署起来

git clone https://gitee.com/bbjg001/httper
cd httper# 构建项目镜像
docker build -t ihttper .
# 启动容器
docker run -tid --name chttper -p 8088:8088 ihttper 8088    # 前面的-p是宿主机和容器的端口映射,最后的端口是设置服务在容器内用的端口,前后要保持一致# 测的接口是这样的
curl http://192.168.1.106:8088/objs

然后加上网络延时的混沌实验

blade create docker network delay --interface eth0 --time 300 --container-name chttper

用locust做一点子压力测试,网络延时前后测试结果如下。locust压力测试相关可以参见鄙人写的 Locust压力测试。

参考

混沌工程-阿里巴巴-chaosblade-安装与使用

chaosblade中文文档

chaosblade混沌测试相关推荐

  1. 混沌测试工具chaosblade介绍及常用命令汇总

    目录 一.什么是混沌测试 二.环境搭建 三.测试指导文档 四.常用命令介绍 五.注意事项 一.什么是混沌测试 类似于"故障演练",通过构造各类异常,验证系统在碰到这些异常时是否有做 ...

  2. OpenShift 4 之Istio-Tutorial (7) 利用VirtualService的故障注入实现混沌测试Chaos Testing

    <OpenShift 4.x HOL教程汇总> 说明:本文已经在OpenShift 4.8环境中验证 在VirtualService中可以对HTTP请求注入模拟的故障,从而实现混沌测试.这 ...

  3. TiDB中的混沌测试实践

    什么是混沌 \\ 在分布式计算领域,我们无法预测集群将会发生什么,一切皆有可能.在里约热内卢飘舞的蝴蝶可能会改变芝加哥的气候,甚至摧毁位于开罗的数据中心.网络时间协议(NTP)可能出现不同步,CPU可 ...

  4. 技术分享 | 在GreatDB分布式部署模式中使用Chaos Mesh做混沌测试

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 1. 需求背景与万里安全数据库软件GreatDB分布式部署模式介绍 1.1 需求背景 混沌测试是检测分布式系统不确定性.建 ...

  5. 干货 | 阿里巴巴混沌测试工具ChaosBlade两万字解读

    点击上方"方志朋",选择"设为星标" 做积极的人,而不是积极废人 一.前言 ChaosBlade 是一款遵循混沌工程实验原理,建立在阿里巴巴近十年故障测试和演练 ...

  6. ChaosBlade混沌工程工具

    目录 ChaosBlade介绍 使用步骤 blade命令介绍 适用的场景 基础资源类故障 网络类故障 进程类故障 java语言类故障 shell脚本类故障 HTTP类故障 RPC类故障 servlet ...

  7. ChaosBlade 在工商银行混沌工程体系中的应用实践

    作者 | 吴冕冠 来源|阿里巴巴云原生公众号 互联网金融时代下,金融产品和服务模式不断创新,交易量大幅攀升.面对互联网金融的全新发展态势,传统的单体 IT 架构暴露出很多不适应的地方,为此业界广泛应用 ...

  8. 利用混沌工程测试以太坊客户端

    本文提供了混沌工程原理的实用知识,讨论了它在软件开发中的应用,并探讨了如何将其应用扩展到区块链开发中. 本文的教程部分演示了如何使用 ChaosETH 框架来利用混沌工程来测试以太坊客户端. 这种策略 ...

  9. ChaosBlade x SkyWalking 微服务高可用实践

    来源|阿里巴巴云原生公众号 前言 在分布式系统架构下,服务组件繁多且服务间的依赖错综复杂,很难评估单个故障对整个系统的影响,而且请求链路长,如果监控告警.日志记录等基础服务不完善会造成故障响应.故障定 ...

  10. 分布式系统保障—混沌工程—初识

    原文作者: 朱小厮的博客 原文地址:混沌工程(Chaos Engineering)初识 编辑推荐: 本文主要介绍什么是混沌工程.混沌工程的五大原则.混沌工程成熟度模型(CMM)以及混沌工程的目标--韧 ...

最新文章

  1. android 画板菜单,Android画板实现
  2. Java遍历Map对象的四种方法
  3. D - Connect the Cities (HDU - 3371)
  4. eclipse创建神经网络_使用Eclipse Deeplearning4j构建简单的神经网络
  5. 蓝桥杯单片机数码管动态显示_单片机静态动态数码管
  6. bin/arm-linux-androideabi-nm: libtinfo.so.5: cannot open shared object file: No such file or directo
  7. 深度强化学习——A3C
  8. [SAP ABAP开发技术总结]增强Enhancement
  9. 三分钟集成连连支付方法(以认证支付为例)
  10. Local declaration of '' hides instance variable
  11. 记录日志的工具类LogWriter
  12. 根据身份证号码(15位或者18位)自动获取出生日期及性别
  13. 2022焊工(初级)操作证考试题库及模拟考试
  14. 转速闭环控制直流调速系统的仿真 matlab
  15. 关于二轮差速小车轮速计算和里程计计算
  16. 微信小程序 物联网解决方案
  17. 灌篮高手DVD高清全集典藏版下载 (目前最好版本,收藏极品)
  18. 前端使用XLSX插件实现导出功能,包含隐藏英文表头字段
  19. 前端知识分享——SheetJS 用法体验
  20. Coupled Multi-Layer Attentions for Co-Extraction of Aspect and Opinion Terms

热门文章

  1. oracle导出dmp文件合集
  2. 软件测试人员,究竟怎么霸气过七夕?!大神攻略请笑纳!
  3. 你及格了吗?史上最难云原生冷知识大挑战真题解析
  4. 数字宫殿110位数字对照物
  5. 2015年换工作感想
  6. 将网页中的文字和图片转换成WORD文档
  7. 使用kubeadm在CentOS上搭建Kubernetes1.14.3集群
  8. 百度相关搜索是怎么出现的如何利用
  9. 什么是promise?
  10. iPhone显示返回的是html界面,iPhone X怎么回到主界面?苹果X返回主页的两种方法...