Deploy Java's Web project website to the server (understand it in half a day)

1 Public IP and Private IP

1.1 Access to website process steps DNS domain name resolution

When we open the browser and enter the website we want, everything we need is displayed in front of us. Have we ever thought about how this all happened?
First of all, when you enter a website, your browser will first use the domain name to find its corresponding IP address, because the domain name is for people to see, and the machine can only see the IP address.

We will use a server, the professional term is DNS. So what is DNS?
Dns is a public service on the Internet, specifically used to help us find the IP address behind the domain name. In fact, when we register a domain name, where does your domain name go? Where is the persistence? Of course, the domain name will be stored on the DNS server. In this way, when you need to query the domain name information, DNS will play its role. It will tell you the address of the website you are looking for.

Connection
Assuming it is a normal request and the server resources are sufficient, the server will also return a packet to you, telling you that you can connect to me. The browser then receives this packet and sends its own confirmation packet.

Response
After completing the connection request, data can be transferred normally between the client and the server. The server parses what you need based on your data request body and request headers. It may be a file or data in a database. The server sends this process to the browser, we call it a response.

Parse
the information returned by the browser, disassemble what the browser needs, and display this information directly. For example, ordinary users cannot understand the json data packet you receive. At this time, you need to use js and css , html parses it out to various data that can be displayed on the page

The story behind the technology, what exactly happens when we visit a website

1.2 Public IP and Private IP

Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
The mobile phones and computers we usually use all have private network IPs. When requesting messages, they are converted to public network IPs through routing, and then Baidu is accessed. Baidu returns it to the router, and the router returns it to the private network IP.
If we build a server on the private IP of our own computer, only people on your private network can access it, because your IP can only be found on the private network. Someone from outside accesses your IP address and cannot find the IP. Because there is no such IP in the public network, the network cannot find it. Therefore, our own computers can access the Internet, but we cannot build websites for others to visit.

IP4 cannot allow each device to have a public IP, but IP6 can allow each device to have a public IP. Therefore, after the development of IP6 technology, everyone's device can have a public IP. Currently, it cannot have a public IP. The reason is that there are too few IP4 addresses, resulting in insufficient resources for everyone to share.

What is the difference between public IP and private IP - Ask Question

The following are some basic knowledge of IP

Public network and intranet are two ways to access the Internet. Public network access method: The IP address obtained by the computer on the Internet is a non-reserved address on the Internet. Computers on the public network and other computers on the Internet can access each other at will.

Class A: 1.0.0.0 to 127.255.255.255 are mainly allocated to large networks with a large number of hosts and a small number of LAN networks.

Category B: 128.0.0.0 to 191.255.255.255 Generally used by large international companies and government agencies

Class C: 192.0.0.0 to 223.255.255.255, used for general small companies, campus networks, research institutions, etc.

Class D: 224.0.0.0 to 239.255.255.255 are used for special purposes, also called broadcast addresses

Class E: 240.0.0.0 to 255.255.255.255 temporarily reserved

Among the above types of addresses, the following are used as private addresses

Class A: 10.0.0.0 to 10.255.255.255

Class B: 172.16.0.0 to 172.31.255.255

Class C: 192.168.0.0 to 192.168.255.255

Among them, 127.0.0.0 to 127.255.255.255 are the system loopback addresses.

1.2.1 The cloud server is automatically equipped with a public IP address

How to apply for a public IP (fixed IP)?
You can go to major server providers to apply for a server.

1For example, Alibaba Cloud, Tencent Cloud, Yiyun, etc.

2Select the server configuration and confirm the protocol.

3. After the server is deployed successfully, the server operator will give you a public network IP address and a private network IP address. The public network can be accessed from the external network, and the private network can be accessed from the internal network.

1.2.2 Public IP configured by the server

DHCP (Dynamic Host Configuration Protocol) Dynamic Host Configuration Protocol is used to dynamically allocate IP addresses to save limited IP address resources.

First, there is a DHCP server waiting to respond to IP address requests. This server stores a batch of valid IP addresses for allocation. Once the application is received, the DHCP server will allocate an IP address to the legitimate requester. This IP address has a validity period, with a default value of 3 days. By default, when the validity period is more than half, the client needs to resubmit the application for extension. If the DHCP server goes down at this time, the client still has half the time to wait for the server to recover.

When the client shuts down normally, the DHCP server will reclaim the IP address. If the client interrupts the network connection for various reasons and does not restore the connection within the validity period, the DHCP server will reclaim the IP address after the IP expires. In this way, IP multi-machine sharing is realized, which is the use of dynamic IP addresses mentioned in the question.

Usually the DHCP server will record the client's physical address, that is, the MAC address (Media Access Control), which is the globally unique address of each network card. The client applies for an IP address by submitting its own MAC address. If the same MAC address submits an IP address application next time, the server will try to allocate the same IP address as last time, provided that this IP address has not been assigned to other clients.

The principle of using DHCP is that the number of clients online at the same time cannot exceed the number of valid IP addresses.

1.2.3 How to apply for a public IP for a private server?

Most areas now have IPv6, which can fully enable remote access. You only need to find a master who installs the modem to change the optical modem to bridge mode, and the following devices can be accessed from the public network.

If it is IPv4, you may have to ask an operator to set up a dedicated line. Home broadband is no longer available on the public network.

If you just want to play and don’t want to bother, it is recommended to use intranet penetration such as Ngork/Frp.

NAT (Network Address Translation) is network address translation. It realizes mutual conversion between LAN IP addresses and WAN addresses, converts WAN IP addresses into a large number of LAN IP addresses, and reduces the occupation of public network IP addresses.

The most typical application of NAT is: in a local area network, only one computer needs to be connected to the Internet, and NAT can be used to share the Internet connection so that other computers in the local area network can also access the Internet.

Using the NAT protocol, computers on the LAN can access computers on the Internet, but computers on the Internet cannot access computers on the LAN.

Configure the public IP address of the server (how to set the public IP address of the server) - Weiqi Network

1.3 Sometimes there is no need to write the port number when accessing the website

Generally, 80 is used as the access port of the web server and is the default port of the http protocol. When entering the website, the browser (not IE) has already entered the protocol for you.
Insert image description here

2 Web project deployment and release (understand in half an hour)

Deployment of web projects to the cloud server is the same as on your computer, that is, first configure the jdk, tomcat and other environments on the server, and then directly start the compiled project. We use localhost to access locally, and the cloud server uses public IP to access.

All JAVAWeb project deployments follow the following three steps:
Insert image description here

Case 1: Web project (Vue) deployed to Alibaba Cloud server [Super detailed, Windows version]

Case 2: Detailed Tutorial on Alibaba Cloud Deployment of Java Web Project_Hejincheng9's Blog-CSDN Blog

Case 3: How to deploy Java web projects to Alibaba Cloud servers_m0_63984008's blog-CSDN blog

Case 4: JavaWeb project deployment and online operation process (cloud server + pagoda panel + Tomcat)_Jeff_Xxxx's blog-CSDN blog_How to deploy and go online web projects

3 Java SpringBoot project deployment and release

Case 1: Springboot project deployed to Alibaba Cloud in practice_trainsun's blog-CSDN blog_abcputty deploys springboot

4 cases of deployment by individuals (very simple)

Deploying a server program is very simple, just 4 steps:

  1. You can purchase a cloud server with a public IP address from Alibaba Cloud or Tencent Cloud;
  2. Install jdk software;
  3. Transfer the jar package and resources to the Linux system of the cloud server through xshell and xftp;
  4. Then start the jar package and open the server to access it.

The whole process is the same as our local one. There are two ways to run ordinary web programs:

  1. The java -jar command runs the jar package
  2. You can also run programs by directly running the idea in the Linux system on the cloud server.

In fact, there is no profound mystery. Just start this program, then listen to the port, and return the specified html file. This is the principle of the web program. We usually use our own computer to run it and the outside world cannot access it because our computer has a LAN IP, not a public IP. The cloud server has a public IP, so just use the public IP.

Directions for improvement:
1. You can use tomcat to implement the program, and you can write a lot less content;
2. Purchase a domain name and connect the domain name with the IP.
3 Realize the transmission of pictures. Currently, the pictures are not displayed.

4.1 Purchase Tencent Cloud Server (new users have a 1-month free trial period)

Just buy it directly. First select the product type, then select the configuration, and finally pay for it directly.

Tencent Cloud Server: https://cloud.tencent.com/act/free/enterprise?from=17591

Insert image description here

After selecting the experience, a pop-up interface will appear for you to choose the configuration. Just choose the Centos7linux system. It’s simple. Then you get to the console. The console controls your server. Each instance is a server.
The picture on the west side shows the display behind the console.
Insert image description here

4.2 Install Linux jdk (very simple)

Installing jdk and idea on linux (CentOS7) _Chongchong 's blog-CSDN blog_linuxidea setting jdk

Insert image description here

4.3 Idea packages the jar package and transfers the jar package and resources to the Linux cloud server

4.3.1 idea packaging jar package

To package the jar package, you only need to package the .class file into the jar package. There is no need to package the configuration file. Just look at the two links below for packaging.

Reference 1: Detailed graphic tutorial on using IDEA to build jar packages_java_Script Home

Reference 2: IntelliJ idea novice installs and packages the first jar package_bilibili_bilibili

Insert image description here
Insert image description here

4.3.2 xshell transfer files

After purchasing the linxu cloud server, choose a password to log in and set the password yourself. Then use xheel to ssh, log in with your account and password, and remotely control the Linux server.
The operation is the same as usual.

4.4 Start the jar package program

Three steps:
1. First open port 8080;
2. Start the jar package;
3. Access via browser.

Direct access to the website failed. I tried pinging the public IP and found that I could ping. I found the reason: I found
in the firewall that port 8080 was not allowed to access. I set it up and opened port 8080, and then it worked.

Insert image description here
Insert image description here
Then the browser can access it, but there is a temporary problem with the image and it cannot be accessed.
Insert image description here
As soon as the browser accesses, access information will appear in the background
Insert image description here

Guess you like

Origin blog.csdn.net/xiaotiig/article/details/128610094