案外まだまだ国内のクラウドの会社だとCentOS6系しかない場合も有るかと思います。
CentOS7ならもっと簡単なhttp2環境の導入をCentOS6.9を利用してインストールしていきます。
(インストールを始める想定環境はCentOS6.9をminimalにてインストールした場合になります)
この手順に沿えばエラーなくインストール出来るかと思います。
ファイルのダウンロードの際にディレクトリを適宜ダウンロード用のディレクトリへ戻って下さい。
(ここでは cd ..
といったコマンドは割愛します)
各種インストールの為の前準備
まずは必要なライブラリを入れるためにEPELを有効にします。
yum install epel-release
各種ライブラリなどのインストールに必要なライブラリをインストールします
yum install perl glib jemalloc jemalloc-devel libxml2-devel python-devel expat-devel pcre-devel wget gcc
これで前準備は大丈夫です。
pkg-configのインストール
pkg-configを利用するのでインストールを行います。
ソースファイルをダウンロード
wget https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
インストール
tar -zxvf pkg-config-0.29.2.tar.gz cd pkg-config-0.29.2 ./configure --with-internal-glib make make install
c-aresのインストール
nghttp2で使うc-aresをインストールします。
※c-aresとはDNSへの問い合わせを非同期で行う事が出来るCのライブラリです。
ソースファイルをダウンロード
wget https://c-ares.haxx.se/download/c-ares-1.13.0.tar.gz
インストール
tar -zxvf c-ares-1.13.0.tar.gz cd c-ares-1.13.0 ./configure make make install
libevのインストール
こちらもnghttp2で使うlibevをインストールします
※libevは非同期処理を行う為のライブラリです
ソースファイルをダウンロード
wget http://dist.schmorp.de/libev/libev-4.24.tar.gz
インストール
tar -zxvf libev-4.24.tar.gz cd libev-4.24 ./configure make make install
openssl 1.0.2系のインストール
http2に対応させるためopenssl 1.0.2系をインストールします。
ソースファイルをダウンロード
(現時点では1.0.2系の最新は1.0.2mになります)
wget https://www.openssl.org/source/openssl-1.0.2m.tar.gz
インストール
既存のopensslとの競合があるのでインストールディレクトリを変更してインストールします。
tar -zxvf openssl-1.0.2m.tar.gz cd openssl-1.0.2m ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl -fPIC shared make make install
pkg-config用のファイルをpkg-configのライブラリパスにコピーします
cp /usr/local/openssl/lib/pkgconfig/libcrypto.pc /usr/local/lib/pkgconfig cp /usr/local/openssl/lib/pkgconfig/libssl.pc /usr/local/lib/pkgconfig cp /usr/local/openssl/lib/pkgconfig/openssl.pc /usr/local/lib/pkgconfig
libxml2のインストール
ソースファイルをダウンロード
wget ftp://xmlsoft.org/libxml2/libxml2-2.9.6.tar.gz
インストール
tar -zxvf libxml2-2.9.6.tar.gz cd libxml2-2.9.6 ./configure make make install
janssonのインストール
※janssonとはC言語用のJSONパーサーです。
ソースファイルをダウンロード
wget http://www.digip.org/jansson/releases/jansson-2.10.tar.gz
インストール
tar -zxvf jansson-2.10.tar.gz cd jansson-2.10 ./configure make make install
libeventのインストール
※libeventは非同期でのイベント通知ライブラリです。
ソースファイルをダウンロード
wget https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
インストール
サンプルはいらないので除外してインストールします
tar -zxvf libevent-2.1.8-stable.tar.gz cd libevent-2.1.8-stable ./configure --disable-samples make make install
devtoolを利用してgccのバージョン2のインストール
centos6.9の標準だとgccのバージョンが古いためdevtoolを利用してgccのバージョン2をインストールします
リポジトリを設定します。
`wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
インストールします
yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++ devtoolset-2-gcc-gfortran`
切り替える際には
scl enable devtoolset-2 bash
をコマンドで入れるか、bash_profileに上記コマンドを入れる必要があります。
(但しbash_profileに入れてしまうと、常にgccのバージョンが新しい状態になるので注意が必要です)
nghttp2のインストール
ソースファイルのダウンロード
wget https://github.com/nghttp2/nghttp2/releases/download/v1.28.0/nghttp2-1.28.0.tar.gz
gccのバージョンが古いままだとインストール失敗しますので、上げて無ければバージョンを上げておきます
scl enable devtoolset-2 bash
インストールします。
tar -zxvf nghttp2-1.28.0.tar.gz cd nghttp2-1.28.0
こちらもサンプルはいらない為外しておきます
env CPPFLAGS="" OPENSSL_CFLAGS="-I/usr/local/openssl/include" OPENSSL_LIBS="-L/usr/local/openssl/lib -lssl -lcrypto" LIBCARES_CFLAGS="-I/usr/local/include" LIBCARES_LIBS="-L/usr/local/lib -lcares" ZLIB_CFLAGS="-I/usr/include" ZLIB_LIBS="-lz" CFLAGS="-std=gnu11" CPPFLAGS="-I/usr/local/include -I/usr/include " ./configure --disable-examples
make
make install
apr及びapr-utilのインストール
apacheにopenssl1.0.2対応の為にapr及びapr-utilをインストールします。
ダウンロードします
wget http://ftp.kddilabs.jp/infosystems/apache//apr/apr-1.6.3.tar.gz
wget http://ftp.yz.yamagata-u.ac.jp/pub/network/apache//apr/apr-util-1.6.1.tar.gz
ライブラリへのパスを変更するためbash(適宜お使いのshellに変えて下さい)の設定を作ります
vi .bash_profile_ssl
if [ -n $LD_LIBRARY_PATH ]; then
echo "Add /usr/local/openssl/lib."
export LD_LIBRARY_PATH=/usr/local/openssl/lib:${LD_LIBRARY_PATH}
fi
設定を読み込みます
. ~/.bash_profile_ssl
aprをインストールします
tar -zxvf apr-1.6.3.tar.gz cd apr-1.6.3 ./configure make make install
apr-utilのインストールします
その際に先ほどいれたaprのパス及び、自分でいれたopenssl1.0.2へのパスを設定します。
tar -zxvf apr-util-1.6.1.tar.gz cd apr-util-1.6.1 ./configure --with-apr=/usr/local/apr --with-openssl=/usr/local/openssl make make install
Apache2.4のインストール
今までインストールした各ライブラリなどを組み込む形でapacheをインストールします。
ソースファイルをダウンロードします。
wget http://ftp.kddilabs.jp/infosystems/apache//httpd/httpd-2.4.29.tar.gz
インストールします
configureを行う際に、あらかじめインストールしていたnghttp2、apr、apr-utilを設定します。
tar -zxvf httpd-2.4.29.tar.gz cd httpd-2.4.29 ./configure --enable-http2 --enable-nghttp2-staticlib-deps --with-ssl=/usr/local/openssl/ --enable-so --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config --with-include-apr=/usr/local/apr/include/ --enable-mpms-shared=all --enable-mods-shared=all --with-crypto
make
make install
環境構築完了!
これでインストールは完了になります。
apacheの設定を記述し、起動すればhttp2環境のできあがりです。
次回はPHPのインストール及びApache等の設定周りをご紹介できればと思います。