The whole process of putting the Spring boot project on Tencent Cloud

1. Preparations

  • 1. You need to purchase a Tencent cloud server (students in school have a discount, here is the address for new users to experience for one month for free: https://cloud.tencent.com/act/free)
  • 2. Need to develop a springboot background project (jar package packaged through maven)
  • 3. You need to purchase a domain name and file it.
  • 4. You need to configure your server environment jdk, mysql (explained below)

By default, you have done all the above preparations. Now let's learn how to deploy the background project to the server so that everyone can access your server.

One, first create a springboot (java project)

1. Create a springboot project and choose jdk1.8

 

2. Fill in the package name, select configuration, and keep the default

3. Add some project dependencies, using the latest springboot version 2.1.7

 4. Project name, project directory settings. can keep the default

5. Import dependencies, the following two methods are available.

6. Implement a simple background data interface

 

7. Run the project locally

8. The sign of successful operation, the console log in run shows that the project port is 8080

 

2. Project packaging

1. Package the SpringBoot project

 

2. Successfully packaged

 

You can pull the jar package down to any position.

3. Modify the name of the jar (or not change the name)

3. Login to the server environment

1. First buy a Tencent cloud server (lightweight server is used here) or rent one (students have discounts)

Then after buying it is such an interface

 2. Then click into the server

 3. Then reset the password first to log in to the Linux system later. After the reset, the system will restart and wait for two minutes.

 

 4. Then you can set up a firewall (security group, that is, open ports), which is very important, otherwise the server cannot be accessed

5. Click Add Rule, here we add two ports, one port 8081 and one port 3306 (database port)

6. After that, we started to log in to the Tencent Cloud Linux system (there are three login methods). I choose VNC to log in, or use XShell software to log in. Anyway, we are connected to the Linux system. Click Remote Login, and there is a VNC login

 

 7. The interface after entering is like this

8. Then enter the default user name (root) and press Enter. Enter the password you just reset to log in. (Note that the password will not be displayed and will always be blank) This means that you have logged in.

 Our java project must have jdk to run on the server

Four. Install jdk on linux server

  • 1. Use yum to install jdk1.8, very simple yum search java|grep jdk to view the version of jdk in the yum library

 yum -y install java-1.8.0-openjdk* install jdk8

 Wait patiently for the installation of jdk, about 2 minutes, the following logo appears, which means the installation is successful

 

Check whether jdk is successfully installed Enter java -version in the command line and the following mark appears, you can see our jdk version 1.8.0_222

5. Upload the jar package to the server

In the fourth step, we have successfully installed jdk on the linux server, and the next step is to find a way to transfer qcl80.jar to the server. Some students may ask, you deploy the server, don't you install tomcat in the linux server? In fact, the jar package we developed with springboot already has built-in tomcat. So we don't need to deploy tomcat anymore, just upload the qcl80.jar file to the server, and then start it with the java command.

We upload files to the Linux server with the following software (you can also use other ftp tools such as Xftp)

 You only need to go to Baidu to download the installation package corresponding to your computer system and install it.

How to upload files to server using FileZilla.

1. Open the FileZilla software and connect to the server

 2. Go to the root directory of the server to see

 3. Upload the file to the home file. If there is no home file in the root directory of the father, you can create it yourself.

 At this point, you have successfully uploaded qcl80.jar to the server. Here's how to start our project on the server.

6. Start the java project in the server

1. First, repeat the fourth step above to log in to the server. Then enter in the server

cd / #Used to return to the server root directory

ls #Display those files in the current root directory

cd home #Enter the home file

ls #Display the sub-files in the home file, you can see our qcl80.jar

2. Start the java project

java -jar qcl80.jar (this command cannot be accessed after exiting)

So usually use this command: nohup java -jar xxxxx.jar& (run the jar package without hanging up)

After startup, it can be accessed on the server.

If you want to run other jar packages, execute the following commands in order

ps aux|grep xxxxxxx.jar to stop the running jar package

netstat -nlp | grep 8080 View the operation of a port (8080)

kill -9 30768 kills a running port process (PID 30768)

Then enter the directory where the jar package is located and run

 7. Server binding domain name

Before we do domain name binding, you need to register a domain name by yourself. For example, the domain name I registered is: "www.xxxx.top". Here I still use Tencent Cloud as an example

1. Log in to the background of Tencent Cloud, find your own domain name list, and click Parse

 2. Add parsing rules (add records)

 3. Enter the public network IP and confirm to add two parsing rules and it will be ok

In this way, after binding the public IP of our server to the domain name, we can access our server through the domain name, and the effect is as follows.

 Seven. Put the https protocol on the domain name (change http to https)

First of all, we are going to apply for an ssl certificate in Tencent Cloud, enter the Tencent Cloud page, search for the ssl certificate and click in

 

 Click My Certificate on the left, then click Apply for a Certificate for Free, confirm it and apply for a certificate as required

 

 After the application is completed, you need to wait for the review, which may take several hours, and you can do other things. After the application is successful, there will be a mobile phone message notification. After the application is successful, we will download the certificate.

Then open the Tomcat folder inside

 

 Then pull the files inside to the Resources directory of the idea

 

Then go to the application.properties file and configure the following code (for the .yml file, check the format on Baidu, the content is the same)

#Configure certificate path (the one under resources on the left)
server.ssl.key-store = classpath :yxkcjy.top.jks
#Configure certificate password
server.ssl.key-store-password = cjy.xxxx #Configure certificate type server.ssl .keyStoreType = JKS

 Then you can start the project to see

Then visit the website and it's OK

 

Supongo que te gusta

Origin blog.csdn.net/cc1373709409/article/details/122668524
Recomendado
Clasificación