#author("2023-02-14T19:17:15+00:00","default:sysosa","sysosa") #author("2023-02-14T19:20:03+00:00","default:sysosa","sysosa") 本家 [[http://www.eclipse.org/jetty/>+http://www.eclipse.org/jetty/]] Java Servletコンテナ Tomcatでもいいのだが、小さくて分かり易いのでこちらを利用している。 手動で 9.4.xをインストールしてみた。 [[Jetty11]] ***Java [#gb0133bc] [[http://www.eclipse.org/jetty/documentation/current/what-jetty-version.html>+http://www.eclipse.org/jetty/documentation/current/what-jetty-version.html]]から、Jetty 9.4 はJava8が必要みたい。現状インストールされているのは #code(nonumber){{ [root@jetty ~]# cat /etc/redhat-release Rocky Linux release 8.7 (Green Obsidian) [root@jetty ~]# getenforce Enforcing [root@jetty ~]# java -version openjdk version "1.8.0_352" OpenJDK Runtime Environment (build 1.8.0_352-b08) OpenJDK 64-Bit Server VM (build 25.352-b08, mixed mode) [root@jetty ~]# }} なので大丈夫. openjdk-develパッケージは不要でjava run-time edition(Java Runtime Environment?)があればいいみたい. &color(magenta){alternatives};でパスを確認します #code(nonumber){{ [root@jetty ~]# alternatives --list libnssckbi.so.x86_64 auto /usr/lib64/pkcs11/p11-kit-trust.so python auto /usr/libexec/no-python ld auto /usr/bin/ld.bfd cifs-idmap-plugin auto /usr/lib64/cifs-utils/cifs_idmap_sss.so java manual /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.352.b08-2.el8_7.x86_64/jre/bin/java jre_openjdk auto /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.352.b08-2.el8_7.x86_64/jre jre_1.8.0 auto /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.352.b08-2.el8_7.x86_64/jre jre_1.8.0_openjdk auto /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.352.b08-2.el8_7.x86_64 [root@jetty ~]# }} ***導入 [#m7364211] [[hhttps://www.eclipse.org/jetty/download.html>+https://www.eclipse.org/jetty/download.html]]より''.tgz''リンクを押下 入手したファイル(&color(magenta){jetty-distribution-9.4.50.v20221201.tar.gz};)を/opt/jettyに配置 #code(nonumber){{ [root@jetty ~]# mkdir /opt/jetty [root@jetty ~]# cd /opt/jetty [root@jetty jetty]# curl -O https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/9.4.50.v20221201/jetty-distribution-9.4.50.v20221201.tar.gz [root@jetty jetty]# ls -lh total 19M -rw-r--r--. 1 root root 19M Feb 15 02:29 jetty-distribution-9.4.50.v20221201.tar.gz [root@jetty jetty]# }} 簡単な動作テストを行いたいのでその場で展開して demo-base をデプロイする. #code(nonumber){{ [root@jetty jetty]# tar xf jetty-distribution-9.4.50.v20221201.tar.gz [root@jetty jetty]# ls -l total 18588 drwxr-xr-x. 10 1000 1000 4096 Dec 2 07:18 jetty-distribution-9.4.50.v20221201 -rw-r--r--. 1 root root 19029816 Feb 15 02:29 jetty-distribution-9.4.50.v20221201.tar.gz [root@jetty jetty]# [root@jetty jetty]# cd jetty-distribution-9.4.50.v20221201/demo-base/ [root@jetty demo-base]# [root@jetty demo-base]# java -jar ../start.jar }} 別ターミナルを開いてfirewallに穴をあけます #code(nonumber){{ [root@jetty ~]# firewall-cmd --add-port=8080/tcp --zone=public --permanent [root@jetty ~]# firewall-cmd --reload }} こうしてブラウザを起動して、展開したサーバの8080を叩くと下記画面が現れる. &ref(2023y02m15d_024809221.png,nolink); 確認したら、&color(red){Ctrl-C};で停止 &color(red){*};&size(10){javaとjettyの組み合わせで稼動できるかのテストかな}; ***jettyの稼動ユーザを作成 [#y553dbb1] jettyをrootで稼動させず、特定のユーザで稼動させる。 &size(10){セキュアのためかな}; apache httpdの「apache」みたいなものと思えばいいかも. #code(nonumber){{ [root@jetty ~]# useradd -r -s /bin/false -d /opt/jetty -M jetty [root@jetty ~]# id jetty uid=993(jetty) gid=990(jetty) groups=990(jetty) [root@jetty ~]# }} /opt/jettyの所有権をjettyに渡す #code(nonumber){{ [root@jetty ~]# chown -R jetty. /opt/jetty }} ***起動スクリプト [#qac90dc9] jettyには起動スクリプトは「&color(magenta){/opt/jetty/jetty-distribution-9.4.50.v20221201/bin};」に「jetty.service」と「jetty.sh」が用意されている。 この「jetty.service」の中身を見ると #code(nonumber){{ [root@jetty ~]# cat /opt/jetty/jetty-distribution-9.4.50.v20221201/bin/jetty.service [Unit] Description=Jetty Web Application Server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/run/jetty/jetty.pid <-- オリジナル「/opt/web/mybase/jetty.pid」から修正済み ExecStart=/etc/init.d/jetty start ExecStop=/etc/init.d/jetty stop ExecReload=/etc/init.d/jetty restart User=jetty Group=jetty [Install] WantedBy=multi-user.target [root@jetty ~]# }} とsystemctl向けに調整されている. 「jetty.sh」はこの「jetty.service」からコールされるinit系の「/etc/init.d/jetty」と見受ける. なので、「jetty.service」は/etc/systemd/systemに供えて、「jetty.sh」は「/etc/init.d/jetty」に移します #code(nonumber){{ [root@jetty ~]# cp /opt/jetty/jetty-distribution-9.4.50.v20221201/bin/jetty.service /etc/systemd/system/ [root@jetty ~]# cp /opt/jetty/jetty-distribution-9.4.50.v20221201/bin/jetty.sh /etc/init.d/jetty }} jetty.serviceを登録して、計算機が起動したときに自動起動させるために下記のようにしておきます #code(nonumber){{ [root@jetty ~]# systemctl daemon-reload [root@jetty ~]# systemctl enable jetty.service }} &size(10){「/etc/systemd/system/jetty.service」を修正して「systemctl daemon-reload」しても反映されない場合は、「systemctl disable jetty.service」としてから「/etc/systemd/system/jetty.service」を修正した方がいいのかも}; ***設定ファイル [#zf44bead] jettyの稼動に必要な設定を行う。 「&color(orangered){/etc/init.d/jetty};」の中身を読むと稼働に必要な事項が記載されている まず、設定ファイルの場所は「/etc/default/$NAME」「$HOME/.$NAMErc」「/etc/$NAME.conf」のいずれか. $NAMEは「/etc/init.d/jetty」のbasename. つまりはportの重複をなくせば1台で複数のjettyが動かせれるみたい. &size(10){「/etc/init.d/jetty-test」とかで複数作れそう}; ここでは「/etc/default/jetty」を設定ファイルとします このファイルに必要な項目はJAVA、JAVA_OPTIONS、JETTY_HOME、JETTY_ARGS、JETTY_USERなどなどが定義対象. 詳しくは「&color(orangered){/etc/init.d/jetty};参照. ここではまず下記のようにした。 #code(nonumber){{ [root@jetty ~]# vi /etc/default/jetty JETTY_HOME=/opt/jetty/jetty-distribution-9.4.50.v20221201 JETTY_USER=jetty JETTY_ARGS=jetty.http.port=8080 JETTY_RUN=/run/jetty JETTY_SHELL=/bin/bash JETTY_BASE=/opt/jetty/jetty-distribution-9.4.50.v20221201/demo-base [root@jetty ~]# }} /run/jettyにpidファイルを置くのでフォルダを削除されないように下記の設定も行います #code(nonumber){{ [root@jetty ~]# echo "d /run/jetty 755 jetty jetty" > /etc/tmpfiles.d/jetty.conf [root@jetty ~]# /usr/bin/systemd-tmpfiles --create /etc/tmpfiles.d/jetty.conf }} &color(red){*};運用の際には「/opt/jetty/jetty-distribution-9.4.50.v20221201/webapps」にwarファイルを入れると思うので、テストが終わったら「JETTY_BASE」を適切にする必要あり ***起動 [#i14186f9] 単純に #code(nonumber){{ [root@jetty ~]# systemctl start jetty }} でOK. 停止は #code(nonumber){{ [root@jetty ~]# systemctl stop jetty }} とする。 定義が間違っていると、stopを実施したのにjettyプロセスが残る場合があります。 その際はプロセス番号を見つけて 「kill -9 <pid>」して下さい ***Gitbucket [#n24d0826] [[GitBucket]]を載せてみた. GitBucketのファイルを入手して、「/opt/jetty/jetty-distribution-9.4.50.v20221201/webapps」 に配置 #code(nonumber){{ [root@jetty ~]# cd /opt/jetty/jetty-distribution-9.4.50.v20221201/webapps [root@jetty webapps]# wget https://github.com/gitbucket/gitbucket/releases/download/4.38.4/gitbucket.war [root@git webapps]# chown jetty:jetty gitbucket.war }} &color(white,blue){留意}; GitBucketは自身の設定ファイルを持つ。その場所は通常ならコンテナ稼動者のホームディレクトリに置かれてしまう。 ここの場合ではjettyユーザの「/opt/jetty」の配下に置かれる. それをコントロールするには「&color(red){/opt/jetty/.bashrc};」を調整する #code(nonumber){{ [root@jetty ~]# cp /etc/skel/.bash_profile /opt/jetty/ [root@jetty ~]# cp /etc/skel/.bashrc /opt/jetty/ [root@jetty ~]# echo "export GITBUCKET_HOME=/opt/jetty/gitbucket" >> /opt/jetty/.bashrc [root@jetty ~]# mkdir /opt/jetty/gitbucket && chown jetty:jetty $_ }} &color(red){*};&size(10){当初、「&color(crimson){/etc/default/jetty};」にGITBUCKET_HOME環境変数を加えたが機能しない. 調べたら「jetty.sh」474行「su - "$JETTY_USER" $SU_SHELL -c "」とあったので$HOME/.bashrcに記載させ有効にした}; 「&color(crimson){/etc/default/jetty};」を下記のようにして、 #code(nonumber){{ [root@jetty ~]# vi /etc/default/jetty JETTY_HOME=/opt/jetty/jetty-distribution-9.4.50.v20221201 JETTY_USER=jetty JETTY_ARGS=jetty.http.port=8080 JETTY_RUN=/run/jetty JETTY_SHELL=/bin/bash JETTY_BASE=/opt/jetty/jetty-distribution-9.4.50.v20221201 [root@jetty ~]# }} jettyを起動させます. 目的のwarファイルが「/opt/jetty/jetty-distribution-9.4.50.v20221201/webapps」に置いたので、 「JETTY_BASE」は「/opt/jetty/jetty-distribution-9.4.50.v20221201」になります #code(nonumber){{ [root@jetty ~]# systemctl start jetty }} 「http://jetty:8080」を開くと下記のようになって &ref(2023y02m15d_040355957.png,nolink,80%); その中の「/gitbucket」リンクを押下すると下記になります &red(2023y02m15d_040608527.png,nolink,80%); ***展開場所とurl [#ae0c10e7] いまだとアクセス先で/gitbuketと掘る必要がある. そのサイトに行ったらそこで運用されている形にしたい. 参照: [[http://www.eclipse.org/jetty/documentation/9.3.x/configuring-specific-webapp-deployment.html>+http://www.eclipse.org/jetty/documentation/9.3.x/configuring-specific-webapp-deployment.html]] その場合は「gitbucket.xml」ファイルをwebappsに追加します #code(nonumber){{ [root@jetty ~]# vi /opt/jetty/curt/webapps/gitbucket.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/</Set> <Set name="war">/opt/jetty/jetty-distribution-9.4.50.v20221201/webapps/gitbucket.war</Set> </Configure> [root@jetty ~]# [root@jetty ~]# systemctl restart jetty }} これでサイト名に直下で表示されます &ref(2023y02m15d_041032900.png,nolink);