一台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

[root@bogon ~]#  tar zxf apache-tomcat-8.0.47.tar.gz

[root@bogon ~]#  mv apache-tomcat-8.0.47 /usr/local/tomcat

[root@bogon ~]#  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变量是否生效

[root@bogon ~]# source /etc/profile

[root@bogon ~]# echo $PATH

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

查看tomcat版本及信息

[root@bogon ~]# 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

[root@bogon ~]# chmod +x /usr/local/tomcat/bin/*.sh

[root@bogon ~]# /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端口通过

[root@bogon ~]# firewall-cmd --add-prot=8080/tcp

4. 部署tomcat2

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

[root@bogon ~]# /usr/local/tomcat8/

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

[root@bogon ~]# chmod +x /usr/local/tomcat/bin/*.sh

[root@bogon ~]#  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 红色字体都需要改

9005" shutdown="SHUTDOWN">

  

  

  

  

  

  

 

  

    

              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" />

  

  

    9080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

    9009" protocol="AJP/1.3" redirectPort="8443" />

 

    

      

        

               resourceName="UserDatabase"/>

      

 

      

            unpackWARs="true" autoDeploy="true">

        

               prefix="localhost_access_log" suffix=".txt"

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

 

      

    

  

修改bin/shutdown.sh exec "$PRGDIR"/"$EXECUTABLE" stop "$@"添加红色字体

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 "$@"

修改bin/startup.sh exec "$PRGDIR"/"$EXECUTABLE" stop "$@"添加红色字体

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

[root@bogon ~]# vim /usr/local/tomcat8/bin/startup.sh