スポンサーリンク

NginxをyumでMainlineからインストールする

スポンサーリンク
この記事は約9分で読めます。
スポンサーリンク

SSLを導入しようとしたんだけど、そういやCachePurgeモジュールを組み込むためにソースからコンパイルして導入していて、その時にSSL非対応にしていたことを思い出した。

もっと言うと、CachePurgeモジュール向けの設定を入れ忘れていて、あってもなくても、な状態であったことは秘密の話。 ということで、今回は素直にNginxをインストールしたい。

バージョンも古いし、最新バージョンに入れ替えてからSSL対応にしよう。

 

Nginxのダウンロードページを見ると、バージョンにはMainline version(1.9.4)、Stable version(1.8.0)、Legacy versions(それ以下)ってのがあって、nakayan.jpで使っている1.6.3は旧式のLegacy versionsだ。

では、新しくするにはどのバージョンを使えば良いのだろう?

一見するとStable versionを使いたくなってしまうが、Nginx開発者コメントによるとオススメはMainline versionということだ。 だけど、yumでインストールされるのは下記の通りでStable versionだね。

$ yum list nginx
nginx.x86_64 1.8.0-1.el6.ngx nginx

yumでインストールしておけばcrontabで自動アップデート設定もできるので、セキュリティ対策等も考えると自家用としてはこちらがオススメになるだろう。

でも、先のページのようにMainline versionがオススメであるなら、できればそっちを使いたいのでちょびっと修正をする。

 

では早速。

 

yumコマンドで使用されるパッケージのデータは下記に保存されているので、ここにnginx.repoというファイルがあれば編集し、無ければ作成する。

/etc/yum.repos.d/nginx.repo

中身は通常だとこうなっている。

# nginx.repo
[nginx]
name=nginx repo
baseurl=//nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

これを下記のように修正して保存する。

# nginx.repo
[nginx]
name=nginx repo
baseurl=//nginx.org/packages/mainline/centos/6/$basearch/
gpgcheck=0
enabled=1

これで最新版のnginxがインストールされる準備が整った。

$ yum list nginx
nginx.x86_64 1.9.4-1.el6.ngx @nginx

既にyumでインストールしている人はアップデートして終了だけど、オレは手動インストールだったので他にも準備が必要になる。

パッケージからインストールした場合との最大の違いは、インストール先が違うということ。 起動スクリプトはパッケージをインストールした段階で適切なものに上書きされるけど、設定ファイルはコピー&修正が必要になる。

前回ソースからインストールしたNginxの設定ファイルは下記にある。

/usr/local/nginx/conf/

yumでインストールすると下記になるので、上記にある設定ファイルをコピーする。

/etc/nginx/

この時、設定ファイル内にディレクトリ構造を書き加えている場合(conf.dの下に全部の設定ファイルを置いた、とか)は、ディレクトリ構造ごとコピーしないと動かなくなるよ。

こういう相対パスによる記述だとコピーだけで良いけど、ルートからの絶対パスで書いていたら、そこも修正すること。

include ./conf.d/*.conf;

で、だ。 このままインストールすると起動スクリプトが上書きされてしまうので、古い起動スクリプトをコピーして保存しておき、動作確認後に消去する。

$ sudo cp /etc/rc.d/init.d/nginx /etc/rc.d/init.d/nginx.old

さぁ、設定を確認し終えたらyumでインストールしよう。

$ sudo yum install -y nginx

再起動させる。 個人サイトは気楽で良いね!

$ sudo /etc/rc.d/init.d/nginx restart
nginx を停止中:??????????????????????????????????????????? [? OK? ]
nginx を起動中:??????????????????????????????????????????? [? OK? ]
$

yumのアップデートは毎晩cronで自動実行しているので、常に最新版が維持されるってことで、これで一安心ってところか。

ところで何が変わったのかな。 まずはインストールされているモジュールやコンパイルオプションはこう。

$ nginx -V
nginx version: nginx/1.9.4
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments:
–prefix=/etc/nginx
–sbin-path=/usr/sbin/nginx
–conf-path=/etc/nginx/nginx.conf
–error-log-path=/var/log/nginx/error.log
–http-log-path=/var/log/nginx/access.log
–pid-path=/var/run/nginx.pid
–lock-path=/var/run/nginx.lock
–http-client-body-temp-path=/var/cache/nginx/client_temp
–http-proxy-temp-path=/var/cache/nginx/proxy_temp
–http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
–http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
–http-scgi-temp-path=/var/cache/nginx/scgi_temp
–user=nginx
–group=nginx
–with-http_ssl_module
–with-http_realip_module
–with-http_addition_module
–with-http_sub_module
–with-http_dav_module
–with-http_flv_module
–with-http_mp4_module
–with-http_gunzip_module
–with-http_gzip_static_module
–with-http_random_index_module
–with-http_secure_link_module
–with-http_stub_status_module
–with-http_auth_request_module
–with-threads
–with-stream
–with-stream_ssl_module
–with-mail
–with-mail_ssl_module
–with-file-aio
–with-ipv6
–with-http_spdy_module
–with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
–param=ssp-buffer-size=4 -m64 -mtune=generic’
$

abコマンドでの負荷測定はこんな感じ。 今までの1.7系列より1割程度、高速で安定した数字が出ているかな、といったところ。 この辺は大規模サイトじゃないとハッキリとした違いは出てこないだろうね。

$ ab -n 10000 -c 100 /
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, //www.zeustech.net/
Licensed to The Apache Software Foundation, //www.apache.org/

Benchmarking nakayan.jp (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests

Server Software:??????? nginx
Server Hostname:??????? nakayan.jp
Server Port:??????????? 80

Document Path:????????? /
Document Length:??????? 63849 bytes

Concurrency Level:????? 100
Time taken for tests:?? 1.211 seconds
Complete requests:????? 10000
Failed requests:??????? 0
Write errors:?????????? 0
Total transferred:????? 640020000 bytes
HTML transferred:?????? 638490000 bytes
Requests per second:??? 8255.52 [#/sec] (mean)
Time per request:?????? 12.113 [ms] (mean)
Time per request:?????? 0.121 [ms] (mean, across all concurrent requests)
Transfer rate:????????? 515986.01 [Kbytes/sec] received

Connection Times (ms)
min? mean[+/-sd] median?? max
Connect:??????? 0??? 1?? 1.7????? 0????? 12
Processing:???? 4?? 11?? 3.7???? 10????? 32
Waiting:??????? 0??? 9?? 4.2????? 9????? 32
Total:????????? 7?? 12?? 3.9???? 10????? 32

Percentage of the requests served within a certain time (ms)
50%???? 10
66%???? 12
75%???? 13
80%???? 15
90%???? 18
95%???? 20
98%???? 23
99%???? 26
100%???? 32 (longest request)

それにしても、月額900円のさくらのVPS(1Gプラン)で、ここまでの性能が出せるNginxってホント凄いよなー。 ローカルでのabコマンド結果でしかないけど、7億アクセス/日だもんね(笑

セキュリティや信頼性、品質の面で大きく進歩したという新しいnginx。 この先の進歩が楽しみだ。

 

コメント

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