Chinaunix首页 | 论坛 | 博客
  • 博客访问: 175777
  • 博文数量: 159
  • 博客积分: 7007
  • 博客等级: 准将
  • 技术积分: 1750
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-17 15:05
文章分类

全部博文(159)

文章存档

2010年(39)

2009年(106)

2008年(14)

我的朋友

分类: LINUX

2009-06-01 10:48:09

Apache 2.2 + Tomcat 6.0 + MySQL 5.0 + mod_jk 整合

说明:系统为redhat enterprise linux 5 update 2

      定制最小化安装

      本机IP地址:192.168.0.253

1.       搭建本地yum

    [root@tomcat ~]# mount /dev/cdrom /mnt

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@tomcat ~]# vi /etc/yum.repos.d/local.repo

[rhel5-local]

name=Red Hat Enterprise Linux 5 Local Repository

baseurl=file:///mnt/Server

enabled=1

gpgcheck=0

[root@tomcat ~]# yum install gcc

[root@tomcat ~]# yum install openssl*

2.       安装apache

   [root@tomcat ~]# cd /usr/local/src/

[root@tomcat src]# ls

apache-tomcat-6.0.18.tar.gz  jaf-1_0_2-upd2.zip  jdk-6u13-linux-i586.bin                tomcat-connectors-1.2.28-src.tar.gz

httpd-2.2.11.tar.bz2         javamail-1.4.2.zip  mysql-connector-java-5.1.7.tar.gz.tar

[root@tomcat src]# tar jxvf httpd-2.2.11.tar.bz2

[root@tomcat src]# cd httpd-2.2.11

[root@tomcat httpd-2.2.11]# ./configure --prefix=/usr/local/httpd --with-mpm=worker --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache --enable-mime-magic --enable-headers --enable-ssl --enable-http --enable-cgi --enable-rewrite --enable-so --with-suexec-gidmin --with-suexec-logfile

[root@tomcat httpd-2.2.11]# make

[root@tomcat httpd-2.2.11]# make install

[root@tomcat httpd-2.2.11]# cp /usr/local/httpd/bin/apachectl   /etc/rc.d/init.d/apache

[root@tomcat httpd-2.2.11]# /etc/rc.d/init.d/apache start

httpd: apr_sockaddr_info_get() failed for tomcat

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

[root@tomcat httpd-2.2.11]# vi /usr/local/httpd/conf/httpd.conf

ServerName localhost:80                                   改为这样

[root@tomcat httpd-2.2.11]# /etc/rc.d/init.d/apache stop

[root@tomcat httpd-2.2.11]# /etc/rc.d/init.d/apache start

[root@tomcat httpd-2.2.11]# ps aux | grep httpd; netstat -ntulp | grep :80

root     29285  0.5  0.4   7420  2476 ?        Ss   17:20   0:00 /usr/local/httpd/bin/httpd -k start

daemon   29286  0.0  0.3   7192  1564 ?        S    17:20   0:00 /usr/local/httpd/bin/httpd -k start

daemon   29287  0.0  0.3 284056  1936 ?        Sl   17:20   0:00 /usr/local/httpd/bin/httpd -k start

daemon   29289  0.0  0.3 284056  1940 ?        Sl   17:20   0:00 /usr/local/httpd/bin/httpd -k start

daemon   29291  0.0  0.3 284056  1940 ?        Sl   17:20   0:00 /usr/local/httpd/bin/httpd -k start

root     29372  0.0  0.1   3904   672 pts/0    R+   17:20   0:00 grep httpd

tcp        0      0 :::80                       :::*                        LISTEN      29285/httpd 

3.安装tomcat

[root@tomcat httpd-2.2.11]# cd ..

[root@tomcat src]# mv apache-tomcat-6.0.18.tar.gz tomcat-connectors-1.2.28-src.tar.gz jdk-6u13-linux-i586.bin jaf-1_0_2-upd2.zip javamail-1.4.2.zip /opt

[root@tomcat src]# cd /opt/

[root@tomcat opt]# ls

apache-tomcat-6.0.18.tar.gz  jaf-1_0_2-upd2.zip  javamail-1.4.2.zip  jdk-6u13-linux-i586.bin  tomcat-connectors-1.2.28-src.tar.gz

[root@tomcat opt]# tar zxvf apache-tomcat-6.0.18.tar.gz ; unzip jaf-1_0_2-upd2.zip ; unzip javamail-1.4.2.zip ; tar zxvf tomcat-connectors-1.2.28-src.tar.gz ;

chmod +x jdk-6u13-linux-i586.bin

[root@tomcat opt]# ls

apache-tomcat-6.0.18         jaf-1.0.2           javamail-1.4.2      jdk-6u13-linux-i586.bin       tomcat-connectors-1.2.28-src.tar.gz

apache-tomcat-6.0.18.tar.gz  jaf-1_0_2-upd2.zip  javamail-1.4.2.zip  tomcat-connectors-1.2.28-src

安装sun javaJDK

[root@tomcat opt]# ./jdk-6u13-linux-i586.bin

Sun Microsystems, Inc. Binary Code License Agreement

for the JAVA SE DEVELOPMENT KIT (JDK), VERSION 6

--More--

~~~~~~~~~~~~~~~~~ignore~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

THIRDPARTYLICENSEREADME.txt file, the disclaimer of

warranty and limitation of liability provisions in

paragraphs 5 and 6 of the Binary Code License Agreement

shall apply to all Software in this distribution.

H. Termination for Infringement. Either party may terminate

this Agreement immediately should any Software become, or

in either party's opinion be likely to become, the subject

of a claim of infringement of any intellectual property

right.

I. Installation and Auto-Update. The Software's

installation and auto-update processes transmit a limited

amount of data to Sun (or its service provider) about those

specific processes to help Sun understand and optimize

them. Sun does not associate the data with personally

identifiable information. You can find more information

about the data Sun collects at

For inquiries please contact: Sun Microsystems, Inc., 4150

Network Circle, Santa Clara, California 95054, U.S.A.

Do you agree to the above license terms? [yes or no]

yes

~~~~~~~~~~~~~~~~~~~ignore~~~~~~~~~~~~~~~~~~~~~``

Java(TM) SE Development Kit 6 successfully installed.

Product Registration is FREE and includes many benefits:

* Notification of new versions, patches, and updates

* Special offers on Sun products, services and training

* Access to early releases and documentation

Product and system data will be collected. If your configuration

supports a browser, the Sun Product Registration form for

the JDK will be presented. If you do not register, none of

this information will be saved. You may also register your

JDK later by opening the register.html file (located in

the JDK installation directory) in a browser.

For more information on what data Registration collects and

how it is managed and used, see:

Press Enter to continue.....

 

Done.

[root@tomcat opt]# mv apache-tomcat-6.0.18 tomcat; mv jdk1.6.0_13 java; mv jaf-1.0.2 jaf; mv javamail-1.4.2 java

[root@tomcat opt]# ls

apache-tomcat-6.0.18.tar.gz  jaf-1_0_2-upd2.zip  javamail-1.4.2.zip       tomcat                        tomcat-connectors-1.2.28-src.tar.gz

jaf                          java                jdk-6u13-linux-i586.bin  tomcat-connectors-1.2.28-src

设定环境变量

[root@tomcat opt]# vi /etc/profile

JAVA_HOME=/opt/java

CATALINA_HOME=/opt/tomcat

CATALINA_BASE=/opt/tomcat

CLASSPATH=./:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib/ext:${CATALINA_HOME}/common/lib:/opt/javamail/mail.jar:/opt/jaf/activation.jar

export JAVA_HOME CATALINA_HOME CATALINA_BASE CLASSPATH

export PATH=${JAVA_HOME}/bin:${CATALINA_HOME}/bin:${PATH}

使用source.指令使修改生效

[root@tomcat opt]# source /etc/profile

[root@tomcat opt]# cd tomcat-connectors-1.2.28-src/native/

编译mod_jk

[root@tomcat native]# ./configure --with-java-home=/opt/java

--with-apxs=/usr/local/httpd/bin/apxs

[root@tomcat native]# make

安装mod_jkhttpd

[root@tomcat native]# cp apache-2.0/mod_jk.so /usr/local/httpd/lib/

[root@tomcat native]#cd /opt

[root@tomcat opt]# vi /usr/local/httpd/conf/httpd.conf

加入如下3,载入mod_jk模组与mod_jk设定档栏目

LoadModule jk_module lib/mod_jk.so

# mod_jk settings

Include conf/mod_jk.conf

[root@tomcat opt]# cd /usr/local/httpd/conf/

[root@tomcat conf]# touch mod_jk.conf

[root@tomcat conf]# vi mod_jk.conf

#setup the workers.properties file path, default prefix path is httpd's home (/usr/local/httpd)

JkWorkersFile conf/workers.properties

JkLogFile /var/log/jk.log

JkShmFile /var/log/jk-runtime-status

JkLogLevel error

JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

JkRequestLogFormat "%w %V %T"

# Sample JkMounts. Replace these with the paths you would

# like to mount from your JSP server.

# syntax: JkMount ${URL_DIR}/*.jsp worker_name

JkMount /project1/*.jsp jsp-ap207

JkMount /project2/*.jsp jsp-ap207

JkMount /project3/*.jsp jsp-ap207

[root@tomcat conf]# touch workers.properties

[root@tomcat conf]# vi workers.properties

# BEGIN workers.properties

# setting tomcat_home and java_home

workers.tomcat_home=/opt/tomcat

workers.java_home=/opt/java

# worker.list defined worker_name, used by mod_jk.conf

worker.list=jsp-ap207

worker.jsp-ap207.port=8009

worker.jsp-ap207.host=192.168.0.253

worker.jsp-ap207.type=ajp13

worker.jsp-ap207.lbfactor=1

[root@tomcat conf]# cd /opt/

[root@tomcat opt]# vi tomcat/conf/server.xml

unpackWARs="true" autoDeploy="true">

debug="5" reloadable="true" crossContext="true">

 

 

[root@tomcat opt]# mkdir -p "/projects/project1"; cd /projects/project1

[root@tomcat project1]# /etc/rc.d/init.d/apache stop

[root@tomcat project1]# /etc/rc.d/init.d/apache start

[root@tomcat project1]# /opt/tomcat/bin/startup.sh

Using CATALINA_BASE:   /opt/tomcat

Using CATALINA_HOME:   /opt/tomcat

Using CATALINA_TMPDIR: /opt/tomcat/temp

Using JRE_HOME:       /opt/java

测试

[root@tomcat project1]# vi hello.jsp

<%@ page contentType="text/html;charset=big5" %>

<%

String str1="Hello World!";

out.println(str1);

%>

4.MYSQL设定

[root@tomcat project1]# yum install mysql*

[root@tomcat project1]# /etc/rc.d/init.d/mysqld start

[root@tomcat project1]# mysqladmin -u root -p password gamester88 

Enter password:              

1.注释: gamester88为新密码,mysql默认没有密码                      

2.因为以前没有密码,直接回车

[root@tomcat project1]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.0.45 Source distribution

 

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

 

mysql> CREATE DATABASE project1;

Query OK, 1 row affected (0.00 sec)

 

mysql> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| project1           |

| test               |

+--------------------+

4 rows in set (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO test@”%”

       IDENTIFIED BY ‘test’ WITH GRANT OPTION;

      注释:test可以从任何地方连接服务器的一个完全的超级用户,但是必须使用一个口令(‘test’)做这个。注意,我们必须对test@localhosttest@”%”发出GRANT语句.如果我们增加localhost条目,对localhost的匿名用户条目在我们从本地主机连接时由mysql_install_db创建的条目将优先考虑,因为它有更特定的Host字段值,所以以user表排列顺序看更早到来。

mysql> quit

Bye

  [root@tomcat project1]# cd /usr/local/src/

[root@tomcat src]# ls

httpd-2.2.11  httpd-2.2.11.tar.bz2  mysql-connector-java-5.1.7.tar.gz.tar

 

[root@tomcat src]# tar xvf mysql-connector-java-5.1.7.tar.gz.tar

[root@tomcat src]# cp

mysql-connector-java-5.1.7/mysql-connector-java-5.1.7-bin.jar /opt/tomcat/lib/

[root@tomcat src]# cd /opt/

[root@tomcat opt]# vi tomcat/conf/server.xml

unpackWARs="true" autoDeploy="true">

       

debug="5" reloadable="true" crossContext="true">

       

type="javax.sql.DataSource" maxActive="100" maxIdle="30"

maxWait="10000" username="root" password="iamis

r00t"

driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/project1?autoReconnect=true"/>

       

       

[root@tomcat opt]# /opt/tomcat/bin/shutdown.sh

Using CATALINA_BASE:   /opt/tomcat

Using CATALINA_HOME:   /opt/tomcat

Using CATALINA_TMPDIR: /opt/tomcat/temp

Using JRE_HOME:       /opt/java

[root@tomcat opt]# /opt/tomcat/bin/startup.sh

Using CATALINA_BASE:   /opt/tomcat

Using CATALINA_HOME:   /opt/tomcat

Using CATALINA_TMPDIR: /opt/tomcat/temp

Using JRE_HOME:       /opt/java

测试可否连接mysql

[root@tomcat opt]# vi /projects/project1/db_test.jsp

<%@ page import="java.sql.*"%>

<%@ page import="javax.sql.*"%>

<%@ page import="javax.naming.*"%>

<%@ page session="false" %>

Test of mysql connection pool

<%

out.print("start
");

try{

Context initctx = new InitialContext();

Context ctx = (Context) initctx.lookup("java:comp/env");

Object obj = (Object) ctx.lookup("jdbc/project1");

javax.sql.DataSource ds = (javax.sql.DataSource)obj;

Connection conn = ds.getConnection();

out.print("mysql connection pool runs perfectly!");

conn.close();

}

catch(Exception ex){

out.print(ex.getMessage());

ex.printStackTrace();

}

%>

致谢:此文参考了台湾廖子儀的文章

                                                           CU:Gamester88

阅读(710) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~