在 CentOS 6.8 x86_64 上安装 nghttp2 最新版及让 curl 具有 http2 特性

简介: 在 CentOS 6.8 x86_64 上安装 nghttp2 最新版及让 curl 具有 http2 特性

nghttp2 是什么?

nghttp2 是一个实现 IETF 官方 HTTP/2 和 HPACK 头压缩算法的 C 库,但不限如此,在 C 库基础上,还实现了 http2 的客户端,服务器,代理服务器,以及压测工具。参见官网链接

http://www.nghttp2.org/

目前最新版本是 1.24.0

https://github.com/nghttp2/nghttp2/releases


网上基本上都是在 Ubuntu 平台上安装 nghttp2,比如,我按照下面的链接在 Ubuntu 16.04.1 LTS 上顺利安装了 nghttp2

http://www.linuxidc.com/Linux/2016-01/127588.htm

 

安装之前的准备

升级 Autoconf 2.63 到 2.69

http://blog.csdn.net/tao_627/article/details/77259591

升级 GCC 4.4.7 到 4.9.2 (通过 devtoolset)

http://blog.csdn.net/tao_627/article/details/77260963

 

安装相关依赖库

sudo yum -y groupinstall "Development Tools"

sudo yum -y install openssl-devel libxml2-devel libev-devel jemalloc-devel python-devel

wget https://c-ares.haxx.se/download/c-ares-1.12.0.tar.gz -O /tmp/c-ares.tar.gz

mkdir -p /tmp/c-ares

tar -zxvf /tmp/c-ares.tar.gz -C /tmp/c-ares --strip-components=1

cd /tmp/c-ares && ./configure --libdir=/usr/lib64

make

sudo make install

wget http://www.digip.org/jansson/releases/jansson-2.9.tar.gz -O /tmp/jansson.tar.gz

mkdir -p /tmp/jansson

tar -zxvf /tmp/jansson.tar.gz -C /tmp/jansson --strip-components=1

cd /tmp/jansson && ./configure --libdir=/usr/lib64

make

make check

sudo make install


下面编译 nghttp2 最新版

wget https://github.com/nghttp2/nghttp2/releases/download/v1.24.0/nghttp2-1.24.0.tar.bz2

tar jxvf nghttp2-1.24.0.tar.bz2

cd nghttp2-1.24.0

./configure

make

make install

这里只是安装的库,在 /usr/local/lib/libnghttp2.so,头文件在 /usr/local/include/nghttp2


更新动态库

vim /etc/ld.so.conf

添加‘/usr/local/lib’

更新配置文件,执行 ldconfig


注意:nghttp2 本身就是一个 http2 的巨大宝库,这里我们仅是简单用到它的动态库。有兴趣的可以继续研究它的其它应用。


下面将 nghttp2 添加进 curl 中,使 curl 带有 HTTP2 特性

从官网下载最新版 curl 源码

wget https://curl.haxx.se/download/curl-7.55.1.tar.bz2

tar jxvf curl-7.55.1.tar.bz2

cd curl-7.55.1

./configure --with-nghttp2=/usr/local --with-ssl

make

make install


必要时修改环境变量

echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf

ldconfig

更新动态库


遇到的问题

在源码编译 curl 时,执行 configure 命令遇到

checking run-time libs availability... failed

configure: error: one or more libs available at link-time are not available run-time. Libs used at link-time: -lnghttp2   -lssl -lcrypto -lssl -lcrypto   -lz -lrt

解决方法

刚才安装的动态库没有刷新到系统中,导致编译 curl 时没有找到

vim /etc/ld.so.conf

添加‘/usr/local/lib’

更新配置文件,执行 ldconfig

查找下面的库是否已经找到

ldconfig -p | grep --color libnghttp2

验证

查看 curl 版本时会发布特性中会增加 HTTP2 功能支持。此时 –http2 参数就可以正常使用了:

测试 curl with http2

我们再使用如下命令测试

curl --http2 -I https://nghttp2.org/

curl --http2 -vo test.out https://nghttp2.org/

我们可以看到详细的交互信息

目录
打赏
0
0
0
0
0
分享
相关文章
|
9天前
|
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
59 20
Centos7.9安装kerberos
Centos7.9安装kerberos
84 25
Centos7.9安装openldap
Centos7.9安装openldap
54 16
centos7环境下tomcat8的安装与配置
本文介绍了在Linux环境下安装和配置Tomcat 8的详细步骤。首先,通过无网络条件下的文件交互软件(如Xftp 6或MobaXterm)下载并解压Tomcat安装包至指定路径,启动Tomcat服务并测试访问。接着,修改Tomcat端口号以避免冲突,并部署Java Web应用项目至Tomcat服务器。最后,调整Linux防火墙规则,确保外部可以正常访问部署的应用。关键步骤包括关闭或配置防火墙、添加必要的端口规则,确保Tomcat服务稳定运行。
从配置源到数据库初始化一步步教你在CentOS 7.9上安装SQL Server 2019
【11月更文挑战第16天】本文介绍了在 CentOS 7.9 上安装 SQL Server 2019 的详细步骤,包括配置系统源、安装 SQL Server 2019 软件包以及数据库初始化,确保 SQL Server 正常运行。
157 4
VMware安装CentOS7
【11月更文挑战第11天】本文详细介绍了在 VMware 中安装 CentOS 7 的步骤,包括准备工作、创建虚拟机、配置虚拟机硬件和安装 CentOS 7。具体步骤涵盖下载 CentOS 7 镜像文件、安装 VMware 软件、创建和配置虚拟机硬件、启动虚拟机并进行安装设置,最终完成 CentOS 7 的安装。在安装过程中,需注意合理设置磁盘分区、软件选择和网络配置,以确保系统的性能和功能满足需求。
399 0
基于CentOS安装http_load压测工具
基于CentOS安装http_load压测工具,方便快捷,安装包只有100K!
294 0
从配置源到数据库初始化一步步教你在CentOS 7.9上安装SQL Server 2019
【11月更文挑战第8天】本文介绍了在 CentOS 7.9 上安装 SQL Server 2019 的详细步骤,包括系统准备、配置安装源、安装 SQL Server 软件包、运行安装程序、初始化数据库以及配置远程连接。通过这些步骤,您可以顺利地在 CentOS 系统上部署和使用 SQL Server 2019。
173 1
Linux系统之Centos7安装cockpit图形管理界面
【10月更文挑战第12天】Linux系统之Centos7安装cockpit图形管理界面
179 1
Linux系统之Centos7安装cockpit图形管理界面