nginxのリポジトリを使用してnginxをインストール

CentOSにnginx.orgで公開されているリポジトリを使用して、「nginx」をインストール方法です。

stableとmainlineブランチについて

「nginx」には「stable」と「mainline」という2つのブランチが用意されていて、それぞれブランチにより提供される「nginx」のバージョンが違ってきます。

公式サイトに分かりやすい図がありましたので参考にしてください。
https://www.nginx.com/blog/nginx-1-12-1-13-released/

ブランチの違い

「stable」と「mainline」ブランチの違いを簡単にまとめてみましたので参考にしてください。

stable 重大なバグ修正のみ反映されサードパーティのモジュールへの影響がほとんどない
mainline 新しい機能追加やすべてのバクフィックスが反映され信頼性が高いが、stableバージョンとことなりサードパーティのモジュールへ動作に影響を与える可能性がある

どちらのブランチを選べばよいのか?

公式ブログでは「mainline」ブランチの方が、すべての新しい機能やパフォーマンスの向上、重大なバグ修正以外も反映されるので「stable」ブランチよりも安定しているとされておすすめされています。

We generally recommend using the mainline branch. This is where we commit all new features, performance improvements, and enhancements. We actively test and QA the mainline branch, so it’s arguably more stable than the “stable” branch. The mainline branch is also the source of NGINX Plus builds for our commercial customers.
If you want to minimize the number of updates you need to deploy and don’t anticipate an urgent need for any of the features planned for the next 12 months, the stable branch is a good choice.

サードパーティモジュールとの連携や、新機能の追加によるバグなどが気になる場合はstableを使用する方が良いでしょう。

nginxリポジトリ設定

nginxの公式ページに記述されている方法で「stable」と「mainline」それぞれのリポジトリを追加していきます。

stableブランチ

公式サイトのドキュメントを参考にしてリポジトリファイル「/etc/yum.repos.d/nginx.repo」を作成していきます。

http://nginx.org/en/linux_packages.html#stable

To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “6” or “7”, for 6.x or 7.x versions, respectively.

「baseurl」部分の「OS」「OSRELEASE」をドキュメント通りに置き換えていきます。

  • OS CentOSの場合「centos」と指定
  • OSRELEASE CentOSのバージョンを指定 6系は「6」7系は「7」とする

設定例

CentOS7環境にリポジトリを追加する場合の例になります。

# vi /etc/yum.repos.d/nginx.repo
設定内容
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=0

※CentOS6の場合は「baseurl」部分を下記のように設定します。
baseurl=http://nginx.org/packages/centos/6/$basearch/

Mainlineブランチ

こちらの場合も公式サイトのドキュメントを参考にしてリポジトリファイル「/etc/yum.repos.d/nginx.repo」を作成していきます。

http://nginx.org/en/linux_packages.html#mainline

To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “6” or “7”, for 6.x or 7.x versions, respectively.

「baseurl」部分の「OS」「OSRELEASE」をドキュメント通りに置き換えていきます。

  • OS CentOSの場合「centos」と指定
  • OSRELEASE CentOSのバージョンを指定 6系は「6」7系は「7」とする

設定例

CentOS7環境にリポジトリを追加する場合の例になります。

# vi /etc/yum.repos.d/nginx.repo
設定内容
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=0

※CentOS6の場合は「baseurl」部分を下記のように設定します。
baseurl=http://nginx.org/packages/mainline/centos/6/$basearch/

nginxインストール

追加したリポジトリを使用して「nginx」をインストールする場合は「--enablerepo=nginx」で、「nginx」リポジトリを指定してインストールをおこないます。

# yum --enablerepo=nginx install nginx

バージョンの確認

インストールされた「nginx」のバージョンは下記コマンドで確認することが出来ます。

# nginx -v
nginx version: nginx/1.11.13

コメント

タイトルとURLをコピーしました