修改tomcat端口号

tomcat服务器的默认端口号是8080

一、只启动一个tomcat的情况

当我们不想使用8080端口,需要修改为其他端口时,我们可以:

1、打开tomcat安装目录下的conf目录,找到server.xml文件。

找到以下代码

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

2、修改端口号

上面的8080就是tomcat的对外访问端口,
我们将他修改为其他端口,但是要避免与系统的端口号冲突,选用一个没有使用过的端口号,然后保存退出
如图将端口号修改为8099

<Connector port="8099" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

3、重启tomcat生效

[root@localhost tomcat]# netstat -luntp|grep 80
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      26201/java
tcp6       0      0 :::8009                 :::*                    LISTEN      26201/java
tcp6       0      0 :::8080                 :::*                    LISTEN      26201/java
tcp6       0      0 :::80                   :::*                    LISTEN      850/httpd
[root@localhost tomcat]# ./bin/shutdown.sh
Using CATALINA_BASE:   /usr/share/tomcat
Using CATALINA_HOME:   /usr/share/tomcat
Using CATALINA_TMPDIR: /usr/share/tomcat/temp
Using JRE_HOME:        /usr/share/jdk
Using CLASSPATH:       /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar
[root@localhost tomcat]# ./bin/startup.sh
Using CATALINA_BASE:   /usr/share/tomcat
Using CATALINA_HOME:   /usr/share/tomcat
Using CATALINA_TMPDIR: /usr/share/tomcat/temp
Using JRE_HOME:        /usr/share/jdk
Using CLASSPATH:       /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@localhost tomcat]# netstat -luntp|grep 80
tcp6       0      0 :::8099                 :::*                    LISTEN      5163/java
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      5163/java
tcp6       0      0 :::8009                 :::*                    LISTEN      5163/java
tcp6       0      0 :::80                   :::*                    LISTEN      850/httpd
[root@localhost tomcat]#

二、当有多个tomcat时

我们还需修改上面文件的其他两个地方

1、修改Connector port

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

修改为其他端口,注意避免端口冲突,如下:

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

2、修改Server port

 22 <Server port="8005" shutdown="SHUTDOWN">

同样将server port的端口修改为其他端口,注意避免端口冲突,这里我选用18005

 22 <Server port="18005" shutdown="SHUTDOWN">

3、同样重启tomcat

[root@dlocalhost tomcat]# netstat -luntp|grep 80
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      26201/java
tcp6       0      0 :::8009                 :::*                    LISTEN      26201/java
tcp6       0      0 :::8080                 :::*                    LISTEN      26201/java
tcp6       0      0 :::80                   :::*                    LISTEN      850/httpd
[root@localhost tomcat]# ./bin/shutdown.sh
Using CATALINA_BASE:   /usr/share/tomcat
Using CATALINA_HOME:   /usr/share/tomcat
Using CATALINA_TMPDIR: /usr/share/tomcat/temp
Using JRE_HOME:        /usr/share/jdk
Using CLASSPATH:       /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar
[root@localhost tomcat]# ./bin/startup.sh
Using CATALINA_BASE:   /usr/share/tomcat
Using CATALINA_HOME:   /usr/share/tomcat
Using CATALINA_TMPDIR: /usr/share/tomcat/temp
Using JRE_HOME:        /usr/share/jdk
Using CLASSPATH:       /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@localhost tomcat]# netstat -luntp|grep 80
tcp6       0      0 :::18009                :::*                    LISTEN      7101/java
tcp6       0      0 :::8099                 :::*                    LISTEN      5163/java
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      5163/java
tcp6       0      0 :::8009                 :::*                    LISTEN      5163/java
tcp6       0      0 :::80                   :::*                    LISTEN      850/httpd
tcp6       0      0 127.0.0.1:18005         :::*                    LISTEN      7101/java
[root@localhost tomcat]#
上一篇