A tutorial on how to install and configure Tomcat to add an external access port to Alibaba cloud server


Alicloud server installation and configuration Tomcat add external network access port

Recently, double eleven is not. I bought an alicloud server to play with, but after Tomcat is configured and security group rules are added, I can’t get access to telnet It can’t pass either. Fortunately, it’s better to solve the problem successfully after a while of forgetting to eat and sleep. Here’s how to solve the problem of deploying Tomcat on Alibaba cloud for the first time. You can access the Internet and add port mapping. As long as you follow the steps of the blogger, there is no problem.

1、 Java environment configuration

1.1 download of JDK and Tomcat

First of all, we need to install JDK and Tomcat. The addresses have been prepared for you

View Linux version: uname – A

# uname -a
Linux root 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

If you have x86_ 64 is 64 bits, no is 32 bits

Download jdk-8u231-linux-x64 tar.gz , 32-bit download jdk-8u231-linux-i586 tar.gz

JDK download address: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Tomcat download address: http://tomcat.apache.org/download-80

1.2 JDK configuration

1. Decompress the JDK installation package. After decompressing, we can see a jdk1.8.0_ Folder of 231

tar -zxvf jdk-8u231-linux-x64.tar.gz

The extracted file contains


2. Edit system environment variables:

Execute VI / etc / profile to edit system configuration file and set Java environment variables

Add at the bottom of the file:

Note: punctuation and path

export JAVA_HOME=/usr/local/java/jdk1.8.0_231
export PATH=$PATH:$JAVA_HOME/bin


Save exit

3. Reload system configuration file

source /etc/profile

4. Check if JDK is installed successfully: Java – version

[[email protected] jdk1.8.0_231]# java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
[[email protected] jdk1.8.0_231]# 

1.2 Tomcat configuration

1. Unzip the JDK installation package. After unzip, we can see a folder of apache-tomcat-8.5.47

tar -zxvf apache-tomcat-8.5.47.tar.gz

Unzip Directory:


2. After JDK is installed, Tomcat can be started directly without configuration



We have configured JDK and Tomcat to access. Here, we need to set port mapping for Alibaba cloud server. Don’t worry, we are ready for you. Brother, look below:

2、 Firewall operation command

Here we need to open the firewall, otherwise your server on the public network is very dangerous, need firewall to protect

#Stop firewall
systemctl stop firewalld.service 
#Open firewall
systemctl start firewalld.service
#Disable firewall startup
systemctl disable firewalld.service 
#View the default firewall status (not running is displayed when it is turned off, and running is displayed when it is turned on)
firewall-cmd --state

But when it is turned on, this error may be reported

Failed to start firewalld.service: Unit firewalld.service is masked.

Enter the following command:

systemctl unmask firewalld.service

2、 Check if it is accessible

If you are just like the blogger at the beginning, adding security group rules can’t be accessed, you can temporarily turn off the firewall to see if you can access it. If you can access it, it indicates the port problem. If you can’t access it, it indicates the Tomcat problem

After starting tomcat, we can use curl command to check whether the port and IP are accessible

#Start Tomcat under the Tomcat directory
#Close Tomcat and put it in the Tomcat directory
#If the shutdown fails, the thread can be killed
ps -ef | grep tomcat
kill -9 8080
curl ip:8080

We can also use Ping and telnet commands under windows to check whether the port and IP can be accessed


#Ping IP to check whether the IP can be accessed (enter alicloud IP)
#Telnet to check whether the IP and port can be accessed (enter alicloud IP and port)
telnet 8080


If you fail, look down

3、 Add security group rule

2.1 add authorization object

1. Log in to alicloud, find the cloud server, and click


2. Find the instance of our server and click more > network and security group > security group configuration



3. Click configuration rules

4. Click add security group rule


5. Add security group rule


5. After adding successfully, the data we just added will appear in the list


When we add successfully, at this time, we can not access the Tomcat external network port, we also need to add the server internal open port

4、 Add Linux open port

Just use the following command to access port 8080

/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

5、 Visit Tomcat

Finally, we input our IP address, and the access is successful


The above is Xiaobian’s introduction to the installation and configuration of Alibaba cloud server Tomcat to add the Internet access port tutorial. I hope it can help you. If you have any questions, please leave me a message and Xiaobian will reply you in time. Thank you very much for your support to developer!
If you think this article is helpful to you, please reprint, please indicate the source, thank you!

Recommended Today

Video compatibility in wechat

1. In line properties of video tag SRC: URL of video Poster: Video cover, no picture displayed when playing Preload: preload Autoplay: autoplay Loop: loop playback Controls: browser’s own control bar Width: video width Height: video height style=”object-fit:fill” /Adding this style will make the Android / Web video full screen in wechat. If it is […]