修改tomcat端口号

2022-03-09 12:26:10 浏览数 (1)

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

一、只启动一个tomcat的情况

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

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

找到以下代码

代码语言:javascript复制
<Connector port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" />

2、修改端口号

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

代码语言:javascript复制
<Connector port="8099" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" />

3、重启tomcat生效

代码语言:javascript复制
[root@localhost tomcat]# netstat -luntp|grep 80tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      26201/javatcp6       0      0 :::8009                 :::*                    LISTEN      26201/javatcp6       0      0 :::8080                 :::*                    LISTEN      26201/javatcp6       0      0 :::80                   :::*                    LISTEN      850/httpd[root@localhost tomcat]# ./bin/shutdown.shUsing CATALINA_BASE:   /usr/share/tomcatUsing CATALINA_HOME:   /usr/share/tomcatUsing CATALINA_TMPDIR: /usr/share/tomcat/tempUsing JRE_HOME:        /usr/share/jdkUsing CLASSPATH:       /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar[root@localhost tomcat]# ./bin/startup.shUsing CATALINA_BASE:   /usr/share/tomcatUsing CATALINA_HOME:   /usr/share/tomcatUsing CATALINA_TMPDIR: /usr/share/tomcat/tempUsing JRE_HOME:        /usr/share/jdkUsing CLASSPATH:       /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jarTomcat started.[root@localhost tomcat]# netstat -luntp|grep 80tcp6       0      0 :::8099                 :::*                    LISTEN      5163/javatcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      5163/javatcp6       0      0 :::8009                 :::*                    LISTEN      5163/javatcp6       0      0 :::80                   :::*                    LISTEN      850/httpd[root@localhost tomcat]#

二、当有多个tomcat时

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

1、修改Connector port

代码语言:javascript复制
116 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

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

代码语言:javascript复制
116 <Connector port="18009" protocol="AJP/1.3" redirectPort="8443" />

2、修改Server port

代码语言:javascript复制
 22 <Server port="8005" shutdown="SHUTDOWN">

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

代码语言:javascript复制
 22 <Server port="18005" shutdown="SHUTDOWN">

3、同样重启tomcat

代码语言:javascript复制
[root@dlocalhost tomcat]# netstat -luntp|grep 80tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      26201/javatcp6       0      0 :::8009                 :::*                    LISTEN      26201/javatcp6       0      0 :::8080                 :::*                    LISTEN      26201/javatcp6       0      0 :::80                   :::*                    LISTEN      850/httpd[root@localhost tomcat]# ./bin/shutdown.shUsing CATALINA_BASE:   /usr/share/tomcatUsing CATALINA_HOME:   /usr/share/tomcatUsing CATALINA_TMPDIR: /usr/share/tomcat/tempUsing JRE_HOME:        /usr/share/jdkUsing CLASSPATH:       /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar[root@localhost tomcat]# ./bin/startup.shUsing CATALINA_BASE:   /usr/share/tomcatUsing CATALINA_HOME:   /usr/share/tomcatUsing CATALINA_TMPDIR: /usr/share/tomcat/tempUsing JRE_HOME:        /usr/share/jdkUsing CLASSPATH:       /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jarTomcat started.[root@localhost tomcat]# netstat -luntp|grep 80tcp6       0      0 :::18009                :::*                    LISTEN      7101/javatcp6       0      0 :::8099                 :::*                    LISTEN      5163/javatcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      5163/javatcp6       0      0 :::8009                 :::*                    LISTEN      5163/javatcp6       0      0 :::80                   :::*                    LISTEN      850/httpdtcp6       0      0 127.0.0.1:18005         :::*                    LISTEN      7101/java[root@localhost tomcat]#

0 人点赞