CentOS7部署tomcat7多实例

tomcat安装简单,最主要是tomcat维护和jvm原理理解。


1、建立一个普通账号

[root@localhost opt]# groupadd gxm
[root@localhost opt]# useradd -g gxm gxm


2、安装java环境

[root@localhost ~]# wget https://download.oracle.com/otn/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm(备注:wget下载不了就手动下载)
[root@localhost ~]# rpm -ivh jdk-7u79-linux-x64.rpm

#备注:rpm安装的java包不需要加环境变量也可以。
[root@localhost ~]# vim /etc/profile
JAVA_HOME=/usr/java/jdk1.7.0_79
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH

[root@localhost ~]# source /etc/profile
[root@localhost ~]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)


3、安装tomcat7

[root@localhost ~]# cd /home/gxm
[root@localhost gxm]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.93/bin/apache-tomcat-7.0.93.zip
[root@localhost gxm]# unzip apache-tomcat-7.0.93.zip
[root@localhost gxm]# mv apache-tomcat-7.0.93 tomcat7-1
[root@localhost gxm]# chown -R gxm.gxm tomcat7-1
[root@localhost gxm]# chmod -R 700 tomcat7-1/


4、使用普通账号启动tomcat7

[root@localhost gxm]# su - gxm

[gxm@localhost ~]$ sh tomcat7-1/bin/startup.sh
Using CATALINA_BASE:   /home/gxm/tomcat7-1
Using CATALINA_HOME:   /home/gxm/tomcat7-1
Using CATALINA_TMPDIR: /home/gxm/tomcat7-1/temp
Using JRE_HOME:        /usr/java/jdk1.7.0_79
Using CLASSPATH:       /home/gxm/tomcat7-1/bin/bootstrap.jar:/home/gxm/tomcat7-1/bin/tomcat-juli.jar
Tomcat started.

[gxm@localhost ~]$ ps -ef | grep tomcat
gxm        4154      1  9 10:58 pts/0    00:00:02 /usr/java/jdk1.7.0_79/bin/java -Djava.util.logging.config.file=/home/gxm/tomcat7-1/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Dignore.endorsed.dirs= -classpath /home/gxm/tomcat7-1/bin/bootstrap.jar:/home/gxm/tomca7-1/bin/tomcat-juli.jar -Dcatalina.base=/home/gxm/tomcat7-1 -Dcatalina.home=/home/gxm/tomcat7-1 -Djava.io.tmpdir=/home/gxm/tomcat7-1/temp org.apache.catalina.startup.Bootstrap start
gxm        4190   4090  0 10:58 pts/0    00:00:00 grep --color=auto tomcat

[gxm@localhost ~]$ netstat -luntp | grep 8080
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::8080                 :::*                    LISTEN      4154/java
备注:停止脚本sh tomcat7-1/bin/shutdown.sh


5、如果开启了firewalld防火墙,则允许8080端口

[root@localhost ~]# firewall-cmd --zone=public --permanent --add-port=8080/tcp
[root@localhost ~]# firewall-cmd --reload


6、访问http://192.168.146.128:8080/验证

spacer.gif图片.png


7、多实例部署

[gxm@localhost ~]$ cp -a tomcat7-1 tomcat7-2
[gxm@localhost ~]$ cp -a tomcat7-1 tomcat7-3
[gxm@localhost ~]$ ll
-rw-r--r-- 1 root root 9739113 2月  17 01:39 apache-tomcat-7.0.93.zip
drwx------ 9 gxm  gxm     4096 2月  16 12:15 tomcat7-1
drwx------ 9 gxm  gxm     4096 2月  16 12:15 tomcat7-2
drwx------ 9 gxm  gxm     4096 2月  16 12:15 tomcat7-3

[gxm@localhost ~]$ vim tomcat7-1/conf/server.xml
Server port="7001" shutdown="SHUTDOWN"
  Listener className="org.apache.catalina.startup.VersionLoggerListener" /
    Connector port="17001" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" /
    Connector port="27001" protocol="AJP/1.3" redirectPort="8443" /
    
[gxm@localhost ~]$ vim tomcat7-2/conf/server.xml
Server port="7002" shutdown="SHUTDOWN"
  Listener className="org.apache.catalina.startup.VersionLoggerListener" /
    Connector port="17002" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" /
    Connector port="27002" protocol="AJP/1.3" redirectPort="8443" /
    
[gxm@localhost ~]$ vim tomcat7-3/conf/server.xml
Server port="7003" shutdown="SHUTDOWN"
  Listener className="org.apache.catalina.startup.VersionLoggerListener" /
    Connector port="17003" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" /
    Connector port="27003" protocol="AJP/1.3" redirectPort="8443" /
    
[gxm@localhost ~]$ sh tomcat7-1/bin/startup.sh
Using CATALINA_BASE:   /home/gxm/tomcat7-1
Using CATALINA_HOME:   /home/gxm/tomcat7-1
Using CATALINA_TMPDIR: /home/gxm/tomcat7-1/temp
Using JRE_HOME:        /usr/java/jdk1.7.0_79
Using CLASSPATH:       /home/gxm/tomcat7-1/bin/bootstrap.jar:/home/gxm/tomcat7-1/bin/tomcat-juli.jar
Tomcat started.

[gxm@localhost ~]$ sh tomcat7-2/bin/startup.sh
Using CATALINA_BASE:   /home/gxm/tomcat7-2
Using CATALINA_HOME:   /home/gxm/tomcat7-2
Using CATALINA_TMPDIR: /home/gxm/tomcat7-2/temp
Using JRE_HOME:        /usr/java/jdk1.7.0_79
Using CLASSPATH:       /home/gxm/tomcat7-2/bin/bootstrap.jar:/home/gxm/tomcat7-2/bin/tomcat-juli.jar
Tomcat started.

[gxm@localhost ~]$ sh tomcat7-3/bin/startup.sh
Using CATALINA_BASE:   /home/gxm/tomcat7-3
Using CATALINA_HOME:   /home/gxm/tomcat7-3
Using CATALINA_TMPDIR: /home/gxm/tomcat7-3/temp
Using JRE_HOME:        /usr/java/jdk1.7.0_79
Using CLASSPATH:       /home/gxm/tomcat7-3/bin/bootstrap.jar:/home/gxm/tomcat7-3/bin/tomcat-juli.jar
Tomcat started.

[gxm@localhost ~]$ ps x
   PID TTY      STAT   TIME COMMAND
  4090 pts/0    S      0:00 -bash
  5888 pts/0    Sl     0:02 /usr/java/jdk1.7.0_79/bin/java -Djava.util.logging.config.file=/home/gxm/tomcat7-1/conf/logging.properties -Djava.util.logging.manager=org.apac
  5912 pts/0    Sl     0:02 /usr/java/jdk1.7.0_79/bin/java -Djava.util.logging.config.file=/home/gxm/tomcat7-2/conf/logging.properties -Djava.util.logging.manager=org.apac
  5936 pts/0    Sl     0:02 /usr/java/jdk1.7.0_79/bin/java -Djava.util.logging.config.file=/home/gxm/tomcat7-3/conf/logging.properties -Djava.util.logging.manager=org.apac
  5951 pts/0    R+     0:00 ps x
  
[gxm@localhost ~]$ netstat -luntp | grep java
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::17001                :::*                    LISTEN      5888/java           
tcp6       0      0 :::17002                :::*                    LISTEN      5912/java           
tcp6       0      0 :::17003                :::*                    LISTEN      5936/java           
tcp6       0      0 :::27001                :::*                    LISTEN      5888/java           
tcp6       0      0 :::27002                :::*                    LISTEN      5912/java           
tcp6       0      0 :::27003                :::*                    LISTEN      5936/java


8、访问验证

http://192.168.146.128:17001/
http://192.168.146.128:17002/
http://192.168.146.128:17003/



转载于:https://blog.51cto.com/net881004/2371559

最新回复(0)
/jishuI6GAu9KsVS5EYFyTAvuYitP2Q90ipDlEP5Vp8GnudXo_3D4661833
8 简首页