备注:
实际上是一个代理工具,但是又不是简单的进行代理(tcp,可以配置策略,toxics 实现延迟,模拟故障,
对于这个大家可能了解的就是netflix 公司的chaos monkey,实际的使用大家可以参考相关文章,本次只是
对于toxiproxy 的简单安装试用,同时这个工具可以放到大家持续集成工具集中。
1. 安装(为了简单同时安装了server 以及cli)
// 下载地址
wget https://github.com/Shopify/toxiproxy/releases/download/v2.1.2/toxiproxy-server-linux-amd64
wget https://github.com/Shopify/toxiproxy/releases/download/v2.1.2/toxiproxy-cli-linux-amd64
// 配置安装(实际上就是改名称,拷贝文件)
mv toxiproxy-cli-linux-amd64 toxiproxy-cli
mv toxiproxy-server-linux-amd64 toxiproxy-server
chmod +x*
cp * /usr/bin/
2. 试用(为了测试安装了redis )
// redis 环境准备
yum install -y redis
systemctl restart redis
// 启动toxiproxy (后台进程)
nohup toxiproxy-server -host"0.0.0.0" &
// 代理 redis
toxiproxy-cli create myredis -l 0.0.0.0:26379 -u 127.0.0.1:6379
// 配置toxic(让redis 处理延迟1秒)
toxiproxy-cli toxic add myredis -t latency -a latency=1000
// 连接测试
redis-cli -h XXXXXX -p 26379
测试效果
3. 帮助命令(比较简单)
a.server
toxiproxy-server --help
Usage of toxiproxy-server:
-config string
JSON file containing proxies to create on startup
-host string
Host for toxiproxy's API to listen on (default "localhost")
-port string
Port for toxiproxy's API to listen on (default "8474")
-seed int
Seed for randomizing toxic swith(default1511142454198638055)
b.cli
list,l,li,lslistallproxies
usage:'toxiproxy-cli list'
inspect,i,insinspectasingleproxy
usage:'toxiproxy-cli inspect '
create,c,newcreateanewproxy
usage:'toxiproxy-cli create --listen --upstream '
toggle,togtoggleenabledstatusonaproxy
usage:'toxiproxy-cli toggle '
delete,ddeleteaproxy
usage:'toxiproxy-cli delete '
toxic,tadd,removeorupdateatoxic
usage:see'toxiproxy-cli toxic'
4. client sdk (因为提供了rest api sdk 比较好使用,同时官方也提供了好多)
toxiproxy-ruby
toxiproxy-go
toxiproxy-python
toxiproxy.net
toxiproxy-php-client
toxiproxy-node-client
toxiproxy-java
5. 参考文档
https://github.com/Shopify/toxiproxy
网友评论