| Linuxコマンド |
| 用語集 |
| debian メモ |
| apache2 メモ |
| MySQL メモ |
| Oracle メモ |
| PostgreSQL |
| HOME |
Linux 環境で、apache + tomcat の連携をできるようにしたい。 mod_jk というモジュールを使ったことがありますが、Linux でも同じでしょうか。
◆環境| OS | Linux 2.6.18-92.el5 |
|---|
まずは、mod_jkをダウンロードします。
tomcat-connectors-1.2.23-src.tar.gz というファイルをダウンロードしました。 ftp でサーバーに送って解凍します。
tomcat-connectors-1.2.23-src/
tomcat-connectors-1.2.23-src/KEYS
tomcat-connectors-1.2.23-src/LICENSE
tomcat-connectors-1.2.23-src/NOTICE
tomcat-connectors-1.2.23-src/BUILD.txt
:
# ll
合計 92
-rw-r--r-- 1 root bin 647 2月 3 2007 BUILD.txt
-rw-r--r-- 1 root bin 41514 3月 1 2007 KEYS
-rw-r--r-- 1 root bin 11358 2月 24 2004 LICENSE
-rw-r--r-- 1 root bin 101 2月 28 2004 NOTICE
drwxr-xr-x 2 root bin 4096 5月 18 2007 conf
drwxr-xr-x 10 root bin 4096 5月 18 2007 docs
drwxr-xr-x 6 root bin 4096 5月 18 2007 jkstatus
drwxr-xr-x 11 root bin 4096 5月 18 2007 native
drwxr-xr-x 2 root bin 4096 5月 18 2007 support
drwxr-xr-x 3 root bin 4096 5月 18 2007 tools
drwxr-xr-x 9 root bin 4096 5月 18 2007 xdocs
フォルダがいっぱいできました。
BUILD.txt というファイルがあるので中を見てみます。
Tomcat. Only the web server connector source is included. The Tomcat
side of the connector is available with the normal Tomcat distributio
n.Documentation for how to build mod_jk 1.2 from source and configure
it for your webserver is located in the native/BUILDING file in this
source distribution.
For the impatient Apache admins:
$> cd native
$> ./configure --with-apxs=/usr/sbin/apxs (or where ever the apxs/apx
s2 is)$> make
$> su -c 'make install'
For the impatient SunONE admins:
$> cd native
$> ./configure --enable-netscape
$> cd netscape
$> make -f Makefile.solaris
これに従ってやればよさそうです。
# ./configure --with-apxs=/usr/sbin/apxs
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
:
checking whether to use SO_RCVTIMEO with setsockopt()... yes
checking whether to use SO_SNDTIMEO with setsockopt()... yes
need to check for Perl first, apxs depends on it...
checking for perl... /usr/bin/perl
configure: error: Invalid location for apxs: '/usr/sbin/apxs'
エラーがでました。 /usr/sbin/apxs がないというメッセージが表示されています。 確認してみます。
ls: /usr/sbin/apxs: そのようなファイルやディレクトリはありません
確かに無いようです。 探してみます。
#
見つかりませんでした。 apxs で検索したところ以下の記載をみつけました。
更に調べると、apxs は「apache-devel - Development tools for the Apache Web server」というパッケージに含まれることが分かりました。 apache-devel がインストールされているかどうかの確認方法ものっていたので試してみます。
#
インストールされていないようです。
httpd-devel-2.2.3-11.el5_1.centos.3.x86_64.rpm というファイルをダウンロードしたので、インストールしてみます。
Setting up Install Process
Parsing package install arguments
Examining httpd-devel-2.2.3-11.el5_1.centos.3.x86_64.rpm: httpd-devel
- 2.2.3-11.el5_1.centos.3.x86_64Marking httpd-devel-2.2.3-11.el5_1.centos.3.x86_64.rpm to be installe
dResolving Dependencies
--> Running transaction check
---> Package httpd-devel.x86_64 0:2.2.3-11.el5_1.centos.3 set to be u
pdated--> Processing Dependency: apr-devel for package: httpd-devel
--> Processing Dependency: apr-util-devel for package: httpd-devel
--> Running transaction check
---> Package apr-devel.i386 0:1.2.7-11 set to be updated
---> Package apr-util-devel.i386 0:1.2.7-7.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================
========Package Arch Version Repository
Size=====================================================================
========Installing:
httpd-devel x86_64 2.2.3-11.el5_1.centos.3 httpd-de
vel-2.2.3-11.el5_1.centos.3.x86_64.rpm 512 kInstalling for dependencies:
apr-devel i386 1.2.7-11 base
237 kapr-util-devel i386 1.2.7-7.el5 base
54 kTransaction Summary
=====================================================================
========Install 3 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 803 k
Is this ok [y/N]:
「y」と入力しEnterを押します。
(1/2): apr-util-devel-1.2 100% |=========================| 54 kB
00:00(2/2): apr-devel-1.2.7-11 100% |=========================| 237 kB
00:00warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8
562897Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing
Key) <centos-5-key@centos.org>" from http://mirror.centos.org/cent
os/RPM-GPG-KEY-CentOS-5Is this ok [y/N]:
また選択肢が表示されたので「y」と入力しEnterを押します。
Running Transaction Test
Finished Transaction Test
Transaction Check Error:
package httpd-devel-2.2.3-11.el5_1.centos.3 is intended for a x86_6
4 architectureError Summary
-------------
エラーがでました。
パッケージ「httpd-devel-2.2.3-11.el5_1.centos.3」は x86_64 アーキテクチャでないといけないようです。
uname でハードウェア情報を確認します。
i686
ちゃんとインストールできたマシンを見てみます。
x86_64
インストールしようとした「httpd-devel」は x86_64 用だったようです。 今回インストールしようとしたマシンは i686 用でないとインストールできない模様です。 「apxs i686」で検索してみましたがみつかりませんでした。
「rpm httpd-devel」で検索したところダウンロードできそうなページを見つけました。
httpd-devel-2.2.8-3.i386.rpm というファイルをダウンロードしてインストールしてみます。
Setting up Install Process
Parsing package install arguments
Examining httpd-devel-2.2.8-3.i386.rpm: httpd-devel - 2.2.8-3.i386
Marking httpd-devel-2.2.8-3.i386.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package httpd-devel.i386 0:2.2.8-3 set to be updated
--> Processing Dependency: apr-devel for package: httpd-devel
--> Processing Dependency: apr-util-devel for package: httpd-devel
--> Processing Dependency: httpd = 2.2.8-3 for package: httpd-devel
--> Running transaction check
---> Package httpd-devel.i386 0:2.2.8-3 set to be updated
--> Processing Dependency: httpd = 2.2.8-3 for package: httpd-devel
---> Package apr-devel.i386 0:1.2.7-11 set to be updated
---> Package apr-util-devel.i386 0:1.2.7-7.el5 set to be updated
--> Finished Dependency Resolution
Error: Missing Dependency: httpd = 2.2.8-3 is needed by package httpd
-develエラーがでました。 依存エラー:httpd = 2.2.8-3 は httpd-devel パッケージが必要なのでしょうか。
調べてたら、httpd-devel だけでインストールしているのをみかけましたのでやってみます。
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package httpd-devel.i386 0:2.2.3-22.el5.centos set to be updated
--> Processing Dependency: apr-util-devel for package: httpd-devel
--> Processing Dependency: apr-devel for package: httpd-devel
--> Processing Dependency: httpd = 2.2.3-22.el5.centos for package: h
ttpd-devel--> Running transaction check
---> Package apr-devel.i386 0:1.2.7-11 set to be updated
---> Package httpd.i386 0:2.2.3-22.el5.centos set to be updated
---> Package apr-util-devel.i386 0:1.2.7-7.el5 set to be updated
--> Processing Dependency: httpd = 2.2.3-11.el5_1.centos.3 for packag
e: mod_ssl--> Running transaction check
---> Package mod_ssl.i386 1:2.2.3-22.el5.centos set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================
========Package Arch Version Repository
Size=====================================================================
========Installing:
httpd-devel i386 2.2.3-22.el5.centos base
145 kUpdating:
httpd i386 2.2.3-22.el5.centos base
1.2 MInstalling for dependencies:
apr-devel i386 1.2.7-11 base
237 kapr-util-devel i386 1.2.7-7.el5 base
54 kUpdating for dependencies:
mod_ssl i386 1:2.2.3-22.el5.centos base
87 kTransaction Summary
=====================================================================
========Install 3 Package(s)
Update 2 Package(s)
Remove 0 Package(s)
Total download size: 1.7 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): httpd-2.2.3-22.el5 100% |=========================| 1.2 MB
00:00(2/3): mod_ssl-2.2.3-22.e 100% |=========================| 87 kB
00:00(3/3): httpd-devel-2.2.3- 100% |=========================| 145 kB
00:00Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : httpd #########################
[1/7]Installing: apr-devel #########################
[2/7]Installing: apr-util-devel #########################
[3/7]Installing: httpd-devel #########################
[4/7]Updating : mod_ssl #########################
[5/7]Cleanup : mod_ssl #########################
[6/7]Cleanup : httpd #########################
[7/7]Installed: httpd-devel.i386 0:2.2.3-22.el5.centos
Dependency Installed: apr-devel.i386 0:1.2.7-11 apr-util-devel.i386 0
:1.2.7-7.el5Updated: httpd.i386 0:2.2.3-22.el5.centos
Dependency Updated: mod_ssl.i386 1:2.2.3-22.el5.centos
Complete!
無事インストールできました! 「/usr/sbin/apxs」にちゃんとファイルができています!
もう一度、tomcat-connector のインストールを再開します。
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
:
config.status: creating common/list.mk
config.status: creating common/jk_types.h
config.status: creating jni/Makefile
config.status: creating common/portable.h
config.status: executing depfiles commands
特にエラーはでていないようなので、makeします!
Making all in common
:
インストールします。
5分ぐらいかかりましたが、特にエラーはでませんでした。
# apxs -n jk -i mod_jk.so
/usr/lib/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib/apr-1/build/libt
ool' mod_jk.so /usr/lib/httpd/modules/usr/lib/apr-1/build/libtool --mode=install cp mod_jk.so /usr/lib/htt
pd/modules/cp mod_jk.so /usr/lib/httpd/modules/mod_jk.so
Warning! dlname not found in /usr/lib/httpd/modules/mod_jk.so.
Assuming installing a .so rather than a libtool archive.
chmod 755 /usr/lib/httpd/modules/mod_jk.so
Warning がでていますがインストールを進めます。
続いて mod_jk.conf を作成します。
| mod_jk.conf /etc/httpd/conf.d | ||
|
| workers.properties /etc/httpd/conf | ||
|
| reqmap /etc/httpd/conf | ||
|
続いて Java を導入します。
jre-6u2-linux-i586.bin というファイルをダウンロードして実行します。
-bash: ./jre-6u2-linux-i586.bin: 許可がありません
chmod で権限を付与して再度実行します。
# ./jre-6u2-linux-i586.bin
Sun Microsystems, Inc. Binary Code License Agreement
for the JAVA SE RUNTIME ENVIRONMENT (JRE) VERSION 6
SUN MICROSYSTEMS, INC. ("SUN") IS WILLING TO LICENSE THE
:
Do you agree to the above license terms? [yes or no]
yesと入力しEnterを押します。
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.ed
u).creating: jre1.6.0_02/
creating: jre1.6.0_02/bin/
:
できたフォルダを丸ごと、/usr/local へコピーしてリンクを作成します。
# cd /usr/local/
# ln -s /usr/local/jre1.6.0_02/ java
続いて Tomcat を導入します。
apache-tomcat-5.5.23.tar.tar ファイルを解凍します。
apache-tomcat-5.5.23/bin/catalina.sh
apache-tomcat-5.5.23/bin/digest.sh
apache-tomcat-5.5.23/bin/setclasspath.sh
apache-tomcat-5.5.23/bin/shutdown.sh
apache-tomcat-5.5.23/bin/startup.sh
:
/usr/local にフォルダを移動しリンクを作成します。
# ln -s /usr/local/apache-tomcat-5.5.23/ tomcat
環境設定シェルを作成します。
| setenv.sh /usr/local/tomcat/bin | ||
|
tomcat 起動・停止シェルを作成します。
| tomcat /etc/init.d | ||
|
URL にアクセスしましたが、apache のページが表示されました。 ポート 8080 を指定すると tomcat のページが表示されるので、mod_jk が正しく起動していないようです。
httpd.conf に mod_jk の記入をしなければならないようです。
LoadModule jk_module modules/mod_jk.so
# mod_jkの設定ファイルを指定
<IfModule mod_jk.c>
Include conf.d/mod_jk.conf
</IfModule>
apacheを再起動します。
httpd を停止中: [ OK ]
# /etc/init.d/httpd start
httpd を起動中: [Thu May 14 14:44:59 2009] [warn] module jk_module is
already loaded, skipping[Thu May 14 14:44:59 2009] [warn] module jk_module is already loaded,
skippinghttpd: Could not reliably determine the server's fully qualified doma
in name, using 127.0.0.1 for ServerName[失敗]
jk_module は既に読み込まれているのでスキップしたようなメッセージが表示されました。
エラーは翻訳したところ「ServerNameに"127.0.0.1"を使用して、サーバの完全修飾ドメイン名を確かに決定できませんでした。」ということでした。
警告は、恐らく httpd.conf に jk_module のロードが2行あるのだと思います。
エラーは、worker.properties の記述が間違っているようです。
現時点では「ymlibrealprep」サーバーは無いので、これを「ymlibrealweb」に修正したら正常起動しました。 でも tomcat にはフォワードされていないようです。
調べたところ、tomcat 自体に webサーバーの機能があるので、その機能を止めないとダメみたいです。
次の行をコメントアウトしてみます。
maxThreads="150" minSpareThreads="25" maxSpareThreads=
"75"enableLookups="false" redirectPort="8443" acceptCount=
"100"connectionTimeout="20000" disableUploadTimeout="true"
/>コメントアウトしましたが特に変化はありませんでしたので元に戻します。
他のページを参考に、workers.properties を書き換えてみました。
| workers.properties /etc/httpd/conf | ||
|
これに伴い、JkMountFile で指定している、reqmap も修正します。
| reqmap /etc/httpd/conf | ||
|
以下のパターンでURLにアクセスしてみましたが上手くいきませんでした。
| URL | 結果 |
|---|---|
| http://192.168.1.1/ | apache のページが開く |
| http://192.168.1.1/servlet | ページが見つかりません。 |
| http://192.168.1.1/servlet/ | HTTP Status 404 - /servlet/ |
| http://192.168.1.1:8009/ | ページを表示できません。 |
| http://192.168.1.1:8009/servlet | ページを表示できません。 |
| http://192.168.1.1:8009/servlet/ | ページを表示できません。 |
| http://192.168.1.1:8080/ | tomcat のページが開く |
「HTTP Status 404」になったURLが気になります。 もしかすると、tomcat の設定が間違っているからかもしれません。
apache、tomcat のログを見ていたら、8009 にアクセスしたときにtomcatのログが更新されていました。
| URL | 結果 |
|---|---|
| http://192.168.1.1/ | apache の error.log に「Directory index forbidden by Options directive: /var/www/html/」が出た。 |
| http://192.168.1.1/servlet | apache の error.log に「File does not exist: /var/www/html/servlet」が出た。 |
| http://192.168.1.1/servlet/ | apache access.log 更新。 |
| http://192.168.1.1:8009/ | tomcat の catalina.out に以下のエラーが出た。 |
| http://192.168.1.1:8009/servlet | tomcat の catalina.out に以下のエラーが出た。 |
| http://192.168.1.1:8009/servlet/ | tomcat の catalina.out に以下のエラーが出た。 |
| http://192.168.1.1:8080/ | tomcat のページが開く |
エラーは以下になります。
SEVERE: BAD packet signature 18245
May 14, 2009 4:36:43 PM org.apache.jk.common.ChannelSocket processCon
nectionSEVERE: Error, processing connection
java.lang.IndexOutOfBoundsException
at java.io.BufferedInputStream.read(Unknown Source)
at org.apache.jk.common.ChannelSocket.read(ChannelSocket.java
:626)at org.apache.jk.common.ChannelSocket.receive(ChannelSocket.j
ava:583)at org.apache.jk.common.ChannelSocket.processConnection(Chann
elSocket.java:691)at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(
ChannelSocket.java:895)at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.
run(ThreadPool.java:685)at java.lang.Thread.run(Unknown Source)
状況から考えると、ポート 8009 にアクセスすると tomcat にフォワードされているようです。 フォワードというより、tomcat が子プロセス(=ワーカー?)として生成され 8009 ポート待ちになっている感じがします。
ということは、tomcat が 8009 ポートを受け付けていれば大丈夫なはず。 server.xml を見てみます。
<Connector port="8009"
enableLookups="false" redirectPort="8443" protocol="AJ
P/1.3" />よく分からないですが、見た感じではポート 8009 へのアクセスをポート 8443 へリダイレクトしているように見えます。 以下のように書き換えて再度テストします。
port="8009" minProcessors="5" maxProcessors="75"
acceptCount="10" debug="0"/>
上手く動作しました!結果は以下の通りです。
| URL | 結果 |
|---|---|
| http://192.168.1.1/ | apache のページが開く |
| http://192.168.1.1/servlet | ページが見つかりません。 |
| http://192.168.1.1/servlet/ | 応答が返って来ない。 |
| http://192.168.1.1:8009/ | tomcat のページが表示される。 |
| http://192.168.1.1:8009/servlet | HTTP Status 404 - /servlet |
| http://192.168.1.1:8009/servlet/ | HTTP Status 404 - /servlet/ |
| http://192.168.1.1:8080/ | tomcat のページが開く |
ポート 8009 へのアクセスで tomcat のページが表示されました。 ということは、apache -> mod_jk -> tomcat の連携は上手く行っていると判断できます。
servlet へのアクセスができないのはなぜでしょうか。 JkMountFile の設定が効いていないのでしょうか。
応答が返ってこないのをずっと待ってたらこんなエラーがでました。
The server is temporarily unable to service your request due to maint
enance downtime or capacity problems. Please try again later.---------------------------------------------------------------------
-----------Apache/2.2.3 (CentOS) Server at 192.168.1.1 Port 80
Copyright (C) 2009 - 2025 ymlib.com
