A solution in linux that cannot be accessed by the browser after tomcat is started

  • 2020-06-23 02:32:11
  • OfStack

preface

To start or turn off the tomcat service, go to the bin path in the tomcat installation directory. Of course, you don't need to turn your computer off.

Recently, however, a problem was found after startup: the Centos server, local and server ip ping were normal (native ping server, server ping local), but after deployment of tomcat on the server, the native was unable to access port 8080 of server tomcat through the browser.

For example, the server public network ip is 123.123.123.123, the default port after starting tomcat is 8080, and the default page of tomcat cannot be accessed through 123.123.123.123:8080.

Verify that tomcat is enabled


$ ps -ef|grep tomcat

Console output indicating that tomcat is on


root  1428  1 0 Dec08 ?  00:02:16 /usr/local/java/jdk1.8.0_152/jre/bin/java -Djava.util.logging.config.file=/usr/local/java/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -classpath /usr/local/java/tomcat8/bin/bootstrap.jar:/usr/local/java/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/java/tomcat8 -Dcatalina.home=/usr/local/java/tomcat8 -Djava.io.tmpdir=/usr/local/java/tomcat8/temp org.apache.catalina.startup.Bootstrap start
root  4932 4069 0 09:16 pts/0 00:00:00 grep --color=auto tomcat

If tomcat is not enabled, it is enabled through tomcat's ES32en. sh command, and you can directly enter the path of the file.


$ /usr/local/java/tomcat8/bin/startup.sh

Console output:


[root@izbp109iqt20o2h63tpcuvz ~]# /usr/local/java/tomcat8/bin/startup.sh 
Using CATALINA_BASE: /usr/local/java/tomcat8
Using CATALINA_HOME: /usr/local/java/tomcat8
Using CATALINA_TMPDIR: /usr/local/java/tomcat8/temp
Using JRE_HOME:  /usr/local/java/jdk1.8.0_152/jre
Using CLASSPATH:  /usr/local/java/tomcat8/bin/bootstrap.jar:/usr/local/java/tomcat8/bin/tomcat-juli.jar
Tomcat started.

Tomcat started. Indicates that tomcat has started successfully!

Configure the firewall

Edit firewall configuration


$ vi /etc/sysconfig/iptables

Add port 8080 firewall to allow access.


*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited

Attention! Critical: the port configuration must be above the following configuration, not below.


-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited

Enter i to start editing,ESC to end editing,WQ to save and exit.

Restart the firewall


$ service iptables restart

Then you can access the 123.123.123.123:8080 on the machine through the browser and see the default welcome page of tomcat.

conclusion

Reference links: http: / / blog csdn. net/itzhangdaopin/article/details / 62044620


Related articles: