tin*_*err 7 hosts hosts-file apachebench
我正在使用ApacheBench进行一些负载测试.我希望ab使用Mac上/ etc/hosts中指定的IP地址来解析主机名.我怎么强迫呢?curl有一个--resolve选项来完成这个,就像这里指定的那样.我正在为ab寻找类似的东西.
反过来想想:你可以告诉Curl点击一个IP地址,并指定Host标题来触发所需的域.
curl example.com
curl --header "Host: example.com" 93.184.216.34
Run Code Online (Sandbox Code Playgroud)
同样的方法也适用于ab使用-H标志
ab -n 10 -c 10 http://example.com/
ab -n 10 -c 10 -H "Host: example.com" http://93.184.216.34/
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
编辑:
捎带@Magistar的答案,你想确保你使用正确的协议(httpvs https)并且正在击中正确的FQD.也就是说,如果您的网站响应www.example.com但没有example.com(没有www)确保使用有效的网站.
另一件需要注意的事情是确保您没有加载测试重定向.例如,运行ab对yahoo.com(我不建议这样做)不会是一个很好的测试,作为yahoo.com一个立即重定向响应www.yahoo.com,你可以看到,如果你curl是在详细模式:
# curl yahoo.com
redirect
# curl yahoo.com -v
* About to connect() to yahoo.com port 80 (#0)
* Trying 98.139.180.180...
* Connected to yahoo.com (98.139.180.180) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: yahoo.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Wed, 07 Mar 2018 13:46:53 GMT
< Connection: keep-alive
< Via: http/1.1 media-router-fp29.prod.media.bf1.yahoo.com (ApacheTrafficServer [c s f ])
< Server: ATS
< Cache-Control: no-store, no-cache
< Content-Type: text/html
< Content-Language: en
< X-Frame-Options: SAMEORIGIN
< Strict-Transport-Security: max-age=2592000
< Location: https://www.yahoo.com/
< Content-Length: 8
<
* Connection #0 to host yahoo.com left intact
redirect
Run Code Online (Sandbox Code Playgroud)
或者更具体地说,因为这是关于将主机欺骗到目标IP地址:
# curl --header "Host: yahoo.com" 98.139.180.180 -v
* About to connect() to 98.139.180.180 port 80 (#0)
* Trying 98.139.180.180...
* Connected to 98.139.180.180 (98.139.180.180) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Accept: */*
> Host: yahoo.com
>
< HTTP/1.1 301 Moved Permanently
< Date: Wed, 07 Mar 2018 13:51:26 GMT
< Connection: keep-alive
< Via: http/1.1 media-router-fp82.prod.media.bf1.yahoo.com (ApacheTrafficServer [c s f ])
< Server: ATS
< Cache-Control: no-store, no-cache
< Content-Type: text/html
< Content-Language: en
< X-Frame-Options: SAMEORIGIN
< Strict-Transport-Security: max-age=2592000
< Location: https://www.yahoo.com/
< Content-Length: 8
<
* Connection #0 to host 98.139.180.180 left intact
redirect
Run Code Online (Sandbox Code Playgroud)
所以一定curl要先确定网址,以确保它返回您期望的数据,然后继续ab.
| 归档时间: |
|
| 查看次数: |
5901 次 |
| 最近记录: |