curl/wget 在故障处置上的应用
curl
/wget
是一个非常常用的命令行工具,用于下载文件。在网络故障时,我们可以使用 curl
/wget
来进行故障侦测。
处置案例
假设有如此一个部署:
graph LR
browser --> nginx
client --> nginx
nginx --> forward --> app
现在发现 browser
能访问 app
,但是 client
无法访问。需要进行分析定位故障点。
这时,我们可以通过 curl
/wget
来进行故障定位。
浏览器/客户端 | nginx | forward | app |
---|---|---|---|
ip1 | ip2 | ip3 | ip4 |
模拟浏览器/客户端访问
app
,发现GET
可以正常访问,POST
无法访问。curl -k -X GET http://ip2/forward/login.action
curl -k -X POST -d "a=b&c=d" http://ip2/forward/login.action模拟
nginx
访问forward
,仍然发现GET
可以正常访问,POST
无法访问。curl -k -X GET http://ip3/fwd/login.action
curl -k -X POST -d "a=b&c=d" http://ip3/fwd/login.action模拟
forward
访问app
,仍然发现GET
可以正常访问,POST
无法访问。curl -k -X GET http://ip4/app/login.action
curl -k -X POST -d "a=b&c=d" http://ip4/app/login.action
至此,可定位问题故障点在 app
服务器上。
wget
同理,命令可通过man wget
查看。
提示
假设在第二步成功,则说明问题在 nginx
服务器上。
假设在第三步成功,则说明问题在 forward
服务器上。
使用限制
- 需安装
curl
/wget
。一般服务器都默认安装。 - 需可直接访问目标服务器。