linux下面安装apache+tomcat+mysql

Share

      是老问题了,今天有人问,所以花了点时间整理了一下(以前写过一篇,但是说写的不详细sweat),贴出来供大家参考:

需要下列的包:
JDK:j2sdk-1_4_2_09-linux-i586.bin
Apache2.0.54:httpd-2.0.54.tar.gz
MySQL:mysql-standard-4.1.14-pc-linux-gnu-i686.tar.gz
Tomcat:jakarta-tomcat-5.0.28.tar.gz
jakarta-tomcat-connectors-jk2:jakarta-tomcat-connectors-jk2-2.0.4-src.tar.gz

下面开始安装:

一:安装jdk
[root@localhost download]# ./j2sdk-1_4_2_09-linux-i586.bin
这一步执行完成后,会在download下面生成j2sdk1.4.2_09文件夹
[root@localhost download]#cp -r j2sdk1.4.2_09 /opt/java/
把jdk   copy到自己合适的目录,我的是/opt/java/
然后配置环境变量,用最简单的方法:
[root@localhost download]#vi /etc/profile
export JAVA_HOME=/opt/java/j2sdk1.4.2_09
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/mysql-connector-java-3.2.0.jar:$JAVA_HOME/lib/classes12.jar
export PATH=$PATH:$JAVA_HOME/bin
export JRE_HOME=$JAVA_HOME/jre
[/java]
ok,注销一下,登陆进来,
[root@localhost download]#java -version
下面出现jdk的版本就说明配置成功了。如果没有,请对应上面的方法检查有没有错误的地方。
二:安装MySQL
[root@localhost download]# tar xzfv mysql-standard-4.1.14-pc-linux-gnu-i686.tar.gz
[root@localhost download]# cd mysql-standard-4.1.14-pc-linux-gnu-i686
[root@localhost mysql-standard-4.1.14-pc-linux-gnu-i686]# groupadd mysql
[root@localhost mysql-standard-4.1.14-pc-linux-gnu-i686]# useradd -g mysql mysql
[root@localhost download]# mv mysql-standard-4.1.14-pc-linux-gnu-i686 /opt/mysql
[root@localhost download]# cd /opt/mysql
[root@localhost mysql]# scripts/mysql_install_db –user=mysql
[root@localhost mysql]# chown -R root .         //将当前文件夹关联到root用户组
[root@localhost mysql]# chown -R mysql data
[root@localhost mysql]# chgrp -R mysql .        //当前目录的所有权是mysql
启动mysql
[root@localhost mysql]# bin/mysqld_safe –user=mysql &
连接上mysql
[root@localhost mysql]# ./bin/mysqladmin -u root password ‘password’
[root@localhost mysql]# ./bin/mysqladmin -u root -h localhost.localdomain password 'pass'
[root@localhost mysql]# ./bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 5 to server version: 4.1.14-standard
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>
下面配置mysql以服务的形式启动
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@localhost mysql]# vi /etc/init.d/mysql
添加如下内容:
basedir=/opt/mysql
datadir=/opt/mysql/data
[root@localhost mysql]# chkconfig –level 345 mysql on
[root@localhost mysql]# service mysql restart
Shutting down MySQL… [ OK ]
Starting MySQL [ OK ]
[root@localhost mysql]#
修改密码啊什么的就自己去弄了。:)

三:安装apache
[root@localhost download]# tar zvxf httpd-2.0.54.tar.gz
[root@localhost download]# cp -r httpd-2.0.54 /var/www/
[root@localhost download]# cd /var/www/httpd-2.0.54/
[root@localhost httpd-2.0.54]# ./configure –prefix=/home/www/apache –enable-module=most –enable-shared=max –enable-so
[root@localhost httpd-2.0.54]# make
[root@localhost httpd-2.0.54]# make install
如果你想创建一个启动脚本,就创建下面的文件:
[root@localhost httpd-2.0.54]# vi /etc/init.d/httpd

#!/bin/bash
# Startup script for the Apache Web Server
# 包含函数库
. /etc/rc.d/init.d/functions
# 获取网络配置
. /etc/sysconfig/network
# 检测 NETWORKING 是否为 “yes”
[ “${NETWORKING}” = “no” ] && exit 0
# apache安装目录
APACHE=/home/www/apache
# 启动服务函数
start() {
echo $”Starting httpd service: ”
$APACHE/bin/apachectl start
RETVAL=$?
echo
}
# 关闭服务函数
stop() {
echo $”Stopping httpd service: “
$APACHE/bin/apachectl stop
RETVAL=$?
echo
}
# 根据参数选择调用
case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $”Usage: $0 start|stop|restart”
exit 1
esac
exit 0
[/java]
[root@localhost httpd-2.0.54]# cd /etc/init.d/
[root@localhost init.d]# chmod 755 httpd
[root@localhost init.d]# chkconfig –level 345 httpd on
[root@localhost init.d]# service httpd restart
Apache又安装完了!sweat 累!

四:安装Tomcat
这个是最容易的了。
[root@localhost download]# tar xzfv jakarta-tomcat-5.0.28.tar.gz
[root@localhost download]# cp -rf jakarta-tomcat-5.0.28 /var/www/tomcat
[root@localhost download]# cd /var/www/tomcat
启动tomcat服务:
[root@localhost tomcat]# ./bin/startup.sh
查看是否启动了tomcat
[root@localhost tomcat]# ps -aedf |grep tomcat
如果除了一个root的bash命令外,还有一个tomcat的进程,就说明已经启动了。
停止tomcat服务:
[root@localhost tomcat]# ./bin/shutdown.sh

五:编译生成tomcat和apache的连接器
注意下面的每一步都很关键,请小心:
[root@localhost download]# tar xzfv jakarta-tomcat-connectors-jk2-2.0.4-src.tar.gz
[root@localhost download]# cd jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2/
[root@localhost native2]# ./configure –with-apxs2=/home/www/apache/bin/apxs
[root@localhost native2]# make
[root@localhost native2]# cd ../build/jk2/apache2/
[root@localhost apache2]# /home/www/apache/bin/apxs -n jk2 -i mod_jk2.so
这样就生成了mod_jk2.so这个连接文件。

六:整合tomcat和apache
[root@localhost apache2]# cd /home/www/apache/conf/
添加连接器到apache中
[root@localhost conf]# vi httpd.conf
LoadModule jk2_module modules/mod_jk2.so
然后在这个目录新建一个文件workers2.properties
[root@localhost conf]# vi workers2.properties
[channel.socket:127.0.0.1:8009]
port=8009
host=127.0.0.1
[ajp13:127.0.0.1:8009]
channel=channel.socket:127.0.0.1:8009
[uri:/*]
worker=ajp13:127.0.0.1:8009
[uri:/examples/*]
worker=ajp13:127.0.0.1:8009
[/java]
接下来进入tomcat下的conf目录:
[root@localhost conf]# cd /home/www/tomcat/conf/
修改server.xml文件
[root@localhost conf]# vi server.xml
              maxThreads=”150″ minSpareThreads=”25″ maxSpareThreads=”75″
              enableLookups=”false” redirectPort=”8443″ acceptCount=”100″
              debug=”0″ connectionTimeout=”20000″
              disableUploadTimeout=”true” URIEncoding=”UTF-8″/>
[/java]
把这一段的注释取消。

然后用浏览器测试下就好了。
大功告成!!!sweat