Linux命令Curl支持HTTP 2.0

简介: Curl命令不一定支持HTTP 2.0,但某些服务必须需要HTTP2.0,如Apple的推送服务若使用HTTP/1.x协议进行请求,则会返回“Unexpected HTTP/1.x request”的错误。因此就有了让Curl命令支持HTTP/2的实践,其实质就是重新编译Curl命令。 # 验证curl对HTTP 2.0的支持 为了验证默认情况下curl使用的协议,执行命令: ```

Curl命令不一定支持HTTP 2.0,但某些服务必须需要HTTP2.0,如Apple的推送服务若使用HTTP/1.x协议进行请求,则会返回“Unexpected HTTP/1.x request”的错误。因此就有了让Curl命令支持HTTP/2的实践,其实质就是重新编译Curl命令。

验证curl对HTTP 2.0的支持

为了验证默认情况下curl使用的协议,执行命令:

[root@host root]# curl -I https://nghttp2.org/
HTTP/1.1 200 OK
Date: Tue, 27 Oct 2020 07:53:18 GMT
Content-Type: text/html
Last-Modified: Tue, 02 Jun 2020 12:23:35 GMT
Etag: "5ed644c7-19d8"
Accept-Ranges: bytes
Content-Length: 6616
X-Backend-Header-Rtt: 0.00096
Strict-Transport-Security: max-age=31536000
Server: nghttpx
Via: 2 nghttpx
alt-svc: h3-29=":443"; ma=3600
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff

HTTP/1.1 200 OK可知当前计算机的curl默认使用HTTP 1.1。

HTTP 2.0的启用需要使用--http2开关,看当前curl命令是否支持这个参数,执行命令:

[root@host root]# curl --http2 -I https://nghttp2.org/
curl: option --http2: is unknown
curl: try 'curl --help' or 'curl --manual' for more information

从上面的结果可见,当前计算机的curl不支持HTTP 2.0。

看curl命令支持的特性,从Features里可以看到curl命令是否真的不支持http2:

[root@host root]# curl --version
curl 7.29.0 (x86_64-koji-linux-gnu) libcurl/7.29.0 NSS/3.28.4 zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets

因为Features里没有HTTP2,因此无法支持HTTP2.0。

增加对HTTP2.0的支持

增加对HTTP2.0的支持说白了,就是重新编译一个curl,其中一个重要的依赖是nghttp2。下面就来实际操作一下。注意用root用户的身份安装系统软件。

  1. 用yum把当前已安装包升级到最新,并安装依赖的包。
[root@host root]# yum -y update
[root@host root]# yum -y install make binutils autoconf automake libtool \
    python-setuptools python-devel python3-devel git openssl openssl-devel curl gcc gcc-c++ \
    pkgconfig zlib-devel zlib libxml2-devel libev-devel libevent-devel libevdev libevdev-devel \
    jansson-devel jemalloc-devel libcurl libicu libmetalink libpsl libssh2 c-ares-devel \
    libnghttp2 systemd
  1. 安装nghttp2。因为每个命令输出内容较长,这里把命令执行输出部分略去。
[root@host root]# git clone https://github.com/tatsuhiro-t/nghttp2.git
[root@host root]# cd nghttp2/
[root@host nghttp2]# autoreconf -i
[root@host nghttp2]# automake
[root@host nghttp2]# autoconf
[root@host nghttp2]# ./configure
[root@host nghttp2]# make
[root@host nghttp2]# make install
[root@host nghttp2]# ldconfig
[root@host nghttp2]# cd ..

如果上面能正确编译和安装,则可直接到下一步。如果make过程中出现错误:#error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. 说明系统的编译器版本过旧,需要进行更多的操作。

[root@host nghttp2]# yum install centos-release-scl
[root@host nghttp2]# yum-config-manager --enable rhel-server-rhscl-7-rpms
[root@host nghttp2]# yum install devtoolset-7
[root@host nghttp2]# scl enable devtoolset-7 bash

上面4个命令执行后,再执行gcc --version就可以看到gcc已经升级到7.0以上。升级完后,继续编译和安装nghttp2。

  1. 重新编译curl命令。
[root@host root]# wget https://curl.haxx.se/download/curl-7.73.0.tar.gz
[root@host root]# tar -zxvf curl-7.73.0.tar.gz
[root@host root]# cd curl-7.73.0/
[root@host curl-7.73.0]# ./configure --with-nghttp2=/usr/local --with-ssl --enable-tls-srp
[root@host curl-7.73.0]# make && make install
[root@host curl-7.73.0]# ldconfig
[root@host curl-7.73.0]# cd ..

需要注意,执行configure后,需要确认输出中含有HTTP2: enabled (nghttp2)字样。

  1. 确认curl命令已经支持HTTP2.0
[root@host root]# curl --version
curl 7.73.0 (x86_64-pc-linux-gnu) libcurl/7.73.0 OpenSSL/1.0.2k-fips zlib/1.2.7 nghttp2/1.42.0-DEV
Release-Date: 2020-10-14
Protocols: dict file ftp ftps gopher http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL UnixSockets

这里显示了HTTP2字样,说明curl已经支持了HTTP 2.0。
上述操作在CentOS Linux release 7.8系统中验证通过。

目录
相关文章
|
2月前
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
412 1
二、Linux文本处理与文件操作核心命令
|
2月前
|
Linux
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
289 137
|
2月前
|
安全 Ubuntu Unix
一、初识 Linux 与基本命令
玩转Linux命令行,就像探索一座新城市。首先要熟悉它的“地图”,也就是/根目录下/etc(放配置)、/home(住家)这些核心区域。然后掌握几个“生存口令”:用ls看周围,cd去别处,mkdir建新房,cp/mv搬东西,再用cat或tail看文件内容。最后,别忘了随时按Tab键,它能帮你自动补全命令和路径,是提高效率的第一神器。
661 57
|
1月前
|
存储 安全 Linux
Linux卡在emergency mode怎么办?xfs_repair 命令轻松解决
Linux虚拟机遇紧急模式?别慌!多因磁盘挂载失败。本文教你通过日志定位问题,用`xfs_repair`等工具修复文件系统,三步快速恢复。掌握查日志、修磁盘、验重启,轻松应对紧急模式,保障系统稳定运行。
372 2
|
2月前
|
缓存 监控 Linux
Linux内存问题排查命令详解
Linux服务器卡顿?可能是内存问题。掌握free、vmstat、sar三大命令,快速排查内存使用情况。free查看实时内存,vmstat诊断系统整体性能瓶颈,sar实现长期监控,三者结合,高效定位并解决内存问题。
257 0
Linux内存问题排查命令详解
|
2月前
|
Unix Linux 程序员
Linux文本搜索工具grep命令使用指南
以上就是对Linux环境下强大工具 `grep` 的基础到进阶功能介绍。它不仅能够执行简单文字查询任务还能够处理复杂文字处理任务,并且支持强大而灵活地正则表达规范来增加查询精度与效率。无论您是程序员、数据分析师还是系统管理员,在日常工作中熟练运用该命令都将极大提升您处理和分析数据效率。
260 16
|
3月前
|
Linux 网络安全 开发工具
技术栈:这50条最常用的 Linux 命令你一定要会!
建议多在终端中实践,遇到不懂的命令就用 man 或 --help 了解详情!
510 0
|
3月前
|
安全 Linux Shell
Linux系统中sudo命令的高效运用技巧。
用户可以通过sudo -l来列出自己目前可执行的命令列表,这有助于用户了解自己的权限范围。
176 0
|
3月前
|
监控 Linux Shell
linux命令
常用 Linux 命令汇总
|
4月前
|
Linux C++
每天一个linux命令(8):cp 命令
cp 命令是 Linux 中用于复制文件或目录的命令。它的名字来源于英文单词 copy。这个命令非常常用,特别是在需要备份文件或创建文件副本时。
263 0

热门文章

最新文章

下一篇
oss云网关配置