會員註冊 / 登入  |  電腦版  |  Jump to bottom of page

Application Server » Tomcat Connector更新至1.2.40後之設定修正

發表人: andowson, 七段學員
2014-04-20 15:29:47
今天將Tomcat Connector利用自動更新程式tomcat-connector.sh(如下)進行更新:

#!/bin/bash
# Name: Apache 2.2.x && Tomcat 7.0.x auto installer for CentOS 6.x
# Author: Andowson Chang (andowson [at] gmail [dot] com)
# Version: 5.16
# Last Modified: 2014-04-20
# Source: http://www.andowson.com
#
TOMCAT_CONNECTOR_VERSION=1.2.40

MIRROR_HOST=apache.stu.edu.tw
SETUP_DIR=/root/setup/web
INTERNET_CONNECTED=1

#
# install dependency packages
#
LIBTOOL_INSTALLED=`rpm -qa|grep libtool|wc -l`
HTTPD_DEVEL_INSTALLED=`rpm -qa|grep httpd-devel|wc -l`
AUTOMAKE_INSTALLED=`rpm -qa|grep automake|wc -l`
if [ ${LIBTOOL_INSTALLED} = 0 ] || [ ${HTTPD_DEVEL_INSTALLED} = 0 ] || [ ${AUTOMAKE_INSTALLED} = 0 ]; then
yum -y install libtool httpd-devel automake
fi

#
# create the setup directory
#
if [ ! -d ${SETUP_DIR} ]; then
mkdir -p ${SETUP_DIR}
fi
cd ${SETUP_DIR}

#
# get latest version
#
wget http://tomcat.apache.org/download-connectors.cgi -q -t 1 -T 5 -O /tmp/connector.html
if [ -s /tmp/connector.html ]; then
TOMCAT_CONNECTOR_VERSION=`grep "1\.2\." /tmp/connector.html|cut -d">" -f2|cut -d"<" -f1 |awk '{print $2}'|grep "1.2"|uniq`
else
echo "Cannot connect to the Internet. Try using local file instead."
INTERNET_CONNECTED=0
fi
rm -rf /tmp/connector.html
if [ ! -r tomcat-connectors-${TOMCAT_CONNECTOR_VERSION}-src.tar.gz ]; then
if [ $INTERNET_CONNECTED -eq 1 ]; then
wget http://${MIRROR_HOST}/tomcat/tomcat-connectors/jk/tomcat-connectors-${TOMCAT_CONNECTOR_VERSION}-src.tar.gz
else
echo "File not found: tomcat-connectors-${TOMCAT_CONNECTOR_VERSION}-src.tar.gz, aborted!"
exit 1
fi
fi

#
# install tomcat connector
#
echo "Install Tomcat Connector JK ${TOMCAT_CONNECTOR_VERSION}"
tar zxvf tomcat-connectors-${TOMCAT_CONNECTOR_VERSION}-src.tar.gz
cd tomcat-connectors-${TOMCAT_CONNECTOR_VERSION}-src/native
./buildconf.sh
./configure --with-apxs=/usr/sbin/apxs
make
make install
cd ${SETUP_DIR}


完成更新後,重啟Apache,再去開網頁卻無法順利開啟網頁,查了一下mod_jk.log:
[Sun Apr 20 13:30:34 2014][15480:139841517975520] [info] init_jk::mod_jk.c (3383): mod_jk/1.2.40 initialized

[Sun Apr 20 13:30:34 2014][15482:139841517975520] [info] init_jk::mod_jk.c (3383): mod_jk/1.2.40 initialized
[Sun Apr 20 13:30:39 2014][15492:139841517975520] [info] jk_open_socket::jk_connect.c (758): connect to ::1:8109 failed (errno=111)
[Sun Apr 20 13:30:39 2014][15492:139841517975520] [info] ajp_connect_to_endpoint::jk_ajp_common.c (1019): Failed opening socket to (::1:8109) (errno=111)
[Sun Apr 20 13:30:39 2014][15492:139841517975520] [error] ajp_send_request::jk_ajp_common.c (1663): (worker1) connecting to backend failed. Tomcat is probably not started or is listening on the wrong port (errno=111)
[Sun Apr 20 13:30:39 2014][15492:139841517975520] [info] ajp_service::jk_ajp_common.c (2673): (worker1) sending request to tomcat failed (recoverable), because of error during request sending (attempt=1)


發現無法連到::1:8109(這是IPv6的locahost IP表示方法)
在查了一下Tomcat的Changelog網頁
Add IPV6 support for connection to webserver. New directive prefer_ipv6 has been added to control the hostname resolution and preserve backward compatibility. (mturk)

感覺應該是預設用IPv6在抓IP,由於我不知道怎麼調整這個預設模式,故我採用修改workers.properties
將這兩行設定的localhost
worker.worker1.host=localhost

worker.worker2.host=localhost

改為127.0.0.1
worker.worker1.host=127.0.0.1

worker.worker2.host=127.0.0.1

再重啟一次Apache,就可以順利連到Tomcat了。

檔案名稱 tomcat-connector.sh
描述 Tomcat Connector auto update script
檔案大小 2 Kbytes
下載次數 2 次
[Disk] 下載





會員註冊 / 登入  |  電腦版  |  Jump to top of page