一.安装JDK
1.首先安装jdk,下面以jdk-6u26-linux-i586为列:
下载安装不需要再说了吧,网上资料多的是
安装完jdk做个软连接:
ln -s /usr/java/jdk1.6.0_26 /usr/local/java
2.然后在/etc/profile里增加变量:
export JAVA_HOME=/usr/java/jdk1.6.0_26
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin
使变量生效:
source /etc/profile
二.安装tomcat-7.0.19
1.首先打开防火墙的8080端口 /sbin/iptables -I INPUT -p tcp –dport 8080 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
2.安装tomcat-7.0.19
tar zxvf apache-tomcat-7.0.19.tar.gz
mv apache-tomcat-7.0.19 /usr/local/tomcat
cd /usr/local/webserver/tomcat/bin
tar zxvf commons-daemon-native.tar.gz
cd commons-daemon-1.0.6-native-src/unix
./configure –with-java=/usr/java/jdk1.6.0_26
make
cp jsvc ../..
3.复制下载的mysql-connector-java-5.1.17-bin.jar到/usr/local/tomcat/lib/目录下
4.建立tomcat运行用户
/usr/sbin/groupadd tomcat
/usr/sbin/useradd -g tomcat tomcat -s /sbin/nologin
5.在/etc/profile里增加tomcat变量
export TOMCAT_HOME=/usr/local/tomcat
export CATALINA_HOME=/usr/local/tomcat
使变量生效:
source /etc/profile
6.在/etc/rc.d/init.d目录下建立启动脚本tomcat文件,脚本内容如下,红色字体就是运行tomcat的用户
#!/bin/sh
# chkconfig: 2345 10 90
# description: Starts and Stops the Tomcat daemon.
# Licensed to the Apache Software Foundation (ASF) under one or
more
# contributor license agreements. See the NOTICE file distributed
with
# this work for additional information regarding copyright
ownership.
# The ASF licenses this file to You under the Apache License,
Version 2.0
# (the “License”); you may not use this file except in compliance
with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
software
# distributed under the License is distributed on an “AS IS”
BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
# See the License for the specific language governing permissions
and
# limitations under the License.
#
# resolve links – $0 may be a softlink
JAVA_HOME=/usr/java/jdk1.6.0_26
CATALINA_HOME=/usr/local/tomcat
ARG0=”$0″
while [ -h "$ARG0" ]; do
ls=`ls -ld “$ARG0″`
link=`expr “$ls” : ‘.*-> (.*)$’`
if expr “$link” : ‘/.*’ > /dev/null; then
ARG0=”$link”
else
ARG0=”`dirname $ARG0`/$link”
fi
done
DIRNAME=”`dirname $ARG0`”
PROGRAM=”`basename $ARG0`”
for o
do
case “$o” in
–java-home )
JAVA_HOME=”$2″
shift; shift;
continue
;;
–catalina-home )
CATALINA_HOME=”$2″
shift; shift;
continue
;;
–catalina-base )
CATALINA_BASE=”$2″
shift; shift;
continue
;;
–catalina-pid )
CATALINA_PID=”$2″
shift; shift;
continue
;;
–tomcat-user )
TOMCAT_USER=”$2″
shift; shift;
continue
;;
* )
break
;;
esac
done
# OS specific support (must be ‘true’ or ‘false’).
cygwin=false;
darwin=false;
case “`uname`” in
CYGWIN*)
cygwin=true
;;
Darwin*)
darwin=true
;;
esac
# Use the maximum available, or set MAX_FD != -1 to use that
test “.$MAX_FD” = . && MAX_FD=”maximum”
# Setup parameters for running the jsvc
#
test “.$TOMCAT_USER” = . && TOMCAT_USER=tomcat
# Set JAVA_HOME to working JDK or JRE
JAVA_HOME=/usr/java/jdk1.6.0_26
# If not set we’ll try to guess the JAVA_HOME
# from java binary if on the PATH
#
if [ -z "$JAVA_HOME" ]; then
JAVA_BIN=”`which java 2>/dev/null || type java 2>&1`”
test -x “$JAVA_BIN” && JAVA_HOME=”`dirname $JAVA_BIN`”
test “.$JAVA_HOME” != . && JAVA_HOME=`cd “$JAVA_HOME/..”
>/dev/null; pwd`
else
JAVA_BIN=”$JAVA_HOME/bin/java”
fi
# Only set CATALINA_HOME if not already set
test “.$CATALINA_HOME” = . && CATALINA_HOME=`cd
“$DIRNAME/..” >/dev/null; pwd`
test “.$CATALINA_BASE” = . &&
CATALINA_BASE=”$CATALINA_HOME”
test “.$CATALINA_MAIN” = . &&
CATALINA_MAIN=org.apache.catalina.startup.Bootstrap
test “.$JSVC” = . && JSVC=”$CATALINA_BASE/bin/jsvc”
# Ensure that any user defined CLASSPATH variables are not used
on startup,
# but allow them to be specified in setenv.sh, in rare case when it
is needed.
CATALINA_HOME=/usr/local/tomcat
JAVA_OPTS=
if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
. “$CATALINA_BASE/bin/setenv.sh”
elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
. “$CATALINA_HOME/bin/setenv.sh”
fi
# Add on extra jar files to CLASSPATH
test “.$CLASSPATH” != . && CLASSPATH=”${CLASSPATH}:”
CLASSPATH=”$CLASSPATH$CATALINA_HOME/bin/bootstrap.jar:$CATALINA_HOME/bin/commons-daemon.jar”
test “.$CATALINA_OUT” = . &&
CATALINA_OUT=”$CATALINA_BASE/logs/catalina-daemon.out”
test “.$CATALINA_TMP” = . &&
CATALINA_TMP=”$CATALINA_BASE/temp”
# Add tomcat-juli.jar to classpath
# tomcat-juli.jar can be over-ridden per instance
if [ -r "$CATALINA_BASE/bin/tomcat-juli.jar" ] ; then
CLASSPATH=”$CLASSPATH:$CATALINA_BASE/bin/tomcat-juli.jar”
else
CLASSPATH=”$CLASSPATH:$CATALINA_HOME/bin/tomcat-juli.jar”
fi
# Set juli LogManager config file if it is present and an override
has not been issued
if [ -z "$LOGGING_CONFIG" ]; then
if [ -r "$CATALINA_BASE/conf/logging.properties" ]; then
LOGGING_CONFIG=”-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties”
else
# Bugzilla 45585
LOGGING_CONFIG=”-Dnop”
fi
fi
test “.$LOGGING_MANAGER” = . &&
LOGGING_MANAGER=”-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager”
JAVA_OPTS=”$JAVA_OPTS $LOGGING_MANAGER”
# Set -pidfile
test “.$CATALINA_PID” = . &&
CATALINA_PID=”$CATALINA_BASE/logs/catalina-daemon.pid”
# Increase the maximum file descriptors if we can
if [ "$cygwin" = "false" ]; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ "$?" -eq 0 ]; then
# Darwin does not allow RLIMIT_INFINITY on file soft limit
if [ "$darwin" = "true" -a "$MAX_FD_LIMIT" = "unlimited" ];
then
MAX_FD_LIMIT=`/usr/sbin/sysctl -n kern.maxfilesperproc`
fi
test “.$MAX_FD” = “.maximum” && MAX_FD=”$MAX_FD_LIMIT”
ulimit -n $MAX_FD
if [ "$?" -ne 0 ]; then
echo “$PROGRAM: Could not set maximum file descriptor limit:
$MAX_FD”
fi
else
echo “$PROGRAM: Could not query system maximum file descriptor
limit: $MAX_FD_LIMIT”
fi
fi
# —– Execute The Requested Command —————————————–
case “$1″ in
run )
shift
“$JSVC” $*
$JSVC_OPTS
-java-home “$JAVA_HOME”
-pidfile “$CATALINA_PID”
-wait 10
-nodetach
-outfile “&1″
-errfile “&2″
-classpath “$CLASSPATH”
“$LOGGING_CONFIG” $JAVA_OPTS $CATALINA_OPTS
-Djava.endorsed.dirs=”$JAVA_ENDORSED_DIRS”
-Dcatalina.base=”$CATALINA_BASE”
-Dcatalina.home=”$CATALINA_HOME”
-Djava.io.tmpdir=”$CATALINA_TMP”
$CATALINA_MAIN
exit $?
;;
start )
“$JSVC” $JSVC_OPTS
-java-home “$JAVA_HOME”
-user $TOMCAT_USER
-pidfile “$CATALINA_PID”
-wait 10
-outfile “$CATALINA_OUT”
-errfile “&1″
-classpath “$CLASSPATH”
“$LOGGING_CONFIG” $JAVA_OPTS $CATALINA_OPTS
-Djava.endorsed.dirs=”$JAVA_ENDORSED_DIRS”
-Dcatalina.base=”$CATALINA_BASE”
-Dcatalina.home=”$CATALINA_HOME”
-Djava.io.tmpdir=”$CATALINA_TMP”
$CATALINA_MAIN
exit $?
;;
stop )
“$JSVC” $JSVC_OPTS
-stop
-pidfile “$CATALINA_PID”
-classpath “$CLASSPATH”
-Djava.endorsed.dirs=”$JAVA_ENDORSED_DIRS”
-Dcatalina.base=”$CATALINA_BASE”
-Dcatalina.home=”$CATALINA_HOME”
-Djava.io.tmpdir=”$CATALINA_TMP”
$CATALINA_MAIN
exit $?
;;
version )
“$JSVC”
-java-home “$JAVA_HOME”
-pidfile “$CATALINA_PID”
-classpath “$CLASSPATH”
-errfile “&2″
-version
-check
$CATALINA_MAIN
if [ "$?" = 0 ]; then
“$JAVA_BIN”
-classpath “$CATALINA_HOME/lib/catalina.jar”
org.apache.catalina.util.ServerInfo
fi
exit $?
;;
* )
echo “Unkown command: `$1′”
echo “Usage: $PROGRAM ( commands … )”
echo “commands:”
echo ” run Start Catalina without detaching from console”
echo ” start Start Catalina”
echo ” stop Stop Catalina”
echo ” version What version of commons daemon and Tomcat”
echo ” are you running?”
exit 1
;;
esac
赋予启动脚本运行权限:
chmod +x /etc/rc.d/init.d/tomcat
赋予tomcat程序目录tomcat用户权限权限:
chown -R tomcat:tomcat /usr/local/tomcat
6.加入随机启动
chkconfig –add tomcat
7.启动tomcat,注意有时候启动不了,需要重新启动下系统才行
service tomcat start
三.安装resin-4.0.20(就我个人而言,我喜欢resin不喜欢用tomcat)
1.首先打开防火墙的8080端口
/sbin/iptables -I INPUT -p tcp –dport 8080 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
2.安装resin-4.0.20
tar -zxvf resin-4.0.20.tar.gz
cd resin-4.0.20
./configure –prefix=/usr/local/resin
–with-java-home=/usr/local/java
make
make install
cd ../
3.复制下载的mysql-connector-java-5.1.17-bin.jar到/usr/local/resin/lib/目录下
4.建立resin运行用户
/usr/sbin/groupadd resin
/usr/sbin/useradd -g resin resin -s /sbin/nologin
5.赋予resin程序目录resin用户权限
chown -R resin:resin /usr/local/resin
6.修改resin配置文件里的运行用户名
打开/usr/local/resin/conf目录下的resin.xml文件
找到:
修改为:
7.在/etc/rc.d/init.d目录下建立启动脚本resin文件,脚本内容如下
#!/bin/bash
### BEGIN INIT INFO
# Provides: resin
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: The Resin Java Application Server
### END INIT INFO
#
### BEGIN Fedora SysV
#
# chkconfig: 345 85 15
# description: Resin is a Java Web server.
# description: The Resin Java Application Server
#
### END Fedora SysV
#
# To install, configure this file as needed and copy init.resin
# to /etc/rc.d/init.d as resin. Then use “# /sbin/chkconfig resin
reset”
#
JAVA_HOME=”/usr/local/java”
RESIN_HOME=”/usr/local/resin”
# for ubuntu
if [ ! -d $JAVA_HOME ]; then
_JAVA_HOMES=”/usr/lib/jvm/java-6-sun
/usr/lib/jvm/java-6-openjdk”
for _java_home in $_JAVA_HOMES; do
if [ -d $_java_home ]; then
JAVA_HOME=$_java_home
break
fi
done
fi
export JAVA_HOME RESIN_HOME
JAVA=”/usr/local/java/bin/java”
#
# Set to the server id to start
#
#SERVER=”-server app-a”
#
# -resin-root /var/resin — the main data directory
#
RESIN_ROOT=”-root-directory /usr/local/resin”
#
# -conf /etc/resin/resin.xml — the main configuration file
#
RESIN_CONF=”-conf /usr/local/resin/conf/resin.xml”
#
# -log-directory /var/log/resin — the main log directory
#
RESIN_LOG=”-log-directory /usr/local/resin/log”
ARGS=”$RESIN_CONF $RESIN_LOG $RESIN_ROOT $SERVER”
if test -r /lib/lsb/init-functions; then
. /lib/lsb/init-functions
fi
type echo 1> /dev/null
if test “$?” != 0; then
log_daemon_msg () {
if [ -z "$1" ]; then
return 1
fi
if [ -z "$2" ]; then
echo -n “$1:”
return
fi
echo -n “$1: $2″
}
log_end_msg () {
[ -z "$1" ] && return 1
if [ $1 -eq 0 ]; then
echo ” .”
else
echo ” failed!”
fi
return $1
}
fi
case “$1″ in
start)
echo “Starting resin”
if test -n “$USER”; then
su $USER -c “”"$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS start”"”
1>/dev/null 2>/dev/null
else
errors=`$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS start
2>&1`
if [ $? != 0 ]; then
echo $errors
fi
fi
echo $?
;;
stop)
echo “Stopping resin”
if test -n “$USER”; then
su $USER -c “”"$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS
shutdown”"” 1>/dev/null 2>/dev/null
else
errors=`$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS shutdown
2>&1`
if [ $? != 0 ]; then
echo $errors
fi
fi
echo $?
;;
status)
$JAVA -jar $RESIN_HOME/lib/resin.jar $ARGS status
;;
restart)
$0 stop
$0 start
;;
*)
echo “Usage: $0 {start|stop|status|restart}”
exit 1
esac
exit 0
8.赋予resin启动脚本运行权限
chmod +x /etc/rc.d/init.d/resin
9.加入随机启动
chkconfig –add resin
10.启动resin
service resin start
写的已经很详细了,如果你需要安装以上的,自己又搞不定,请使用热点的jdk/resin/tomcat/jdbc一键安装包
详情:http://blog.7qy.com/html/532.html