Blog address: ONESTAR Inn

Source code access method 1:

  • Scan the qr code at the end of the article, pay attention to the public number [programming Daily], background reply [blog], you can get the source code

Source code access method two:

  • Front-end page source address: github.com/oneStarLR/m…

  • Jpa as a persistent layer source address: github.com/oneStarLR/m…

  • Mybatis as a persistent layer source address: github.com/oneStarLR/m…

Welcome to give encouragement to star


This article will be purchased from the server after remote connection, environment setup, project deployment run and domain name access to describe the SpringBoot setup personal blog online deployment

First, server purchase

The blogger bought the Tencent cloud server on 618 with a large discount. He bought a three-year one. As for whether to choose Tencent Cloud or Ali Cloud, it is almost the same for personal blogs.

  • Tencent Cloud purchase address: Tencent cloud purchase address

That’s what the blogger bought, new user 2883, eight yuan a month, cheaper than the student price

2. Remotely connect to the server

1. Change the user name and password

After buying the server, the blogger directly installed CentOS 7.5 64-bit system for me by default, and the user name and password are also default. Maybe I did not choose some options, but it does not affect me. Enter the instance console to change the password, click more operations, select Reset password, and reset password after verification.

2. Download and install FinalShell

Don’t ask me why I use FinalShell, use you know, easy to use! Here’s a download address: www.hostbuf.com/

Download and install. After installation, open the following folder and click on it

To create an SSH remote connection, enter the server information:

  • Name: optional, easy to identify with
  • Host: Public IP address of the replication server
  • Port: server port. The default value is 22
  • User name: root if not changed
  • Password: password set during the reset

Click OK to connect to the server remotely

3. Environment construction

Here is mainly to build the blog required environment, only need to install JDK and MySQL database, in order to ensure the development environment and deployment environment consistent, here to install JDK1.8, MySQL5.7

1. The JDK installation

1.1 yum install

After using the yum command on Linux, OpenJDK is installed in the /usr/lib/jvm/ directory

# its installationYum install Java - 1.8.0 comes with - its Java - 1.8.0 comes with its develCopy the code

1.2 Configuring JDK Environment Variables

Open the configuration file
vim /etc/profile
Copy the code

When entering the text editing state, the cursor moves to the end of the last line of the file (Shift + G quickly moves to the bottom of the file), and the keyboard presses I (English state).

Insert the following four lines

exportJAVA_HOME = / usr/lib/JVM/jdk1.8.0.171export JRE_HOME=/$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
Copy the code

:wq Save the changes and exit

1.3 Let environment variables take effect

source /etc/profile
Copy the code

1.4 Checking whether the JDK is installed successfully

java -version
Copy the code

The JDK version information is displayed. The installation is successful

openjdk version "1.8.0 comes with _252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
Copy the code

2. MySQL5.7 installation

Download MySQL 2.1

Install MySQL
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

# install yum
rpm -Uvh mysql57-community-release-el7-11.noarch.rpm

# check the MySQL startup list of the yum repository
yum repolist enabled | grep mysql

Install the MySQL database
yum install mysql-community-server
Copy the code

2.2 Starting the MySQL Service

Start the MySQL service
systemctl start mysqld 

Check the MySQL startup status
systemctl status mysqld

Set boot up
systemctl enable mysqld
systemctl daemon-reload
Copy the code

2.3 Logging In to Reset the Password

/var/log/mysqld.log /mysqld.log /mysqld.log /mysqld.log /mysqld.log /mysqld.log /mysqld.log /mysqld.log /mysqld.log

grep "temporary password" /var/log/mysqld.log
Copy the code

You can then use this password to log in to MySQL

mysql -uroot -p
Copy the code

Press Enter and enter the password to log in to the database. The password needs to be reset for the first login.

ALTER user 'root'@'localhost' identified by '123456';
Copy the code

After the reset, you can log in and operate the database using the new password

== Note: this is to change the password to ‘123456’, this is just a demonstration, do not make such a simple password, otherwise how to lose the data do not know ==

At this point, the database installation is complete and can meet the basic requirements of the deployment project. Here, there are two more points: database configuration, database authorization

2.4 Database Configuration

CNF: /etc/my. CNF: /etc/my. CNF: /etc/my. CNF: /etc/my. CNF: /etc/my. CNF: /etc/my. CNF: /etc/my. CNF: /etc/my. CNF: /etc/my. CNF: /etc/my. CNF: /etc/my. CNF: /etc/my. CNF

Set database character set to UTF8MB4[client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 [mysqld] character-set-client-handshake  = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect ='SET NAMES utf8mb4'
 
lower_case_table_names = 1 The table name is case insensitive
Copy the code

After the modification is complete, restart the MySQL service:

# restart MySQL
systemctl restart mysqld
Copy the code

Mysql database my.cnf (my.cnf, my.cnf, my.cnf

2.5 Database Authorization

In order to facilitate the operation of the database, it is generally the use of visual software to connect to the database remotely, but if any machine can connect to your server database remotely, it is not safe, here we need to authorize the database, specify the database that can be connected remotely, Without authorization, only local access to localhost is supported.

# log in to the database
mysql -uroot -p

# Use database
use mysql;

# set permissions
GRANT ALL PRIVILEGES ON *.* TO 'root'@The '%' IDENTIFIED BY 'root' WITH GRANT OPTION;

# refresh permission
flush privileges;

Exit and restart the server
service mysqld restart
Copy the code

Set permissions for the sentence:

  • *. * : indicates all libraries. All the tables
  • ‘root’@’%’ identified by ‘root’ :
    • Previous root: indicates the user name,
    • % : indicates all access IP addresses
    • Root: indicates the database password

Through it can configure the remote access database and access to the IP, bloggers are usually directly configuration ‘%’ all IP access, because sometimes development needs to change the IP, if specified IP is not convenient, so the configuration of the ‘%’, usually is to port 3306 to shut down, need to connect remotely to open the port 3306, Turn it off when you’re done. It’s safer

In order to facilitate the operation, server security group can be modified here, let’s open the server instance of the console, find a safe set of rules, some KaiBian triple-verse-poetry standing rules, you can see the server there are two default rules, you can see the first article is all the service ports are open, so not too safe, so here will close it, and then open the need to configure the port

2.5.1 Rejecting all Protocol Ports

Click on the first edit, change allow to deny, and save

2.5.2 Adding Ports 22 and 3306

Port 22 is for SSH remote connections, and port 3306 is for database remote connections

Click Add rule and add the following two rules. Click Finish to connect to the database remotely

Note: You can turn off port 3306 when you do not need to remotely connect to the database

Iv. Project deployment

After the server environment is set up, the project can be packaged and deployed to the server. Here, the JAR package is deployed by using IDEA into a JAR package, and then the JAR package is uploaded to the server to run in the background, and then the IP can be accessed

Pack 1.

Click Maven Projects on the right of IDEA, double-click Clean, and then double-click Package

Not surprisingly, the console will display BUILD SUCCESS with the size of the jar package file, and under the target folder will generate a jar package of myblog-0.0.1- snapshot.jar, which is the jar package to upload to the server for deployment.

Deployment of 2.

Upload the jar package you just generated to the server and deploy it. Note that before uploading, change the project database configuration to the server database

2.1 upload

Here use FinalShell upload, first use FinalShell login server, create a folder in the server to store the project

Create folder
mkdir myblog

# enter directory
cd myblog
Copy the code

Under FinalShell there is a visual directory structure. Click on the newly created folder, right click on the blank space, click Upload, select myblog-0.0.1- snapshot.jar and upload the JAR

2.2 Disabling the Firewall to enable Port 8080

The server can be accessed only after the firewall is turned off. Our blog project is configured with port 8080. All ports were turned off earlier, so port 8080 will be open here

  • Firewall correlation
Check the firewall status
systemctl status firewalld

# open firewall
systemctl start firewalld

# disable firewall
systemctl stop firewalld
Copy the code
  • Open port 8080

Enter the server console security group rules, add rules, and open port 8080 as follows:

3 Run the JAR package

Let the JAR package run in the server background, enter the JAR package folder, and run the command to run the JAR package

Enter the jar package folder
cd /home/myblog

Run jar packages in the backgroundNohup Java -jar myblog-0.0.1 -snapshot.jar &Copy the code

3.1 access

Access port 8080 of server in browser, Bingo!!

5. Configure domain name Access (HTTP)

Here the default reader has purchased the domain name, and successfully registered

Generally speaking, a server runs more than one service (depending on your requirements, of course, you can run only one service), each service uses a secondary domain name to access, so configure the secondary domain name for access

1 Add Resolution

Log in to the cloud server and find DNS resolution in the console of the cloud server. Tencent Cloud can search DNS in the cloud products above, as follows

Click on it and look like this, you can see that this is empty, because there is no resolution added, let’s click on Add resolution, and then add your own domain name

After adding the domain name, there will be a message to add the domain name, click the domain name, here to add three records, the following three:

Note: If you only want to configure your website to be accessible by domain name, you only need to configure the third secondary domain name in the full screenshot, but generally speaking, a server is not only accessed by secondary domain name, but also directly and through the WWW.

  • @ : Resolves the domain name
  • WWW: Resolves domain names through the WWW
  • XXXX (secondary domain name) : resolve through secondary domain name access, I configured here is onestar secondary domain name

The value is the public IP address of the server

After the domain name is added, you can use the domain name to access, But, if you access it directly, the server will access port 80 by default, But our project uses port 8080, so the port will be forwarded here, and port 8080 will be forwarded to the domain name, which will use the reverse proxy technology.

2 Reverse Proxy

In Reverse Proxy mode, a Proxy server receives Internet connection requests, forwards the requests to the Intranet server, and returns the results to the Internet client. In this case, the Proxy server acts as a server externally. Here use the NGINX reverse proxy, forward port 80 to port 8080, need to configure NGINX, so you need to download NGINX first

2.1 Download and Install NGINX

# Download NGINX:
yum install nginx

# start nginx:
systemctl start nginx

# Add boot:
systemctl enable nginx

# check nginx status:
systemctl status nginx
Copy the code

2.2 configure NGINX

Need to configure NGINX, after downloading the configuration files here is NGINX. Conf, you can use the find command / -name “NGINX. Conf” lookup, default is in the/etc/NGINX/NGINX. Conf, let’s configure:

# Open the nginx.conf configuration file
vim /etc/nginx/nginx.conf
Copy the code

You can see the following configuration, and there are only two areas that are highlighted here

  • Include: /etc/nginx/conf.d/*. Conf: /etc/nginx/conf.d/*. Conf file in /etc/nginx/conf.d/ to add the configuration, which will be used later
  • Sever: This is the part that needs to be modified, which is the service configuration, but we usually don’t modify it directly here, because a server usually has many services to run, so if you modify it directly here, it will not be convenient to expand, and you can see that I annotated server here, which means that you don’t need to use the server, Instead, add additional configuration files to include

Nginx. conf is a general configuration file, include is a sub-configuration file, if you want to add a service, you can add a sub-configuration file to /etc/nginx/conf.d/

Create a *. Conf file in /etc/nginx/conf.d/. I’ll call it onestar

# create open onestar
vim /etc/nginx/conf.d/onestar.conf
Copy the code

Add the following configuration:

server { listen 80; server_name onestar.newstar.net.cn; The location / {proxy_pass http://81.68.734.422:8080; index index.html index.htm; proxy_set_header Host$host;
        proxy_set_header X-Real-Ip $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
    }
    access_log /logs/onestar.newstar.net.cn.access.log;
}
Copy the code

Here we know a few points:

  • Listen: Listens on port 80
  • Server_name: Indicates the IP address to be forwarded, that is, the previously configured secondary domain name address
  • Proxy_pass: indicates the address to which the proxy will go, that is, the port address of the server to access
  • Access_log: it means the logging information, will create onestar.newstar.net.cn.access.log log files under the root directory, print the log information of the project

2.3 restart NGINX

# reset:
nginx -s reload
Copy the code

The service takes effect after restart and can be accessed using the domain name: onestar.newstar.net.cn/

At this point, the blog development is complete, can be visited domain, was going to use HTTPS access also tells of a once, but if you want to write the article, I will be speaking again, so will my blog project to stop, then redeploy the HTTPS, and now my blog every day hundreds of thousands of requests, so also can’t do this, HTTPS access allows you to query related information, also using NGINX, which is not covered here.

Well, it is not easy to build a good blog, we enjoy writing articles!

[Point attention, don’t get lost, welcome to continue to pay attention to this site]