我的apache+tomcat的整合!

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

我的apache+tomcat的整合!

我的環境實現的主要功能是如果是https就訪問tomcat下面的應用,如果是http,則訪問apache下面的靜態頁面,廢話不多說!
一、下載工具:
apache httpd-2.2.0.tar.gz 下載地址:http://archive.apache.org/dist/httpd/
jdk-1_5_0_05-linux-i586.bin 下載地址:http://java.sun.com/javase/downloads/index.jsp
jakarta-tomcat-connectors-1.2.15-src.tar.gz
下載地址http://archive.apache.org/dist/jakarta/tomcat-connectors/jk/source/
tomcat-5.5.12.tar.gz 下載地址: http://archive.apache.org/dist/jakarta/
二、安裝apache:
1../configure - -prefix=/usr/local/apache
\--enable-so \--enable-ssl \
--with-apr=/usr/local/apr-httpd \
--with-apr-util=/usr/local/apr-util-httpd/
--enable-mods-shared=all
#make
#make install
#make clean
#cd apache/bin
#./apachectl start //可能會提示不能夠綁定127.0.0.1,不過沒有關係,我們在下面會修改的,先看一下是不是服務起來了。
#ps aux
輸入http://192.168.1.5就會出現工作界面。
二、配置tomcat
先安裝jdk
## ./jdk-1_5_0_05-linux-i586.rpm.bin
#root@localhost home]# rpm -ivh jdk-1_5_0_05-linux-i586.rpm
生成目錄:jdk1.5.0_05
在/usr/創建目錄,java
root@host1 jdk1.5.0_05]# ls
bin COPYRIGHT demo include jre ib LICENSE man README.html sample src.zip
# ./java –version
# ./java -version
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)
顯示版本,說明java環境建立成功!//如果不能夠顯示,安裝完tomcat后,重新啟動計算機一切就會正常(哈哈)。
(注意:tomcat5.5的必須有jdk1.5這個版本支持)
安裝tomcat
1.#tar zxvf jakarta-tomcat-5.1.12.tar.gz /home (指定安裝到/home目錄下)
#mv jakarta-tomcat-5.1.12 tomcat (換個文件名)
啟動關閉服務文件放在/home/tomcat/bin
配置文件 /home/tomcat/conf
web文件 /home/tomcat/webapps
默認訪問目錄 /home/tomcat/webapps/ROOT
2.設置環境變數,
在/etc/profile中末尾加入:
export JAVA_HOME=/home/jdk1.5.0_05
export TOMCAT_HOME=/home/tomcat
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
3.啟動與關閉服務:
#cd /home/tomcat/bin
#./startup.sh(關閉服務:#./shutdown.sh)或者是./Catalina.sh start/stop
4.從新啟動計算機,tomcat 就會運行正常,也可以通過jsvc把tomcat載入在啟動服務裡面,建議不要用root來運行tomcat。
五.安裝jakarta-tomcat-connectors-1.2.15-src,生成mod_jk.so文件。

1.安裝jakarta-tomcat-connectors-1.2.15-src.tar.gz
參考文檔:http://www.redflag-linux.com/pho ... redflag/read.php?15,100143
進行安裝,具體過程如下:
root@localhost native]#tar zxvf jakarta-tomcat-connectors-1.2.15-src.tar.gz
生成原文件: jakarta-tomcat-connectors-1.2.15-src
# cd jakarta-tomcat-connectors-1.2.15-src
#
# cd jk
# cd native
root@localhost native]#./configure --with-apxs=/usr/local/apache2/bin/apxs
#make
#make install
#cd apache-2.0/
#ls
mod_jk.so
#cp mod_jk.so /usr/local/apache2/moduels
#cp ../conf/workers.properties /usr/local/apache2/conf
配置httpd.conf 文檔:下面是我自己的配置文檔修改過的地方。
#cd apache/conf
#vi httpd.conf
找到#LoadModule foo_module modules/mod_foo.so加入下面代碼:
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile /usr/local/apache/conf/workers.properties
# Where to put jk logs
JkLogFile /usr/local/apache/logs/mod_jk.log
# Set the jk log level
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
找到# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf ,Include conf/extra/httpd-default.conf,
Include conf/extra/httpd-languages.conf,Include conf/extra/httpd-autoindex.conf取消#號,這個可根據自己情況定(我要啟用ssl)
# cd jakarta-tomcat-connectors-1.2.15-src/jk/conf
# cp  workers.properties /usr/local/apache/conf/
編輯workers.properties文件,修改java和tomcat路徑.
#cd /usr/local/apache2/conf/extra
# vi httpd-ssl.conf
在最後加入:JkMount /* ajp13
# Send JSPs for context /examples to worker named worker1
JkMount /*/*.jsp ajp13 //根據自己tomcat/webapps的應用來舉起配置。
修改虛擬機目錄為:/usr/local/tomcat/webapps
修改有關ssl證書的路徑。
安裝openssl解壓:(注意,openssl的安裝要在apache以前進行),一般系統默認安裝了openssl,就不需要再安裝!
# tar -zxvf openssl-0.9.7j.tar.gz
編譯和安裝
# ./config
# make
# make test
# make install
安裝證書
首先我假定你已經安裝好了openssl和MOD_SSL,如果你的openssl安裝時
的prefix設置為/usr/local/openssl,那麼把/usr/local/openssl/bin加入
執行文件查找路徑。還需要MOD_SSL源代碼中的一個腳本,它在MOD_SSL的
源代碼目錄樹下的pkg.contrib目錄中,文件名為 sign.sh。
將它拷貝到 /usr/local/openssl/bin 中。

先建立一個 CA 的證書,
首先為 CA 創建一個 RSA 私用密鑰,

openssl genrsa -des3 -out ca.key 1024
系統提示輸入 PEM pass phrase,也就是密碼,輸入后牢記它。
生成 ca.key 文件,將文件屬性改為400,並放在安全的地方。

chmod 400 ca.key
你可以用下列命令查看它的內容,

openssl rsa -noout -text -in ca.key
利用 CA 的 RSA 密鑰創建一個自簽署的 CA 證書(X.509結構)

openssl req -new -x509 -days 3650 -key ca.key -out ca.crt
然後需要輸入下列信息:
Country Name: cn 兩個字母的國家代號
State or Province Name: An Hui 省份名稱
Locality Name: Begum 城市名稱
Organization Name: Family Network 公司名稱
Organizational Unit Name: Home 部門名稱
Common Name: Chen Yang 你的姓名
Email Address: sunstorm@263.net Email地址
生成 ca.crt 文件,將文件屬性改為400,並放在安全的地方。

chmod 400 ca.crt
你可以用下列命令查看它的內容,

openssl x509 -noout -text -in ca.crt
下面要創建伺服器證書籤署請求,
首先為你的 Apache 創建一個 RSA 私用密鑰:

openssl genrsa -des3 -out server.key 1024
這裡也要設定pass phrase。
生成 server.key 文件,將文件屬性改為400,並放在安全的地方。

chmod 400 server.key
你可以用下列命令查看它的內容,

openssl rsa -noout -text -in server.key

用 server.key 生成證書籤署請求 CSR.

openssl req -new -key server.key -out server.csr
這裡也要輸入一些信息,和中的內容類似。
至於 'extra' attributes 不用輸入。

你可以查看 CSR 的細節

openssl req -noout -text -in server.csr

openssl x509 -in new.cert.csr -out new.cert.cert -req -signkey new.cert.key -days 1825
就可以得到server.crt。
將文件屬性改為400,並放在安全的地方。

chmod 400 server.crt
刪除CSR

rm server.csr
可以 apachectl startssl 試一下了。
讓apache在啟動時不需輸入RSA私鑰(while preserving the original file):
$ cp server.key server.key.org
$ openssl rsa –in server.key.org –out server.key
確認server.key 文件為root可讀
$ chmod 400 server.key
哈哈,現在就全部工作做完了,這樣就實現了兩個功能,當訪問http://mydemon.com時訪問的是apache/htdocs應用,訪問https://mydemon.com時訪問的是tomcat/webapps下面的應用。
《解決方案》

哈哈,現在就全部工作做完了,這樣就實現了兩個功能,當訪問http://mydemon.com時訪問的是apache/htdocs應用,訪問https://mydemon.com時訪問的是tomcat/webapps下面的應用。

為何兩個不能整合到一起呢?那不是更好啊
《解決方案》

翻貼,學習:mrgreen:
《解決方案》

我有問題!請大家幫忙看下。

我的Apache是安裝系統的時候安裝好的 (rhel 5 apache 2.2.3)
jdk 1.6
tomcat 6.14
tomcat-connectors 1.2.25 源碼包

現在我想把apache和tomcat整合,我查看一些資料,用下面命令安裝,提示錯誤:

# ./configure --with-apxs2=/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 for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for test... /usr/bin/test
checking for rm... /bin/rm
checking for grep... /bin/grep
checking for echo... /bin/echo
checking for sed... /bin/sed
checking for cp... /bin/cp
checking for mkdir... /bin/mkdir
need to check for Perl first, apxs depends on it...
checking for perl... /usr/bin/perl
configure: error: Invalid location for apxs: '/usr/sbin/apxs2'
# ./configure --with-apxs2=/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 for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for test... /usr/bin/test
checking for rm... /bin/rm
checking for grep... /bin/grep
checking for echo... /bin/echo
checking for sed... /bin/sed
checking for cp... /bin/cp
checking for mkdir... /bin/mkdir
no apxs given
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... none
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... (cached) /bin/grep
checking for egrep... /bin/grep -E
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognise dependent libraries... pass_all
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... none
checking how to run the C++ preprocessor... g++ -E
checking for g77... no
checking for f77... no
checking for xlf... no
checking for frt... no
checking for pgf77... no
checking for cf77... no
checking for fort77... no
checking for fl32... no
checking for af77... no
checking for f90... no
checking for xlf90... no
checking for pgf90... no
checking for pghpf... no
checking for epcf90... no
checking for gfortran... no
checking for g95... no
checking for f95... no
checking for fort... no
checking for xlf95... no
checking for ifort... no
checking for ifc... no
checking for efc... no
checking for pgf95... no
checking for lf95... no
checking for ftn... no
checking whether we are using the GNU Fortran 77 compiler... no
checking whether  accepts -g... no
checking the maximum length of command line arguments... 32768
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC
checking if gcc PIC flag -fPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking for shl_load... no
checking for shl_load in -ldld... no
checking for dlopen... no
checking for dlopen in -ldl... yes
checking whether a program can dlopen itself... yes
checking whether a statically linked program can dlopen itself... no
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
configure: creating libtool
appending configuration tag "CXX" to libtool
checking for ld used by g++... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC
checking if g++ PIC flag -fPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
appending configuration tag "F77" to libtool
LIBTOOL="$(SHELL) $(top_builddir)/libtool"
checking for char... yes
checking size of char... 1
checking for int... yes
checking size of int... 4
checking for long... yes
checking size of long... 4
checking for short... yes
checking size of short... 2
checking for long double... yes
checking size of long double... 12
checking for long long... yes
checking size of long long... 8
checking for longlong... no
checking size of longlong... 0
checking size of pid_t... 4
checking for snprintf... yes
checking for vsnprintf... yes
checking for flock... yes
checking for setsockopt in -lsocket... no
checking sys/filio.h usability... no
checking sys/filio.h presence... no
checking for sys/filio.h... no
checking whether to use SO_RCVTIMEO with setsockopt()... yes
checking whether to use SO_SNDTIMEO with setsockopt()... yes
checking for target platform... unix


no apache given
no netscape given
configure: error: Cannot find the WebServer

[ 本帖最後由 daizhongxian 於 2007-12-6 10:29 編輯 ]
《解決方案》

使用命令  ./configure --with-apxs=/usr/local/apache2/bin/apxs  就不會出錯了,而不是 --with-apxs2.
《解決方案》

還可以,就是整理的時候有些亂。。。。




[火星人 ] 我的apache+tomcat的整合!已經有387次圍觀

http://coctec.com/docs/service/show-post-31330.html