在CentOS 6.8 x86_64上安装nghttp2最新版及让curl具有http2特性
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 --http2 -I https://nghttp2.org/
curl --http2 -vo test.out https://nghttp2.org/
我們可以看到詳細的交互信息
參考文獻
http://blog.csdn.net/freewebsys/article/details/59112145
https://wzyboy.im/post/1052.html
官網RFC
https://tools.ietf.org/html/rfc7540 ? ?HTTP/2
https://tools.ietf.org/html/rfc7541 ? ?HPACK
https://tools.ietf.org/html/rfc7838 ? ?HTTP Alternative Services
其它參考資料(由淺入深)
http://www.cnblogs.com/zlingh/p/5887143.html ? ? ? ? ? ? ? ? ? ?HTTP 2.0的那些事
https://bagder.gitbooks.io/http2-explained/zh/ ? ? ? ? ? ? ? ? ? ? ? http2講解
High Performanc Browser Networking(Web性能權威指南) ? 第12章
https://hpbn.co/http2/ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 電子書最新版本
總結
以上是生活随笔為你收集整理的在CentOS 6.8 x86_64上安装nghttp2最新版及让curl具有http2特性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在CentOS 6.8 x86_64上利
- 下一篇: 在CentOS 6.8 x86_64的n