linux tomcat安装
linux tomcat安装
哈哈2725458 发表于5个月前
linux tomcat安装
  • 发表于 5个月前
  • 阅读 0
  • 收藏 0
  • 点赞 0
  • 评论 0

【腾讯云】如何购买服务器最划算?>>>   

1、  软件准备

JDK:jdk-7u79-linux-x64.gz

Tomcat:apache-tomcat-7.0.61.tar.gz

日志切割:cronolog-1.6.2-10.el6.x86_64.rpm

2、   JDK配置

# 上传jdk-7u79-linux-x64.gz到服务器

$ mkdir/opt/server

$ tar zvxf jdk-7u79-linux-x64.gz -C /opt/server

$ chmod 755 /opt –R

$ chown -R dzfp.dzfp /opt/server

 

修改 /etc/profile

$ vi /etc/profile

------------------在文件末尾添加以下内容------------------

JAVA_HOME=/opt/server/jdk1.7.0_79

CLASSPATH=$JAVA_HOME/jre/lib/rt.jar:.

PATH=$JAVA_HOME/bin:$PATH

export JAVA_HOME PATH CLASSPATH

------------------结束------------------------------------------------

$ source /etc/profile

$ 检查java版本:

$java -version

java version "1.7.0_79"

Java(TM) SE Runtime Environment (build 1.7.0_79-b06)

Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

 

3、Tomcat安装

$tar zxvf apache-tomcat-7.0.61.tar.gz -C /opt/server/

$ chmod 755 -R /opt/

$ cd /opt/server

$ mv apache-tomcat-7.0.61 tomcat

$ chown -R dzfp.dzfp tomcat

$ cd /opt/server/tomcat/webapps/

$ rm -rf docs examples manager host-manager

 

4、日志切分

# 上传cronolog-1.6.2-10.el6.x86_64.rpm到 /opt/server

$ rpm -ivh cronolog-1.6.2-10.el6.x86_64.rpm

# 用which命令查看路径验证安装

$ which cronolog

/usr/sbin/cronolog

 

$ cd /opt/server

$ vim tomcat/bin/catalina.sh  (将原来的内容替换为红色部分)

#  touch "$CATALINA_OUT"

if [ "$1" = "-security" ] ; then

if [ $have_tty -eq 1 ]; then

echo "Using Security Manager"

fi

shift

eval "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \

      -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \

      -Djava.security.manager \

      -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \

      -Dcatalina.base="\"$CATALINA_BASE\"" \

      -Dcatalina.home="\"$CATALINA_HOME\"" \

      -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \

org.apache.catalina.startup.Bootstrap "$@" start  2>&1 \

      | /usr/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out >> /dev/null &

#      org.apache.catalina.startup.Bootstrap "$@" start \

#      >> "$CATALINA_OUT" 2>&1 "&"

 

else

eval "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \

      -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \

      -Dcatalina.base="\"$CATALINA_BASE\"" \

      -Dcatalina.home="\"$CATALINA_HOME\"" \

      -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \

org.apache.catalina.startup.Bootstrap "$@" start  2>&1 \

      | /usr/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out >> /dev/null &

#      org.apache.catalina.startup.Bootstrap "$@" start \

#      >> "$CATALINA_OUT" 2>&1 "&"

 

4、设置开机自启动

$ vi /etc/init.d/tomcat

复制下面内容

#!/bin/sh

# tomcat: Start/Stop/Restart tomcat

# chkconfig: 2345 40 20

# description: Tomcat is a Java Servlet Container

# match these values to your environment:

TOMCAT_HOME=/opt/server/tomcat

TOMCAT_USER=dzfp

NOW_USER=$(whoami)

. /etc/init.d/functions TOMCAT=${TOMCAT_HOME}

 

start() {

       echo -n "Starting Tomcat:"

       if [ "$NOW_USER" == "dzfp" ];then

              ${TOMCAT_HOME}/bin/startup.sh

       else

              su  - ${TOMCAT_USER}  -c  "${TOMCAT_HOME}/bin/startup.sh"

       fi

   }

 

stop() {

       echo -n "Stopping Tomcat:"

       if [ "$NOW_USER" == "dzfp" ];then

              ${TOMCAT_HOME}/bin/shutdown.sh

       else

              su  - ${TOMCAT_USER} -c "${TOMCAT_HOME}/bin/shutdown.sh"

       fi

# clear tomcat cache

rm -rf $TOMCAT_HOME/work/Catalina

   }

# See how we were called.

case "$1" in

start)

start

  ;;

stop)

stop

    ;;

status)

    ;;

restart)

stop

sleep 2

start

    ;;

 *)

echo "Usage: $0 {start stop restart}" ;;

esac

exit $RETVAL


--------------------------------------------------------------------------------------------------------------------------------

$chmod +x /etc/init.d/tomcat

$chown -R dzfp:dzfp /opt/server/tomcat /opt/apps /etc/init.d/tomcat

$chkconfig --add tomcat

$chkconfig tomcat on

$chkconfig tomcat --list

tomcat          0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

#启动tomcat

$ /etc/init.d/tomcat start

# 停止tomcat

$ /etc/init.d/tomcat stop

 

5、清理日志脚本

每天2点清理tomcat日志

$mkdir/opt/server/scripts

$chmod 755 -R /opt/server/scripts

$vim /opt/server/scripts/clear_tomcat_logs.sh

#!/bin/bash

# clear tomcat logs

KEEP_TIME=30

DOMAIN_HOME="/opt/server/tomcat"

/usr/bin/find $DOMAIN_HOME/logs -mtime +$KEEP_TIME -exec rm -rf {} \; >>/tmp/clean_tomcat_logs.log

exit 0

$ chown dzfp.dzfp /opt/server/scripts/clear_tomcat_logs.sh

$chmod +x /opt/server/scripts/clear_tomcat_logs.sh

$crontab -e

 0 2 * * * sh /opt/server/scripts/clear_tomcat_logs.sh

共有 人打赏支持
粉丝 1
博文 6
码字总数 11130
×
哈哈2725458
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: