This article can be said to be full of dry goods. Students who pay attention to me should wait until I have several SpringBoot articles that introduce how to build a local server (students who have not read it can systematically read my SpringBoot column to ensure that you will gain a lot). But we are all playing locally, and the database is also operated locally, and we have never gone to the cloud. This article will teach you how to deploy the SpringBoot project to Tencent Cloud Server.
If you are a novice and have not read my previous series of SpringBoot articles, it is recommended to at least read this one:
SpringBoot (4) SpringBoot builds a simple server_springboot makes a service_heart poisoned blog-CSDN blog
If you want to study systematically from beginning to end, please pay attention to my column and keep updating:
Table of contents
1. Cloud server installation system and login
2. Install MySql on the cloud server
1. Uninstall mariadb installed by default in centos
2. Create a mysql installation folder
3. Cloud server configuration Mysql
5. Modify mysql_native_password to a new password
6. Allow all ip to access the cloud server MySql
4. Test connection to cloud server MySql
1. Add rules to server firewall
2. MySQL Workbench tests whether the connection is successful
5. Deploy the project to the cloud server
1. The local packaging project is jar
2. Upload the jar to Tencent Cloud Server
Sixth, the background continues to run
1. The problem of terminal disconnection
2. Set the background to run continuously
1. Cloud server installation system and login
I use Tencent Cloud Lightweight Application Server, and the mirroring system is CentOS 7.6 64bit. CentOs is still recommended here, and windows is not recommended. Although there is a graphical tool pagoda panel, it is really difficult to use. I tossed for a long time, and finally reinstalled CentOS, linux is really fragrant.
After installing the system, reset the password and log in.
2. Install MySql on the cloud server
After logging in, we use linux commands to operate everything next.
1. Uninstall mariadb installed by default in centos
rpm -e mariadb-libs --nodeps
2. Create a mysql installation folder
cd /usr/local
mkdir mysql
cd mysql
3. Download mysql
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar
4. Unzip the folder
tar -xvf mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar
5. Install mysql
rpm -ivh mysql-community-common-8.0.16-2.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-8.0.16-2.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-8.0.16-2.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-8.0.16-2.el7.x86_64.rpm --nodeps --force
3. Cloud server configuration Mysql
1. Modify the my.cnf file
Increase
lower_case_table_names = 1
2. Initial configuration
mysqld --initialize;
chown mysql:mysql /var/lib/mysql -R;
systemctl start mysqld.service;systemctl enable mysqld;
3. Change password
View the initial password and log in to mysql
cat /var/log/mysqld.log | grep password
change Password
alter user 'root'@'localhost' identified by '888888';
flush privileges;
4. Login with new password
5. Modify mysql_native_password to a new password
alter user 'root'@'localhost' identified with mysql_native_password by '888888';
6. Allow all ip to access the cloud server MySql
create user 'root'@'%' identified with mysql_native_password by '888888';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
4. Test connection to cloud server MySql
1. Add rules to server firewall
2. MySQL Workbench tests whether the connection is successful
3. Establish a connection
4. Test server MySQL
Next, I created the same database and table as my previous local server in my Tencent Cloud Server MySQL connection, and I copied it directly from the local field by field.
Modify the configuration information in the previous SpringBoot project to the public network ip of Tencent Cloud Server, as follows:
Run the project, then visit http://localhost:8080/register?name=zj&phone=1234567890&password=123456
As you can see, there is no problem with the request, and the user registration information is also written in the database:
5. Deploy the project to the cloud server
As of now, we have only completed half of the cloud migration, because our project is still running locally, but the database has been moved to the cloud server. Therefore, the next step is to deploy the SpringBoot project to the cloud server.
1. The local packaging project is jar
Enter the following command on the command line of IDEA:
mvn clean package
If there is any error in packaging, you need to modify the problem according to the error information. Generally, if the local operation is OK, there is no error. After a while, you will see the following Buid Success information:
2. Upload the jar to Tencent Cloud Server
After Build Succes, you can see xxx-xxx-SNAPSHOT.jar in the target directory of the project:
Upload the jar package to the cloud server. After installing the enhanced function, drag it directly to the command line, and you can see the upload progress in the lower right corner:
3. Run jar
Note that the server needs to have java installed, if not, install it
yum install -y java-1.8.0-openjdk
After installing java, use java -jar to run the project. You can see that our project is running on Tencent Cloud Server:
4. Public network ip test
First, set an accessible port on the firewall, such as 8080, which is the same as our previous local port number:
After setting, you can directly use the public network ip of your cloud server to access in the browser:
Sixth, the background continues to run
1. The problem of terminal disconnection
The above is not perfect, because once the remote terminal is disconnected, the user will be unable to access, which is naturally not feasible. In general, except for maintenance, the server needs to be kept running continuously.
2. Set the background to run continuously
Use the following command to ensure that the project can run continuously in the background even if the terminal exits:
nohup java -jar server-0.0.1-SNAPSHOT.jar &
After setting, disconnect the terminal and test it, no problem:
So far, we have completely deployed our project to Tencent Cloud Server. Seriously, I've been thinking about writing this blog for almost a week now, on and off. Because it really takes a lot of energy to really go through the whole process. This Saturday, I couldn't hold back and started to write slowly in the afternoon. I wrote intermittently until 0:30 in the morning. It was really not easy. I hope that students who have seen this, if I really help you, you can comment, like and support. If there is something you don't understand, please communicate.