LoginSignup
26
22

More than 5 years have passed since last update.

Jettyのインストール(EC2 ver9.1)

Last updated at Posted at 2014-01-23

あるサービスでWebSocketを使いたかったので色々調べていたところ、
@ITさんのTomcat、Jetty、Socket.IO/Node.js性能比較
を発見、jettyがなかなか良さそうだと思いインストールを開始した次第。

JDKインストール

元々1.6が入っていたのですが、jetty 9以降は1.7対応なのでアップデートします。
Amazon Linux AMIのyumリポジトリ使っちゃいます。
※root作業


# yum install java-*
# alternatives --config java
 選択       コマンド
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java

Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2[Enter]

# java -version
java version "1.7.0_51"
OpenJDK Runtime Environment (amzn-2.4.4.1.34.amzn1-x86_64 u51-b02)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)

できました。YES、I Love yum.

Jettyのインストール

JettyでWebSocketを使うにはJetty7以降が必須で、6までの配布元codehaus(8までは平行配布っぽい)でなくEclipse Foundationで公開されています。
アクセスしてインストールする番号を確認します。Eclipse

スクリーンショット 2014-01-23 18.45.39.png

現時点で最新の9.1.1をインストールします。律儀に公式のインストール方法を従って環境変数インスコ!


# JETTY_VERSION=9.1.1.v20140108
# wget http://download.eclipse.org/jetty/$JETTY_VERSION/dist/jetty-distribution-$JETTY_VERSION.tar.gz
# tar xfz jetty-distribution-$JETTY_VERSION.tar.gz
# cd jetty-distribution-$JETTY_VERSION
# java -jar start.jar

おや、エラーが発生しました。

java.io.IOException: Cannot read file: modules/npn/npn-1.7.0_51.mod
at org.eclipse.jetty.start.Modules.registerModule(Modules.java:405)
at org.eclipse.jetty.start.Modules.registerAll(Modules.java:395)
at org.eclipse.jetty.start.Main.processCommandLine(Main.java:561)
at org.eclipse.jetty.start.Main.main(Main.java:102)

Usage: java -jar start.jar [options] [properties] [configs]
java -jar start.jar --help # for more information

modules/npn/npn-1.7.0_51.modがないとのこと。
どれどれ?


# ls modules/npn/
npn-1.7.0_10.mod  npn-1.7.0_13.mod  npn-1.7.0_17.mod  npn-1.7.0_25.mod  npn-1.7.0_40.mod  npn-1.7.0_5.mod  npn-1.7.0_7.mod
npn-1.7.0_11.mod  npn-1.7.0_15.mod  npn-1.7.0_21.mod  npn-1.7.0_4.mod   npn-1.7.0_45.mod  npn-1.7.0_6.mod  npn-1.7.0_9.mod

確かにない。java1.7.0_51版がサポートされてないって事ね・・・、
40と45のdiffを取ってみる。差分ないじゃん、うん大丈夫大丈夫!
というわけで力技で最新の45を51にしてしまえ!


# cp modules/npn/npn-1.7.0_45.mod modules/npn/npn-1.7.0_51.mod
# java -jar start.jar
2014-01-23 09:56:52.835:INFO:oejs.Server:main: jetty-9.1.1.v20140108
2014-01-23 09:56:52.945:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/root/tmp/jetty-distribution-9.1.1.v20140108/webapps/] at interval 1
2014-01-23 09:56:53.028:INFO:oejs.ServerConnector:main: Started ServerConnector@13c2a62a{HTTP/1.1}{0.0.0.0:8080}

ま、こんなもんでしょう。
http://[サーバIP]:8080にアクセスすればおそらく初期画面が表示されると思うんだけど、
AWSのセキュリティグループいじりたくないのでスルーします。きっとできてる。
一旦停止して起動スクリプトでも書くことにします。

2014/03/10
横着してましたが試しました。セキュリティグループで8080開けてあげたらちゃんと404が出ました。
スクリーンショット

デーモン化

まずJettyのモジュール類をそれなりの位置(なんとなく/usr/local/)に配置してうにゃうにゃします。


# cd ..
# mv jetty-distribution-$JETTY_VERSION /usr/local/.
# cd /usr/local/
# ln -s jetty-distribution-9.1.1.v20140108 jetty
# chmod +x /usr/local/jetty/bin/jetty.sh

起動スクリプトを配置


# cp jetty/bin/jetty.sh /etc/init.d/jetty
# vi /etc/init.d/jetty/

# 以下適当に挿入(僕は160step目くらいにつっこみました)
##################################################
# Jetty Home
##################################################
JETTY_HOME="/usr/local/jetty/"

これでOK。
自動起動設定するなら


# chkconfig --add /etc/init.d/jetty
# chkconfig jetty on
# chkconfig --list jetty
jetty           0:off   1:off   2:on    3:on    4:on    5:on    6:off

# service jetty restart
Stopping Jetty: OK
Starting Jetty: 2014-03-10 07:53:43.785:INFO::main: Redirecting stderr/stdout to /usr/local/jetty-distribution-9.1.1.v20140108/logs/2014_03_10.stderrout.log
OK Mon Mar 10 07:53:46 UTC 2014

ほいいっちょあがりー。

26
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
22