欢迎您来到腾讯云!积分商城

腾讯云腾讯云论坛

 找回密码
 立即注册
忘了密码?

扫一扫,访问微社区

快捷导航
搜索
查看: 212|回复: 0

[经验分享] CURL在CDN排障中的使用

[复制链接]

38

主题

0

好友

1879

积分

攻城师[LV3]

Rank: 3Rank: 3Rank: 3

云币
5442
威望
1879
发表于 2018-4-22 13:43:03 |显示全部楼层 |未分类
curl的常用参数
-I Show document info only 只展示headers,发起HEAD请求
-o Write output to file instead of stdout 保存到本地
-x 用这个option可以指定http访问所使用的proxy服务器及其端口
-v Make the operation more talkative 可以显示一次http通信的整个过程,包括端口连接和http
-H Custom header to pass to server 添加header
-A/–user-agent [string] 指定UA访问
-e, --referer URL 指定referer
--resolve HOST:PORT:ADDRESS --resolve HOST:PORT:ADDRESS Force resolve of HOST:PORT to ADDRESS
例子
通过61.156.15.39的80端口 访问 http://mat1.gtimg.com/www/images/qq2012/weiboIcon.png 只展示 返回头
  1. curl -I 'http://mat1.gtimg.com/www/images/qq2012/weiboIcon.png' -x 61.156.15.39:80
  2. HTTP/1.1 200 OK
  3. Server: X2_Platform
  4. Connection: keep-alive
  5. Date: Tue, 29 Aug 2017 11:46:50 GMT
  6. Cache-Control: max-age=600
  7. Expires: Tue, 29 Aug 2017 11:56:50 GMT
  8. Last-Modified: Wed, 03 Sep 2014 07:35:47 GMT
  9. Content-Type: image/png
  10. Content-Length: 1320
  11. X-NWS-LOG-UUID: a2c0b82e-26ca-49d6-8b0a-7bf7454a9167 aa3427e8cc9ad3ae0642cf3e63b08ea2
  12. Access-Control-Expose-Headers: X-Client-Ip
  13. Access-Control-Expose-Headers: X-Server-Ip
  14. Access-Control-Expose-Headers: X-Upstream-Ip
  15. X-Client-Ip: 119.29.119.193
  16. X-Server-Ip: 61.156.15.39
  17. X-Upstream-Ip:  
  18. X-Cache-Lookup: Hit From Disktank
复制代码
下载文件保存为 weiboIcon.png
  1. curl -o weiboIcon.png 'http://mat1.gtimg.com/www/images/qq2012/weiboIcon.png'
  2.   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  3.                                  Dload  Upload   Total   Spent    Left  Speed
  4. 100  1320  100  1320    0     0  12005      0 --:--:-- --:--:-- --:--:-- 12110
  5. [root@VM_105_254_centos tmp]# ll
  6. total 4
  7. -rw-r--r-- 1 root root 1320 Aug 29 19:47 weiboIcon.png
复制代码
查看详细请求,文件不保存
https查看证书详情,请求到的IP信息,请求header,返回header
  1. curl  -vo /dev/null 'https://mc.qcloudimg.com/static/img/ae4bfa87aae5714c1c74dd9e134f5a29/image.png'
  2.   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  3.                                  Dload  Upload   Total   Spent    Left  Speed
  4.   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* About to connect() to mc.qcloudimg.com port 443 (#0)
  5. *   Trying 218.11.8.104...
  6. * Connected to mc.qcloudimg.com (218.11.8.104) port 443 (#0)
  7. * Initializing NSS with certpath: sql:/etc/pki/nssdb
  8. *   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  9.   CApath: none
  10. * SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  11. * Server certificate:
  12. *   subject: CN=*.qcloudimg.com,OU=R&D,O=Shenzhen Tencent Computer Systems Company Limited,L=Shenzhen,ST=Guangdong,C=CN
  13. *   start date: Jul 28 00:00:00 2016 GMT
  14. *   expire date: Jul 28 23:59:59 2019 GMT
  15. *   common name: *.qcloudimg.com
  16. *   issuer: CN=Symantec Class 3 Secure Server CA - G4,OU=Symantec Trust Network,O=Symantec Corporation,C=US
  17. > GET /static/img/ae4bfa87aae5714c1c74dd9e134f5a29/image.png HTTP/1.1
  18. > User-Agent: curl/7.29.0
  19. > Host: mc.qcloudimg.com
  20. > Accept: */*
  21. >
  22. < HTTP/1.1 200 OK
  23. < Server: NWSs
  24. < Date: Tue, 29 Aug 2017 11:48:22 GMT
  25. < Content-Type: image/png
  26. < Content-Length: 38325
  27. < Connection: keep-alive
  28. < Cache-Control: max-age=2592000
  29. < Expires: Thu, 28 Sep 2017 11:48:22 GMT
  30. < Last-Modified: Mon, 14 Aug 2017 08:51:52 GMT
  31. < X-NWS-LOG-UUID: c977832c-4772-45b2-8da7-904df04c5235
  32. < X-Cache-Lookup: Hit From Disktank3
  33. < Accept-Ranges: bytes
  34. < X-Daa-Tunnel: hop_count=1
  35. < X-Cache-Lookup: Hit From Inner Cluster
  36. <
  37. { [data not shown]
  38. 100 38325  100 38325    0     0   102k      0 --:--:-- --:--:-- --:--:--  102k
  39. * Connection #0 to host mc.qcloudimg.com left intact
复制代码
指定某节点https请求
如果是http可以直接 -x 14.204.144.142:80
https需要 --resolve mc.qcloudimg.com:443:14.204.144.142 即--resolve host:端口:ip
  1. curl  -vo /dev/null 'https://mc.qcloudimg.com/static/img/ae4bfa87aae5714c1c74dd9e134f5a29/image.png' --resolve mc.qcloudimg.com:443:14.204.144.142
  2. * Added mc.qcloudimg.com:443:14.204.144.142 to DNS cache
  3. * About to connect() to mc.qcloudimg.com port 443 (#0)
  4. *   Trying 14.204.144.142...
  5.   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  6.                                  Dload  Upload   Total   Spent    Left  Speed
  7.   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to mc.qcloudimg.com (14.204.144.142) port 443 (#0)
  8. * Initializing NSS with certpath: sql:/etc/pki/nssdb
  9. *   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  10.   CApath: none
  11. * SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  12. * Server certificate:
  13. *   subject: CN=*.qcloudimg.com,OU=R&D,O=Shenzhen Tencent Computer Systems Company Limited,L=Shenzhen,ST=Guangdong,C=CN
  14. *   start date: Jul 28 00:00:00 2016 GMT
  15. *   expire date: Jul 28 23:59:59 2019 GMT
  16. *   common name: *.qcloudimg.com
  17. *   issuer: CN=Symantec Class 3 Secure Server CA - G4,OU=Symantec Trust Network,O=Symantec Corporation,C=US
  18. > GET /static/img/ae4bfa87aae5714c1c74dd9e134f5a29/image.png HTTP/1.1
  19. > User-Agent: curl/7.29.0
  20. > Host: mc.qcloudimg.com
  21. > Accept: */*
  22. >
  23. < HTTP/1.1 200 OK
  24. < Server: NWSs
  25. < Date: Tue, 29 Aug 2017 12:02:33 GMT
  26. < Content-Type: image/png
  27. < Content-Length: 38325
  28. < Connection: keep-alive
  29. < Cache-Control: max-age=2592000
  30. < Expires: Thu, 28 Sep 2017 12:02:32 GMT
  31. < Last-Modified: Mon, 14 Aug 2017 08:51:52 GMT
  32. < X-NWS-LOG-UUID: d6e89516-13a1-453e-9382-4cfce5b203bd
  33. < X-Cache-Lookup: Hit From Disktank3
  34. < Accept-Ranges: bytes
  35. < X-Daa-Tunnel: hop_count=1
  36. < X-Cache-Lookup: Hit From Inner Cluster
  37. <
  38. { [data not shown]
  39. 100 38325  100 38325    0     0   161k      0 --:--:-- --:--:-- --:--:--  161k
  40. * Connection #0 to host mc.qcloudimg.com left intact
复制代码
带gzip 测试
  1. curl -vo /dev/null -H "Accept-Encoding: gzip,deflate" 'https://img3.doubanio.com/f/shire/25e3b87e05e5de459e1473fad35d25cafd392ad6/css/core/_init_.css'
  2.   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  3.                                  Dload  Upload   Total   Spent    Left  Speed
  4.   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* About to connect() to img3.doubanio.com port 443 (#0)
  5. *   Trying 124.227.27.226...
  6. * Connected to img3.doubanio.com (124.227.27.226) port 443 (#0)
  7. * Initializing NSS with certpath: sql:/etc/pki/nssdb
  8. *   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  9.   CApath: none
  10. * SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  11. * Server certificate:
  12. *   subject: CN=*.doubanio.com,OU=Technology Department,O=Beijing Douwang Technology Co. Ltd.,L=Beijing,ST=Beijing,C=CN
  13. *   start date: May 23 00:00:00 2017 GMT
  14. *   expire date: Jul 05 23:59:59 2019 GMT
  15. *   common name: *.doubanio.com
  16. *   issuer: CN=GeoTrust SSL CA - G3,O=GeoTrust Inc.,C=US
  17. > GET /f/shire/25e3b87e05e5de459e1473fad35d25cafd392ad6/css/core/_init_.css HTTP/1.1
  18. > User-Agent: curl/7.29.0
  19. > Host: img3.doubanio.com
  20. > Accept: */*
  21. > Accept-Encoding: gzip,deflate
  22. >
  23. < HTTP/1.1 200 OK
  24. < Server: Tengine
  25. < Content-Type: text/css
  26. < Transfer-Encoding: chunked
  27. < Connection: keep-alive
  28. < Vary: Accept-Encoding
  29. < Date: Tue, 23 May 2017 02:48:22 GMT
  30. < Expires: Wed, 23 May 2018 02:48:22 GMT
  31. < Cache-Control: max-age=31536000
  32. < Last-Modified: Wed, 21 Jan 2004 19:51:30 GMT
  33. < Vary: Accept-Encoding
  34. < Via: cache6.l2st4-3[0,200-0,H], cache20.l2st4-3[2,0], cache4.cn775[0,200-0,H], cache5.cn775[0,0]
  35. < Age: 8502171
  36. < X-Cache: HIT TCP_MEM_HIT dirn:4:6027639
  37. < X-Swift-SaveTime: Mon, 14 Aug 2017 11:45:29 GMT
  38. < X-Swift-CacheTime: 15552000
  39. < Timing-Allow-Origin: *
  40. < EagleId: 7ce31b9915040098733093939e
  41. < Content-Encoding: gzip
  42. <
  43. { [data not shown]
  44. 100  7444    0  7444    0     0  46758      0 --:--:-- --:--:-- --:--:-- 46817
  45. * Connection #0 to host img3.doubanio.com left intact
复制代码
使用refere
  1. curl -e 'http://www.bigmen.cn' 'http://mat1.gtimg.com/www/images/qq2012/weiboIcon.png' -vo /dev/null
  2.   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  3.                                  Dload  Upload   Total   Spent    Left  Speed
  4.   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* About to connect() to mat1.gtimg.com port 80 (#0)
  5. *   Trying 27.221.81.38...
  6. * Connected to mat1.gtimg.com (27.221.81.38) port 80 (#0)
  7. > GET /www/images/qq2012/weiboIcon.png HTTP/1.1
  8. > User-Agent: curl/7.29.0
  9. > Host: mat1.gtimg.com
  10. > Accept: */*
  11. > Referer: http://www.bigmen.cn
  12. >
  13. < HTTP/1.1 200 OK
  14. < Server: X2_Platform
  15. < Connection: keep-alive
  16. < Date: Tue, 29 Aug 2017 12:35:56 GMT
  17. < Cache-Control: max-age=600
  18. < Expires: Tue, 29 Aug 2017 12:45:56 GMT
  19. < Last-Modified: Wed, 03 Sep 2014 07:35:47 GMT
  20. < Content-Type: image/png
  21. < Content-Length: 1320
  22. < X-NWS-LOG-UUID: b9831f5f-6144-43d9-b00d-bee2bbf01d53 6a93446aaa8e62f1e3b39997d017a315
  23. < Access-Control-Expose-Headers: X-Client-Ip
  24. < Access-Control-Expose-Headers: X-Server-Ip
  25. < Access-Control-Expose-Headers: X-Upstream-Ip
  26. < X-Client-Ip: 119.29.119.193
  27. < X-Server-Ip: 27.221.81.38
  28. < X-Upstream-Ip:  
  29. < X-Cache-Lookup: Hit From Disktank
  30. <
  31. { [data not shown]
  32. 100  1320  100  1320    0     0  14928      0 --:--:-- --:--:-- --:--:-- 15000
  33. * Connection #0 to host mat1.gtimg.com left intact
复制代码
带上指定 host请求
  1. curl -H "Host:mat1.gtimg.com" 'http://61.156.15.28/www/images/qq2012/weiboIcon.png' -vo /dev/null
  2. * About to connect() to 61.156.15.28 port 80 (#0)
  3. *   Trying 61.156.15.28...
  4.   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  5.                                  Dload  Upload   Total   Spent    Left  Speed
  6.   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 61.156.15.28 (61.156.15.28) port 80 (#0)
  7. > GET /www/images/qq2012/weiboIcon.png HTTP/1.1
  8. > User-Agent: curl/7.29.0
  9. > Accept: */*
  10. > Host:mat1.gtimg.com
  11. >
  12. < HTTP/1.1 200 OK
  13. < Server: X2_Platform
  14. < Connection: keep-alive
  15. < Date: Tue, 29 Aug 2017 12:41:52 GMT
  16. < Cache-Control: max-age=600
  17. < Expires: Tue, 29 Aug 2017 12:51:52 GMT
  18. < Last-Modified: Wed, 03 Sep 2014 07:35:47 GMT
  19. < Content-Type: image/png
  20. < Content-Length: 1320
  21. < X-NWS-LOG-UUID: 4b9db60e-8b43-4812-a5b9-41032ef7d443 aa3427e8cc9ad3ae6f9a23387443675b
  22. < Access-Control-Expose-Headers: X-Client-Ip
  23. < Access-Control-Expose-Headers: X-Server-Ip
  24. < Access-Control-Expose-Headers: X-Upstream-Ip
  25. < X-Client-Ip: 119.29.119.193
  26. < X-Server-Ip: 61.156.15.28
  27. < X-Upstream-Ip:  
  28. < X-Cache-Lookup: Hit From Disktank
  29. <
  30. { [data not shown]
  31. 100  1320  100  1320    0     0  15634      0 --:--:-- --:--:-- --:--:-- 15714
  32. * Connection #0 to host 61.156.15.28 left intact
复制代码
带分片range测试
  1. curl -vo /dev/null 'http://mat1.gtimg.com/www/images/qq2012/weiboIcon.png' -H 'Range:bytes=0-0'
  2.   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  3.                                  Dload  Upload   Total   Spent    Left  Speed
  4.   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* About to connect() to mat1.gtimg.com port 80 (#0)
  5. *   Trying 123.6.0.15...
  6. * Connected to mat1.gtimg.com (123.6.0.15) port 80 (#0)
  7. > GET /www/images/qq2012/weiboIcon.png HTTP/1.1
  8. > User-Agent: curl/7.29.0
  9. > Host: mat1.gtimg.com
  10. > Accept: */*
  11. > Range:bytes=0-0
  12. >
  13. < HTTP/1.1 206 Partial Content
  14. < Server: X2_Platform
  15. < Connection: keep-alive
  16. < Date: Thu, 09 Nov 2017 07:12:29 GMT
  17. < Cache-Control: max-age=600
  18. < Expires: Thu, 09 Nov 2017 07:22:29 GMT
  19. < Last-Modified: Wed, 03 Sep 2014 07:35:47 GMT
  20. < Content-Range: bytes 0-0/1320
  21. < Content-Type: image/png
  22. < Content-Length: 1
  23. < X-NWS-LOG-UUID: c131b44c-3a82-43e8-9c9e-fc659b8081db 8a9f959e372c114c417ade199478a184
  24. < Access-Control-Expose-Headers: X-Client-Ip
  25. < Access-Control-Expose-Headers: X-Server-Ip
  26. < Access-Control-Expose-Headers: X-Upstream-Ip
  27. < X-Client-Ip: 119.29.119.193
  28. < X-Server-Ip: 123.6.0.15
  29. < X-Upstream-Ip:  
  30. < X-Cache-Lookup: Hit From Upstream
  31. < X-Cache-Lookup: Hit From Disktank
  32. <
  33. { [data not shown]
  34. 100     1  100     1    0     0      6      0 --:--:-- --:--:-- --:--:--     6
  35. * Connection #0 to host mat1.gtimg.com left intact
复制代码
您需要登录后才可以回帖 登录 | 立即注册
您需要登录后才可以发帖 QQ登录

联系我们|腾讯云平台|积分商城|腾讯云官方论坛    

GMT+8, 2018-5-20 21:37 , Processed in 1.180072 second(s), 29 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部