Tutorial on installing and configuring Tomcat on Alibaba Cloud Server and adding external network access ports

Tutorial on installing and configuring Tomcat on Alibaba Cloud Server and adding external network access ports

Alibaba Cloud Server installs and configures Tomcat and adds external network access ports

It was not the Double Eleven recently, and I bought an Alibaba Cloud server to play with it. However, after configuring tomcat and adding security group rules, I could not access it no matter what, and telnet could not get through. Fortunately, after a period of hard work, I successfully solved the problem. The following is a record of how to solve the problem of deploying tomcat on Alibaba Cloud for the first time so that it can be accessed from the external network and add port mapping. As long as you follow the blogger's steps, there will generally be no problem.

1. JAVA environment configuration

1.1 Download JDK and Tomcat

First we need to install jdk and tomcat, the addresses have been prepared for you, see below:

Check the 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 there is x86_64, it is 64-bit, if not, it is 32-bit

For 64-bit Linux, download jdk-8u231-linux-x64.tar.gz, for 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. Unzip the jdk installation package. After unzipping, we can see a jdk1.8.0_231 folder

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

The unzipped file contains

insert image description here

2. Edit system environment variables:

Run vi /etc/profile to edit the system configuration file and set the Java environment variables.

Add at the bottom of the file:

Note: Punctuation and Paths

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

insert image description here

Save and exit

3. Reload the system configuration file

source /etc/profile

4. Check whether jdk is installed successfully: java -version

[root@root 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)
[root@root jdk1.8.0_231]#

1.2 Tomcat Configuration

1. Unzip the jdk installation package. After unzipping, we can see a folder called apache-tomcat-8.5.47

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

Unzip the directory:

insert image description here

2. After installing JDK, Tomcat does not need to be configured again, just start it directly

Command: ./bin/startup.sh

insert image description here

We have configured jdk and tomcat to access Alibaba Cloud Server. We need to set up port mapping here. Don't worry, it's all ready for you. Look below:

2. Firewall operation commands

Here we need to open the firewall, otherwise your server is very dangerous on the public network and needs a firewall to protect it.

#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 when turned off, running when 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 whether it is accessible

If you are like the blogger at the beginning and still cannot access after adding security group rules, you can temporarily close the firewall to see if you can access it. If you can access it, it means the port problem. If you cannot access it, it means Tomcat problem

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

#Start tomcat, in the tomcat directory bin/startup.sh
#Shut down tomcat, in the tomcat directory bin/shutdown.sh
#If the shutdown fails, you can kill the thread ps -ef | grep tomcat
kill -9 8080
#Access curl 127.0.0.1:8080
curl ip:8080

We can also use the ping and telnet commands under Windows to check whether the port and IP are accessible

Order:

# ping ip to check whether the IP is accessible (enter Alibaba Cloud IP)
ping 127.0.0.1 
# telnet to check whether the IP and port are accessible (enter Alibaba Cloud IP and port)
telnet 127.0.0.1 8080 

insert image description here

If it fails, please see below

3. Add security group rules

2.1 Adding Authorization Objects

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

insert image description here

2. Find the instance of our server, click More > Network and Security Group > Security Group Configuration

insert image description here

insert image description here

3. Click Configure Rules

4. Click Add Security Group Rule

insert image description here

5. Add security group rules

insert image description here

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

insert image description here

When we add successfully, at this time, we cannot access the tomcat external network port, we also need to add the server internal open port

4. Add Linux open ports

Just use the following command to access port 8080

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

5. Access tomcat

Finally, we enter our IP address and access is successful:

Summarize

The above is the tutorial on how to install and configure Tomcat on Alibaba Cloud Server and add an external network access port. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Alibaba Cloud Server Linux System Builds Tomcat to Deploy Web Project
  • Detailed steps for installing JDK and Tomcat on Linux cloud server (recommended)
  • Linux (CentOS7) installs Tomcat and sets Tomcat as a startup item (taking tomcat8 as an example)
  • Installation of Tomcat9 and deployment of web projects under Linux CentOS
  • CentOS 6 configures tomcat8 to start the script
  • Detailed tutorial on installing Tomcat8.5 in Centos8.2 cloud server environment

<<:  The use of mysql unique key in query and related issues

>>:  In-depth understanding of the use of the infer keyword in typescript

Recommend

Master the commonly used HTML tags for quoting content in web pages

Use blockquote for long citations, q for short ci...

A brief analysis of CSS :is() and :where() coming to browsers soon

Preview versions of Safari (Technology Preview 10...

Research on the Input Button Function of Type File

<br />When uploading on some websites, a [Se...

A detailed discussion of MySQL deadlock and logs

Recently, several data anomalies have occurred in...

More elegant processing of dates in JavaScript based on Day.js

Table of contents Why use day.js Moment.js Day.js...

Problems with Vue imitating Bibibili's homepage

Engineering Structure The project is divided into...

Implementation of Docker deployment of MySQL cluster

Disadvantages of single-node database Large-scale...

Linux editing start, stop and restart springboot jar package script example

Preface In the springboot configuration file, the...

How to use the MySQL authorization command grant

The examples in this article run on MySQL 5.0 and...

Summary of basic operations for MySQL beginners

Library Operations Query 1.SHOW DATABASE; ----Que...

Convert psd cut image to div+css format

PSD to div css web page cutting example Step 1: F...

js realizes the magnifying glass function of shopping website

This article shares the specific code of js to re...