インストール
システム要求
NGINX Unit は以下のシステムでコンパイルおよび実行をテストされています:
- Linux 2.6 以降
- FreeBSD 9 以降
- MacOS X
- Solaris 11
アーキテクチャー:
- i386
- amd64
- powerpc
- arm
NGINX Unitの中で実行しているアプリケーションのために、それぞれプログラミング言語が必要です:
- Python 2.6, 2.7, 3
- PHP 5, 7
- Go 1.6 以降
- Perl 5.12 以降
- Ruby 2.0 以降
同じシステム上にインストールされている複数の同じ言語を実行することができます。
事前コンパイルされたパッケージ¶
Unitのために事前コンパイルされたバイナリは以下で利用可能です:
- CentOS 6, 7
- RHEL 6, 7
- Amazon Linux
- Ubuntu 16.04, 17.10
- Debian 8, 9
CentOS パッケージ¶
以下の内容で **/etc/yum.repos.d/unit.repo** ファイルを生成します:
[unit] name=unit repo baseurl=https://packages.nginx.org/unit/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
Unitベースのパッケージのインストール:
# yum install unit
使用したい追加のモジュールパッケージのインストール。例えば:
# yum install unit-php unit-python unit-go unit-perl
RHEL パッケージ¶
以下の内容で **/etc/yum.repos.d/unit.repo** ファイルを生成します:
[unit] name=unit repo baseurl=https://packages.nginx.org/unit/rhel/$releasever/$basearch/ gpgcheck=0 enabled=1
Unitベースのパッケージのインストール:
# yum install unit
使用したい追加のモジュールパッケージのインストール。
RHEL 6 について:
# yum install unit-php unit-python unit-perl
RHEL 7 について:
# yum install unit-php unit-python unit-go unit-perl
Amazon Linux パッケージ¶
以下の内容で **/etc/yum.repos.d/unit.repo** ファイルを生成します:
[unit] name=unit repo baseurl=https://packages.nginx.org/unit/amzn/$releasever/$basearch/ gpgcheck=0 enabled=1
Amazon Linux 2 LTS について:
[unit] name=unit repo baseurl=https://packages.nginx.org/unit/amzn2/$releasever/$basearch/ gpgcheck=0 enabled=1
Unitベースのパッケージのインストール:
# yum install unit
使用したい追加のモジュールパッケージのインストール。例えば:
# yum install unit-php unit-python27 unit-python34 unit-python35 unit-python36 unit-go unit-perl
Amazon Linux 2 LTS について:
# yum install unit-php unit-python unit-go unit-perl
Ubuntu パッケージ¶
NGINX, Inc. のリポジトリとパッケージを署名するために使われている キー をダウンロードする。
Add the key to the
apt
program’s keyring:# apt-key add nginx_signing.key
プログラムはNGINXのリポジトリの署名を認証することができます。これはUnitパッケージのインストールの間に失われたPGPキーについての警告を無視します。
以下の内容を持つ /etc/apt/sources.list.d/unit.list ファイルを作成する。
Ubuntu 16.04 について:
deb https://packages.nginx.org/unit/ubuntu/ xenial unit deb-src https://packages.nginx.org/unit/ubuntu/ xenial unit
Ubuntu 17.10 について:
deb https://packages.nginx.org/unit/ubuntu/ artful unit deb-src https://packages.nginx.org/unit/ubuntu/ artful unit
Unitベースのパッケージのインストール:
# apt-get update # apt-get install unit
使用したい追加のモジュールパッケージのインストール。
Ubuntu 16.04 について:
# apt-get install unit-php unit-python2.7 unit-python3.5 unit-go unit-perl unit-ruby
Ubuntu 17.10 について:
# apt-get install unit-php unit-python2.7 unit-python3.6 unit-go1.8 unit-go1.9 unit-perl unit-ruby
Debian パッケージ¶
NGINX, Inc. のリポジトリとパッケージを署名するために使われている キー をダウンロードする。
Add the key to the
apt
program’s keyring:# apt-key add nginx_signing.key
プログラムはNGINXのリポジトリの署名を認証することができます。これはUnitパッケージのインストールの間に失われたPGPキーについての警告を無視します。
以下の内容を持つ /etc/apt/sources.list.d/unit.list ファイルを作成する。
Debian 8 について:
deb https://packages.nginx.org/unit/debian/ jessie unit deb-src https://packages.nginx.org/unit/debian/ jessie unit
Debian 9 について:
deb https://packages.nginx.org/unit/debian/ stretch unit deb-src https://packages.nginx.org/unit/debian/ stretch unit
Unitベースのパッケージのインストール:
# apt-get update # apt-get install unit
使用したい追加のモジュールパッケージのインストール。
Debian 8 について:
# apt-get install unit-php unit-python2.7 unit-python3.4 unit-perl unit-ruby
Debian 9 について:
# apt-get install unit-php unit-python2.7 unit-python3.5 unit-go1.7 unit-go1.8 unit-perl unit-ruby
ソースコード¶
この章はソースコードからUnitをコンパイルしインストールする方法を説明します。
ソースの取得¶
Unitソースコードを取得するには3つの方法があります: NGINX, Inc. のMercurialリポジトリから、GitHubから、あるいはtarballの中で。
どの場合でも、ソースは現在の作業ディレクトリのunit サブディレクトリに置かれます。
Mercurial レポジトリ¶
Mercurial ソフトウェアがまだ無い場合は、ダウンロードしインストールします。例えば、Ubuntuシステムでは、このコマンドを実行します:
# apt-get install mercurial
Unitソースをダウンロードします:
# hg clone https://hg.nginx.org/unit
GitHub レポジトリ¶
まだGitソフトウェアが無い場合は、ダウンロードします。GitHub ドキュメントを見てください。
Unitソースをダウンロードします:
# git clone https://github.com/nginx/unit
Tarball¶
Unit ソースコードのtarballは https://unit.nginx.org/download/で利用可能です。
必要なソフトウェアのインストール¶
Unitを設定およびコンパイルする前に、必要なビルドツールに加えてサポートしたい利用可能な言語 (Go, PHP, and Python) のそれぞれのためのライブラリをインストールする必要があります。
Ubuntu の前提条件¶
ビルドツールをインストールする:
# apt-get install build-essential
Goアプリケーションのサポートのために、
golang
パッケージをインストールします:# apt-get install golang
PHPアプリケーションのために
php-dev
とlibphp-embed
パッケージをインストールします:# apt-get install php-dev # apt-get install libphp-embed
Python アプリケーションのサポートのために、
python-dev
パッケージをインストールします:# apt-get install python-dev
Perl アプリケーションのサポートのために、
libperl-dev
パッケージをインストールします:# apt-get install libperl-dev
Ruby アプリケーションのサポートのために、
ruby-dev
パッケージをインストールします:# apt-get install ruby-dev
CentOSの前提条件¶
ビルドツールをインストールする:
# yum install gcc make
Goアプリケーションのサポートのために、
golang
パッケージをインストールします:# yum install golang
PHP アプリケーションのサポートのために、
php-devel
とphp-embedded
パッケージをインストールします。# yum install php-devel php-embedded
Python アプリケーションのサポートのために、
python-devel
パッケージをインストールします。# yum install python-devel
Perl アプリケーションのサポートのために、
perl-devel
とperl-libs
パッケージをインストールします。# yum install perl-devel perl-libs
Ruby アプリケーションのサポートのために、
ruby-devel
パッケージをインストールします:# yum install ruby-devel
ソースの設定¶
最小に必要なシステムチェックを行い、他の全てのものをコンパイルために必要とされるMakefileを生成するために、configureスクリプトを実行する必要があります:
# ./configure
Unitを使って、サポートされる言語 (Go, PHP, or Python) の異なるバージョンを使うアプリケーションを同時に実行することができます。それぞれのために個々のUnitモジュールを設定する必要があります。以下のコマンドは各モジュールについてMakefileの中の必要な命令を生成します。
Goパッケージの設定¶
NGINX Unit はUnit内であなたのGoアプリケーションを実行するために必要なGoパッケージを提供するでしょう。
GOPATH
環境変数を設定します。これはUnit Goパッケージのための出力ディレクトリを設定します。# export GOPATH=/home/user/go_apps
次のコマンドを実行します:
# ./configure go configuring Go package checking for Go ... found + go version go1.6.2 linux/amd64 + Go package path: "/home/user/go_apps"
作業中のGOPATHにGoパッケージをインストールします:
# make go-install
Goアプリケーションのビルド¶
Goアプリケーションのためのソースファイルを修正し、二つの箇所を変更します:
import
セクションの中で、個々の行で"nginx/unit"
を追加します。import ( "fmt" "net/http" "nginx/unit" )
main()
関数の中で、http.ListenandServe
関数をコメントアウトし、unit.ListenAndServe
関数を挿入します。func main() { http.HandleFunc("/", handler) //http.ListenAndServe(":8080", nil) unit.ListenAndServe(":8080", nil) }
Goアプリケーションをビルドします:
# go build
Goアプリケーションが直接実行される場合、unitモジュールはhttpモジュールに戻るでしょう。GoアプリケーションがUnitによって起動される場合、共有メモリを経由してUnitルーターと通信するでしょう。
Perlモジュールの設定¶
To configure a Unit module (called perl.unit.so) for the version of
Perl that the configure
script finds bundled with the operating system,
run this command:
# ./configure perl
他のバージョンのPerl (あなたがカスタム化したバージョンを含む)のためにUnitモジュールを設定するために、それぞれについて以下のコマンドを繰り返します:
# ./configure perl OPTIONS
OPTIONS
は以下のものです:
--module=<prefix> | |
Perl バージョンに固有のUnitモジュールのためのファイル名のプリフィックスを設定します (つまり、結果のモジュールは <prefix>.unit.soと呼ばれます)。 | |
--perl=<perl> | 特定のPerlインタプリタを指定します。 |
--include=<directory> | |
使用するPerl ヘッダ ファイルについてのディレクトリを指定します。 |
例えば、このコマンドは Perl 5.20.2 のための perl-5.20.unit.so と呼ばれるモジュールを生成します:
$ ./configure perl --module=perl-5.20 \
--perl=perl5.20.2
configuring Perl module
checking for Perl ... found
+ Perl version: 5.20.2
+ Perl module: perl-5.20.unit.so
PHPモジュールの設定¶
To configure a Unit module (called php.unit.so) for the version of
PHP that the configure
script finds bundled with the operating system,
run this command:
# ./configure php
他のバージョンのPHP(あなたがカスタム化したバージョンを含む)のためにUnitモジュールを設定するために、それぞれについて以下のコマンドを繰り返します:
# ./configure php OPTIONS
OPTIONS
は以下のものです:
--module=<prefix> | |
PHP バージョンに固有のUnitモジュールのためのファイル名のプリフィックスを設定します (つまり、結果のモジュールは <prefix>.unit.soと呼ばれます)。 | |
--config=<script> | |
PHPの特定のバージョンのための php-config を指定します。 | |
--lib-path=<directory> | |
使用するPHPライブラリファイルのためのディレクトリを指定します。 | |
--lib-static | 静的ライブラリとのリンクを有効にします。 |
例えば、このコマンドはPHP 7.0のための php70.unit.so と呼ばれるモジュールを生成します:
# ./configure php --module=php70 \
--config=/usr/lib64/php7.0/bin/php-config \
--lib-path=/usr/lib64/php7.0/lib64
configuring PHP module
checking for PHP ... found
+ PHP version: 7.0.22-0ubuntu0.16.04.1
+ PHP SAPI: [apache2handler embed cgi cli fpm]
checking for PHP embed SAPI ... found
+ PHP module: php70.unit.so
Pythonモジュールの設定¶
To configure a Unit module (called python.unit.so) for the version of
Python that the configure
script finds bundled with the operating system,
run this command:
# ./configure python
他のバージョンのPython(あなたがカスタム化したバージョンを含む)のためにUnitモジュールを設定するために、それぞれについて以下のコマンドを繰り返します:
# ./configure python OPTIONS
OPTIONS
は以下のものです:
--module=<prefix> | |
Python バージョンに固有のUnitモジュールのためのファイル名のプリフィックスを設定します (つまり、結果のモジュールは <prefix>.unit.soと呼ばれます)。 | |
--config=<script> | |
Pythonの特定のバージョンのための python-config を指定します。 | |
--lib-path=<directory> | |
使用するPythonライブラリファイルのためのディレクトリを指定します。 |
例えば、このコマンドはPython 3.3のための py33.unit.so と呼ばれるモジュールを生成します:
# ./configure python --module=py33 \
--config=python-config-3.3
configuring Python module
checking for Python ... found
checking for Python version ... 3.3
+ Python module: py33.unit.so
Rubyモジュールの設定¶
To configure a Unit module (called ruby.unit.so) for the version of
Ruby that the configure
script finds bundled with the operating system,
run this command:
# ./configure ruby
他のバージョンのRuby (あなたがカスタム化したバージョンを含む)のためにUnitモジュールを設定するために、それぞれについて以下のコマンドを繰り返します:
# ./configure ruby OPTIONS
OPTIONS
は以下のものです:
--module=<prefix> | |
Ruby バージョンに固有のUnitモジュールのためのファイル名のプリフィックスを設定します (つまり、結果のモジュールは <prefix>.unit.soと呼ばれます)。 | |
--ruby=<ruby> | 特定のRubyインタプリタを指定します。 |
例えば、このコマンドはRuby 2.3のための ru23.unit.so と呼ばれるモジュールを生成します:
# ./configure ruby --module=ru23 \
--ruby=ruby23
configuring Ruby module
checking for Ruby ... found
+ Ruby version: 2.3.0
+ Ruby module: ru23.unit.so