一台centos7.2服务器安装两个tomcat应用服务

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一台centos7.2服务器安装两个tomcat应用服务相关的知识,希望对你有一定的参考价值。

一台Centos服务器安装两个tomcat8服务

1. 安装部署jdk打开链接,详细安装步骤

   http://bbs.hfteams.com/forum.php?mod=viewthread&tid=13&extra=

2. 服务列表

应用服务

版本

服务器

Jdk

8u151

Centos7.2

127.0.0.1

Tomcat1

8.0.47

Tomcat2

8.0.47

3. 安装部署tomcat1

[[email protected] ~]#  tar zxf apache-tomcat-8.0.47.tar.gz

[[email protected] ~]#  mv apache-tomcat-8.0.47 /usr/local/tomcat

[[email protected] ~]#  vim /etc/profile

添加tomcat1配置

#tomcat1

TOMCAT_HOME=/usr/local/tomcat

CATALINA_HOME=/usr/local/tomcat

CATALINA_BASE=/usr/local/tomcat

export  TOMCAT_HOME  CATALINA_HOME CATALINA_BASE

保存退出 :wq

执行/etc/profile文件  查看PATH变量是否生效

[[email protected] ~]# source /etc/profile

[[email protected] ~]# echo $PATH

/usr/local/tomcat/bin:/usr/local/java/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

查看tomcat版本及信息

[[email protected] ~]# catalina.sh version

Using CATALINA_BASE:   /usr/local/tomcat

Using CATALINA_HOME:   /usr/local/tomcat

Using CATALINA_TMPDIR: /usr/local/tomcat/temp

Using JRE_HOME:        /usr/local/java

Using CLASSPATH:       /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

Server version: Apache Tomcat/8.0.47

Server built:   Sep 29 2017 13:46:41 UTC

Server number:  8.0.47.0

OS Name:        Linux

OS Version:     3.10.0-514.el7.x86_64

Architecture:   amd64

JVM Version:    1.8.0_151-b12

JVM Vendor:     Oracle Corporation

tomcat/bin执行文件添加执行权限并启动tomcat1

[[email protected] ~]# chmod +x /usr/local/tomcat/bin/*.sh

[[email protected] ~]# /usr/local/tomcat/bin/startup.sh

Using CATALINA_BASE:   /usr/local/tomcat

Using CATALINA_HOME:   /usr/local/tomcat

Using CATALINA_TMPDIR: /usr/local/tomcat/temp

Using JRE_HOME:        /usr/local/java

Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

Tomcat started.

查看端口是否生效,是否有8080端口

添加防火墙规则允许8080端口通过

[[email protected] ~]# firewall-cmd --add-prot=8080/tcp

4. 部署tomcat2

安装步骤跟tomcat1一样,只需要改一下安装目录名,我改的是tomcat8

[[email protected] ~]# /usr/local/tomcat8/

tomcat/bin执行文件添加执行权限

[[email protected] ~]# chmod +x /usr/local/tomcat/bin/*.sh

[[email protected] ~]#  vim /etc/profile

#tomcat2

TOMCAT_8_HOME=/usr/local/tomcat8

CATALINA_8_HOME=/usr/local/tomcat8

CATALINA_8_BASE=/usr/local/tomcat8

export  TOMCAT_8_HOME  CATALINA_8_HOME CATALINA_8_BASE

完整profile配置文件

# /etc/profile

pathmunge () {

    case ":${PATH}:" in

        *:"$1":*)

            ;;

        *)

            if [ "$2" = "after" ] ; then

                PATH=$PATH:$1

            else

                PATH=$1:$PATH

            fi

    esac

}

 

 

if [ -x /usr/bin/id ]; then

    if [ -z "$EUID" ]; then

        # ksh workaround

        EUID=`/usr/bin/id -u`

        UID=`/usr/bin/id -ru`

    fi

    USER="`/usr/bin/id -un`"

    LOGNAME=$USER

    MAIL="/var/spool/mail/$USER"

fi

 

# Path manipulation

if [ "$EUID" = "0" ]; then

    pathmunge /usr/sbin

    pathmunge /usr/local/sbin

else

    pathmunge /usr/local/sbin after

    pathmunge /usr/sbin after

fi

 

HOSTNAME=`/usr/bin/hostname 2>/dev/null`

HISTSIZE=1000

if [ "$HISTCONTROL" = "ignorespace" ] ; then

    export HISTCONTROL=ignoreboth

else

    export HISTCONTROL=ignoredups

fi

 

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

 

if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then

    umask 002

else

    umask 022

fi

 

for i in /etc/profile.d/*.sh ; do

    if [ -r "$i" ]; then

        if [ "${-#*i}" != "$-" ]; then

            . "$i"

        else

            . "$i" >/dev/null

        fi

    fi

done

 

unset i

unset -f pathmunge

 

export JAVA_HOME=/usr/local/java

CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

PATH=$PATH:$JAVA_HOME/bin

JRE_HOME=$JAVA_HOME/jre

export JAVA_HOME

export PATH

export CLASSPATH

#export PATH=$JAVA_HOME/bin:$CATALINA_HOME/bin:$PATH

 

#tomcat1

TOMCAT_HOME=/usr/local/tomcat

CATALINA_HOME=/usr/local/tomcat

CATALINA_BASE=/usr/local/tomcat

export  TOMCAT_HOME  CATALINA_HOME CATALINA_BASE

 

#tomcat2

TOMCAT_8_HOME=/usr/local/tomcat8

CATALINA_8_HOME=/usr/local/tomcat8

CATALINA_8_BASE=/usr/local/tomcat8

export  TOMCAT_8_HOME  CATALINA_8_HOME CATALINA_8_BASE

修改tomcat2端口conf/server.xml 红色字体都需要改

<?xml version='1.0' encoding='utf-8'?>

<Server port="9005" shutdown="SHUTDOWN">

  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />

  <Listener className="org.apache.catalina.security.SecurityListener" />

  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />

  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

 

  <GlobalNamingResources>

    <Resource name="UserDatabase" auth="Container"

              type="org.apache.catalina.UserDatabase"

              description="User database that can be updated and saved"

              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"

              pathname="conf/tomcat-users.xml" />

  </GlobalNamingResources>

  <Service name="Catalina">

    <Connector port="9080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

    <Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />

 

    <Engine name="Catalina" defaultHost="localhost">

      <Realm className="org.apache.catalina.realm.LockOutRealm">

        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"

               resourceName="UserDatabase"/>

      </Realm>

 

      <Host name="localhost"  appBase="webapps"

            unpackWARs="true" autoDeploy="true">

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"

               prefix="localhost_access_log" suffix=".txt"

               pattern="%h %l %u %t "%r" %s %b" />

 

      </Host>

    </Engine>

  </Service>

</Server>

修改bin/shutdown.sh exec "$PRGDIR"/"$EXECUTABLE" stop "[email protected]"添加红色字体

export JAVA_HOME=/usr/local/java

export PATH=$PATH:$JAVA_HOME/bin

export CLASSPATH=$JAVA_HOME/lib

export CATALINA_HOME=$CATALINA_8_HOME

export CATALINA_BASE=$CATALINA_8_BASE

exec "$PRGDIR"/"$EXECUTABLE" stop "[email protected]"

修改bin/startup.sh exec "$PRGDIR"/"$EXECUTABLE" stop "[email protected]"添加红色字体

export JAVA_HOME=/usr/local/java

export PATH=$PATH:$JAVA_HOME/bin

export CLASSPATH=$JAVA_HOME/lib

export CATALINA_HOME=$CATALINA_8_HOME

export CATALINA_BASE=$CATALINA_8_BASE

启动tomcat2

[[email protected] ~]# vim /usr/local/tomcat8/bin/startup.sh

以上是关于一台centos7.2服务器安装两个tomcat应用服务的主要内容,如果未能解决你的问题,请参考以下文章

centos7+nginx负载均衡Tomcat服务

在一台电脑上运行两个或两个以上的tomcat

怎么在同一个Tomcat下部署两个相同的项目吗,请大神解决!!!

一台服务器上配置多个Tomcat的方法

一台服务器上部署两个tomcat

如何在一台机子上启动两个TOMCAT