码迷,mamicode.com
首页 > Web开发 > 详细

apache_tomcat整合应用

时间:2016-04-19 00:34:48      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:mysql   用户 tomcat   

清除以前编译产生的目标文件 .o的文件清除以前编译产生的目标文件 .o的文件一、创建apache mysql用户 安装启动apache mysql
[root@node1 ~]# netstat -tnlp |grep 80      
tcp        0      0 :::80                       :::*                        LISTEN      1960/httpd
二、单独使用Tomcat(Mysql)
[root@node1 jsp]# rpm -qa |grep java
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
[root@node1 jsp]# rpm -e --nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
[root@node1 jsp]# rpm -e --nodeps java-1.6.0-openjdk-devel-1.6.0.0-1.24.1.10.4.el5
[root@node1 jsp]# rpm -e java-1.6.0-openjdk-1.6.0.0-1.24.1.10.4.el5
[root@node1 jsp]# java -version

-bash: /usr/bin/java: 没有那个文件或目录
安装JDK
[root@node1 jsp]# rpm -ivh jdk-7u11-linux-i586.rpm
[root@node1 jsp]# java -version

java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) Client VM (build 23.6-b04, mixed mode, sharing)

[root@node1 jsp]# ls /usr/java/jdk1.7.0_11
[root@node1 jsp]# vim /etc/profile            

JAVA_HOME=/usr/java/jdk1.7.0_11
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME PATH

[root@node1 jsp]# source /etc/profile  等于命令 . /etc/profile
[root@node1 jsp]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/jdk1.7.0_11/bin
安装Tomcat
[root@node1 jsp]# tar xvf apache-tomcat-7.0.34.tar.gz -C /usr/local/
[root@node1 jsp]# cd /usr/local/
[root@node1 local]# ln -sv apache-tomcat-7.0.34 tomcat

创建指向“apache-tomcat-7.0.34”的符号链接“tomcat”

定义Tomcat环境变量
[root@node1 local]# vim /etc/profile

CATALINA_HOME=/usr/local/tomcat
export CATALINA_HOME

[root@node1 local]# source /etc/profile
[root@node1 local]# env |grep HOME

CATALINA_HOME=/usr/local/tomcat
JAVA_HOME=/usr/java/jdk1.7.0_11
HOME=/root

[root@node1 local]# /usr/local/tomcat/bin/catalina.sh start    启动服务
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/jdk1.7.0_11
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

[root@node1 ~]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address         Foreign Address         State       PID/Program name

tcp        0      0 ::ffff:127.0.0.1:8005       :::*                        LISTEN      2920/java          
tcp        0      0 :::8009                     :::*                        LISTEN      2920/java          
tcp        0      0 :::8080                     :::*                        LISTEN      2920/java          
tcp        0      0 :::80                       :::*                        LISTEN      2135/httpd          
======================================
System V脚本   可选项
#[root@node1 ~]# vim /etc/init.d/tomcat
#!/bin/bash
# Init file for Tomcat server daemon
#
# chkconfig: 2345 96 14
# description: Tomcat server daemon
JAVA_OPTS=‘-Xms64m -Xmx128m‘
JAVA_HOME=/usr/java/jdk1.7.0_11
CATALINA_HOME=/usr/local/tomcat
export JAVA_OPTS JAVA_HOME CATALINA_HOME
exec $CATALINA_HOME/bin/catalina.sh $*

[root@node1 ~]# chmod a+x /etc/init.d/tomcat
[root@node1 ~]# chkconfig tomcat --list

tomcat 服务支持 chkconfig,但它在任何级别中都没有被引用(运行“chkconfig --add tomcat”)
[root@node1 ~]# chkconfig --add tomcat
[root@node1 ~]# chkconfig tomcat --list

tomcat          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
[root@node1 ~]# chkconfig tomcat on
[root@node1 ~]# service tomcat stop

Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/jdk1.7.0_11
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

[root@node1 ~]# service tomcat start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/jdk1.7.0_11
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

======================================
测试:
http://192.168.2.251:8080/
安装 tomcat-native
[root@node1 ~]# yum groupinstall -y "Development tools" "Development libraries"
[root@node1 ~]# yum -y install openssl-devel apr-devel
[root@node1 jsp]# cd /usr/local/tomcat/bin/
[root@node1 bin]# ls

bootstrap.jar       commons-daemon-native.tar.gz  digest.bat        shutdown.sh           tool-wrapper.bat
catalina.bat        configtest.bat                digest.sh         startup.bat           tool-wrapper.sh
catalina.sh         configtest.sh                 setclasspath.bat  startup.sh            version.bat
catalina-tasks.xml  cpappend.bat                  setclasspath.sh   tomcat-juli.jar       version.sh
commons-daemon.jar  daemon.sh                     shutdown.bat      tomcat-native.tar.gz

[root@node1 bin]# tar xf tomcat-native.tar.gz    
[root@node1 bin]# cd tomcat-native-1.1.24-src/jni/native/
[root@node1 native]# ls

build       build-outputs.mk  include          NMAKEmakefile      srclib
buildconf   config.layout     libtcnative.dsp  NMAKEmakefile.inc  tcnative.dsp
build.conf  configure         libtcnative.dsw  os                 tcnative.pc.in
BUILDING    configure.in      Makefile.in      src                tcnative.spec

报错:
checking for APR... configure: error: the --with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file.
解决方案,安装:yum install apr-devel
[root@node1 native]# ./configure --with-apr=/usr/ --with-ssl --with-java-home=/usr/java/jdk1.7.0_11/
[root@node1 native]# make && make install

[root@node1 native]# echo "/usr/local/apr/lib" > /etc/ld.so.conf.d/apr.conf
重新加载库文件
[root@node1 native]# ldconfig
======================================
为查看Tomcat运行状态添加用户:
Tomcat配置文件
/usr/local/tomcat/conf/server.xml  
[root@node1 ~]# vim /usr/local/tomcat/conf/tomcat-users.xml

<role rolename="manager-gui"/>
<role rolename="manager-scripts"/>
<role rolename="manager-status"/>
<user username="tomcat" password="123456" roles="manager-gui,manager-scripts,manager-status,admin-gui"/>

[root@node1 ~]# service tomcat stop
[root@node1 ~]# service tomcat start
=========================================
为Tomcat提供连接Mysql的文件

[root@node1 jsp]# tar xf mysql-connector-java-5.0.8.tar.gz
[root@node1 jsp]# cd mysql-connector-java-5.0.8
[root@node1 mysql-connector-java-5.0.8]# ls

build.xml  COPYING  docs                    mysql-connector-java-5.0.8-bin.jar  README.txt
CHANGES    debug    EXCEPTIONS-CONNECTOR-J  README                              src

[root@node1 mysql-connector-java-5.0.8]# cp mysql-connector-java-5.0.8-bin.jar /usr/local/tomcat/lib/
[root@node1 ~]# service tomcat stop
[root@node1 ~]# service tomcat start

配置Tomcat虚拟主机:JavaCenter_Home
[root@node1 jsp]# ls /usr/local/tomcat/webapps/        
docs  examples  host-manager  manager  ROOT
默认网站的主目录
[root@node1 jsp]# ls /usr/local/tomcat/webapps/ROOT  

asf-logo.png       bg-nav-item.png  favicon.ico        tomcat.gif        WEB-INF
asf-logo-wide.gif  bg-nav.png       index.jsp          tomcat.png
bg-button.png      bg-upper.png     RELEASE-NOTES.txt  tomcat-power.gif
bg-middle.png      build.xml        tomcat.css         tomcat.svg

[root@node1 jsp]#
为新网站建立主目录
[root@node1 jsp]# mkdir /usr/local/tomcat/webapps/blog
tomcat主配置文件
[root@node1 jsp]# vim /usr/local/tomcat/conf/server.xml

      <Host name="www.blog.com"  appBase="webapps" unpackWARs="true" autoDeploy="true">
           <Context docBase="blog" path="" />
      </Host>

安装JSP网站
[root@node1 jsp]# unzip JavaCenter_Home_2.0_Source_UTF8.zip
[root@node1 jsp]# cd JavaCenter_Home_2.0_Source_UTF8/source/WebRoot/
[root@node1 WebRoot]# ls

admin        avatar.jsp         data         help.jsp    js.jsp       rss.jsp    userapp.jsp
admincp.jsp  config.properties  do.jsp       image       link.jsp     source     WEB-INF
api          contact.jsp        editor.jsp   index.jsp   magic.jsp    space.jsp  xmlrpc.jsp
app.jsp      cp.jsp             errors       install     META-INF     template
attachment   crossdomain.xml    favicon.ico  invite.jsp  network.jsp  theme

[root@node1 WebRoot]#
[root@node1 WebRoot]# cp -rf * /usr/local/tomcat/webapps/blog/

[root@node1 ~]# service tomcat stop
[root@node1 ~]# service tomcat start

是否支持连接数据库
http://www.blog.com:8080
安装测试网站      
http://www.blog.com:8080/install
三、整合Apache、Tomcat
确定建立了两个虚拟机:
www.126.com        /webroot1/126 默认网站目录        PHP
www.blog.com        /usr/local/tomcat/webapps/blog/    JSP(Tomcat:8080)
[root@node1 ~]# mkdir /webroot
[root@node1 ~]# mkdir /webroot/126
[root@node1 ~]# echo "welcome to 126" > /webroot/126/index.html
[root@node1 ~]#  vim /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
    DocumentRoot "/webroot/126"
    ServerName
www.126.com
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "/usr/local/tomcat/webapps/blog/"
    ServerName
www.blog.com
</VirtualHost>
<Directory "/webroot/126">
        Require all granted
</Directory>
<Directory "/usr/local/tomcat/webapps/blog/">
        Require all granted
</Directory>

[root@node1 ~]# service httpd restart
必须确保两个网站都能访问,此时JSP网只能访问到
整合
[root@node1 jsp]# tar xvf  tomcat-connectors-1.2.31-src.tar.gz
[root@node1 jsp]# cd tomcat-connectors-1.2.31-src/native/
[root@node1 native]# ls

aclocal.m4  buildconf.sh  common        docs  Makefile.am  NEWS        scripts
apache-1.3  BUILDING.txt  configure     iis   Makefile.in  nt_service  STATUS.txt
apache-2.0  CHANGES       configure.in  jni   netscape     README.txt  TODO.txt

[root@node1 native]# chmod 755 buildconf.sh
[root@node1 native]# ./buildconf.sh
======================================
[root@station252 ~]# which apxs
/usr/sbin/apxs
[root@station252 ~]#
[root@station252 ~]# rpm -qf /usr/sbin/apxs
httpd-devel-2.2.3-63.el5
场景一:RPM包关联Apache
[root@node1 native]# ./configure --with-apxs=/usr/sbin/apxs
场景二:源码包关联Apache
[root@node1 native]# ./configure --with-apxs=/usr/local/apache2/bin/apxs
[root@node1 native]# make && make install
======================================

编译时产生错误及解决方案
[root@node1 native]# make
Making all in common
make[1]: Entering directory `/root/jsp/tomcat-connectors-1.2.31-src/native/common‘
make[1]: Nothing to be done for `all‘.
make[1]: Leaving directory `/root/jsp/tomcat-connectors-1.2.31-src/native/common‘
Making all in apache-2.0
make[1]: Entering directory `/root/jsp/tomcat-connectors-1.2.31-src/native/apache-2.0‘

/usr/local/apache2/build/libtool --silent --mode=compile gcc -std=gnu99 -I/usr/local/apache2/include  -DHAVE_CONFIG_H -DUSE_APACHE_MD5 -I ../common -I /usr/java/jdk1.7.0_11/include -I /usr/java/jdk1.7.0_11/include/unix -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -g -O2 -pthread -DHAVE_APR  -I/usr/local/apache2/include -I/usr/local/apache2/include  -DHAVE_CONFIG_H -g -O2 -pthread -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -c mod_jk.c -o mod_jk.lo
mod_jk.c: In function ‘init_ws_service‘:
mod_jk.c:735: error: ‘conn_rec‘ has no member named ‘remote_ip‘
mod_jk.c:999: error: ‘conn_rec‘ has no member named ‘remote_ip‘
mod_jk.c:999: error: ‘conn_rec‘ has no member named ‘remote_ip‘
make[1]: *** [mod_jk.lo] 错误 1
make[1]: Leaving directory `/root/jsp/tomcat-connectors-1.2.31-src/native/apache-2.0‘
make: *** [all-recursive] 错误 1
解决方法:
[root@node1 native]# vim apache-2.0/mod_jk.c
735:

改之前
s->remote_addr = r->connection->remote_ip;    

改之后    
s->remote_addr = r->connection->client_ip;
999

改之前    
STRNULL_FOR_NULL(r->connection->remote_ip),

改之后
STRNULL_FOR_NULL(r->connection->client_ip),

重新编译:
[root@node1 native]# ./configure --with-apxs=/usr/local/apache2/bin/apxs
清除以前编译产生的目标文件.o的文件
[root@node1 native]# make clean

[root@node1 native]# make && make install
======================================
[root@node1 native]# ls /etc/httpd/modules/mod_jk.so
/etc/httpd/modules/mod_jk.so

正式开始整合。。。
==== vim /etc/httpd/conf/httpd.conf=====
DirectoryIndex index.html index.jsp
LoadModule jk_module modules/mod_jk.so    加载mod_jk.so
jkWorkersFile conf.d/workers.properties
jkLogFile logs/mod_jk.log
jkLogLevel info

修改:vim /etc/httpd/conf.d/workers.properties
ps=/
worker.list=tomcat1,tomcat2,loadbalancer
worker.tomcat1.port=8080
worker.tomcat1.host=127.0.0.1
workes.tomcat1.type=ajp13
worker.tomcat1.lbfactor=100

修改vim /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/tomcat/webapps/blog/"
    ServerName
www.blog.com
    jkmount /*.jsp loadbalancer
    jkmount /servlet/* loadbalancer
    jkmount /application/* loadbalancer

</VirtualHost>
重启服务测试
service httpd restart
service tomcat stop
service tomcat start


本文出自 “小郑技术博客” 博客,请务必保留此出处http://ko178.blog.51cto.com/220419/1765205

apache_tomcat整合应用

标签:mysql   用户 tomcat   

原文地址:http://ko178.blog.51cto.com/220419/1765205

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!