Alibaba Cloud Server deploys Java Web project and connects to MySQL database

( Only to commemorate the first learning blog in my life ) A
while ago, I took a small JavaWeb project and released it to the cloud server as needed. At the same time, in order to be more familiar with the entire process of JavaWeb development, I bought an Alibaba Cloud server to practice. Practice hands. In the previous exercises, I used my own computer as the server. Other people who are not under the same local area network can not access the local project. I thought it would be difficult to publish the project to the Linux server. In fact, after contacting it, I found it very simple. Install the same (JDK, Mysql, Tomcat) environment on the Alibaba Cloud server as the local machine (it’s nothing more than Linux, which has less visual graphical interface than Windows system), and then package the project on the server. Then I will go through the whole process Show it again, starting with purchasing Alibaba Cloud servers...

1. Purchase Alibaba Cloud Server

Enter Ali cloud the official website , register Login

  1. Search "Alibaba Cloud Server ECS" and click to buy
    Insert picture description here
    Insert picture description here
     

  2. Choose custom purchase  , choose server configuration according to your own needs;

It is best to choose a region close to your customers to reduce network latency and increase access speed. Insert picture description here
Shared instance refers to an entry-level server, suitable for basic configuration such as website building and testing
Insert picture description here
 

  1. Select  system mirror

It is recommended to choose the CentOS (Linux) system image, because Linux abandons the graphical interface and uses the command line to operate, and the performance can be more fully utilized. [Note: Non-Aliyun Linux]
Under the premise of determining the environmental requirements, you can also directly select more complete mirrors from the mirror market. These mirrors are pre-installed with the basic environment required for operation, saving time and effort.
Insert picture description here
There is a system image (Tomcat9, jdk1.8, MySQL5.6) pre-installed with the environment required for running a complete JavaWeb project. The system version is recommended to choose CentOS7 series, 7.3 and above.
Insert picture description here
Click " Use ", click " Next " to configure the network and security group



 

  1. Perform  network and security group  configuration

Choose the bandwidth according to your needs. I choose the default minimum Insert picture description here
security group rule. After the purchase is successful, you need to open the corresponding port in the console, and then set it later.
Insert picture description here
Click Next to proceed to system configuration.

 

  1. Perform  system configuration

Set a login password, don’t forget it, if you forget it, you can retrieve it or reinstall the system, the steps are the same, you need to connect later
Insert picture description here

Instance name and description are set according to personal preferenceInsert picture description here

  1. The group setting  is not filled by default, confirm the order and the purchase is successful!

Click on the console on the homepage of Alibaba Cloud official website, Insert picture description here
click on the cloud server ECS andInsert picture description here
click on the instance on the left , you can see the Alibaba Cloud server instance you just purchased
Insert picture description here

 

Two, configure the security group

Click "Manage" on the right side of "Instance",
Insert picture description here
click "Security Group for this instance " on the left, and then click "Configure Rules" on the right
Insert picture description here

 

  1. Inbound security group configuration

Then click in the inbound direction to quickly create a security group, and see if the check I ticked must be marked, otherwise the port will not be connected.
Insert picture description here
After adding, you need to add two more! Two! Two security groups
Insert picture description here
Insert picture description here


 

  1. Outbound security group configuration

Insert picture description here

Three, connect to Alibaba Cloud server

  1. Download Xshell (connect to remote server host via network)

Open Xshell -> New connection

Insert picture description here
Insert picture description here
Fill in the login user name (default root) and password you set when you purchased the server
Insert picture description here
Insert picture description here
. Prompt for successful connection. Insert picture description here
Enter java -version to see the built-in jdk version.
Insert picture description here
MySQL.
Enter rpm -qa | grep mysql to see if the database is installed.
Insert picture description here
Enter mysql -u Root -p enter the password and log in to the database (Linux system is very cute, it hides the password, don't change the keyboard)
Insert picture description here
Use the local database visualization tool Navicate to connect to the MySQL database of Alibaba Cloud Server
Create a new connection -> Alibaba Cloud Database MySQL Edition
Insert picture description here
General settings (host connection port, username and password)
Insert picture description here
SSH channel settings (Alibaba Cloud server ip, port and username, password)
Insert picture description here
Click OK, double-click the connection name on the left to open the connection, you can manually create a database and table for the cloud server , And operating data from the cloud server database
Insert picture description here



















 

2. Verify  Tomcat

Enter the public network ip+:8080 of the Alibaba Cloud server you purchased in the address bar of the local browser, and you will see the following Tom Cat page, indicating that your Alibaba Cloud server public network ip is publicly accessible and tomcat is running normally
Insert picture description here
3. Download Xftp (can Transfer files between Linux and Windows)  deploy JavaWeb project to Alibaba Cloud server
 

In the eclipse compiler, export the JavaWeb project as a war package (WAR file format)

Right-click on the project——>Export, select WAR file,
Insert picture description here
select the export address of the war package, and uncheck the specific Tomcat operating environment.
Insert picture description here
Open the Xftp tool downloaded earlier, the new connection
Insert picture description here
is successful, the left side is the computer file of the machine, the right Linux system files on the side (drag and drop to transfer files)
Insert picture description here





 

In the Linux system interface on the right, browse to the /usr/local/src/apache-tomcat-9.0.1/webapps directory, and directly drag the WAR package exported from the local JavaWeb project to the webapps directory on the right (here No need to unzip, tomcat will automatically unzip for us)
Insert picture description here
After the above, the entire project deployment process has been completed
 

Fourth, run the project

Enter ip+:8080+ project name (the designated jsp page) in the address bar of the local browser to access the JavaWeb project.
Insert picture description here
We can deploy JavaWeb, Html web pages, App, etc. on the server.
 

Congratulations! So far, you have successfully deployed the web project to the Alibaba Cloud server!

5. About how to remove the ":8080" in the address

  1. Enter /usr/local/src/apache-tomcat-9.0.1/conf in the cnof directory of tomcat in the Xftp tool, right-click sever.xml and open it with notepad
    Insert picture description here2. Modify a port information
    Insert picture description here3.  Restart tomcat
    Restart command under Linux : Systemctl restart tomcat.service
    or go to the bin directory of tomcat, use the tomcat command to restart tomcat


     
  2. Without port 8080 , visit again
    Insert picture description here

Guess you like

Origin blog.csdn.net/wx_15323880413/article/details/108506048