The steps for purchasing Alibaba Cloud servers are omitted. After purchasing, go in to reset the password and connect to the example to enter the server terminal.
1. Configure the Java environment (install jdk)
Since the official download is too slow, I chose the mirror website: https://repo.huaweicloud.com/java/jdk
Copy the downloaded compressed package into the virtual machine, and use scp -r jdk-8u202-linux-x64.tar.gz root@ip地址:/usr/
the compressed package in the virtual machine to transfer it to the server:
Create a java/jdk directory under usr:
root@i[省略]:/usr# mkdir java
root@i[省略]:/usr# cd java
root@i[省略]:/usr/java# mkdir jdk
root@i[省略]:/usr/java# cd jdk
root@i[省略]:/usr/java/jdk# cd ../
root@i[省略]:/usr/java# cd ../</pre>
Go to the usr directory and unzip the jdk compressed package to /usr/java/jdk:
root@i[省略]:/usr# tar -xvf jdk-8u202-linux-x64.tar.gz -C /usr/java/jdk
Configure environment variables:
root@i[省略]:~# vi /etc/profile
Add the following code to the file:
# set java environment
export JAVA_HOME=/usr/java/jdk/jdk1.8.0_202
export JRE_HOME=/usr/java/jdk/jdk1.8.0_202/jre
export CLASSPATH=.:JAVA_HOME/lib:JRE_HOME/lib:$CLASSPATH
export PATH=JAVA_HOME/bin:JRE_HOME/bin/JAVA_HOME:PATH</pre>
Use to source /etc/profile
make the added environment variable take effect.
Then use to java -version
check whether the configuration is successful:
2. Configure MySQL
Find if there is mysql and delete the remaining mysql:
find / -name mysql | xargs rm -rf
Transfer the downloaded file to the server through the virtual machine (this step is omitted, and the specific operation can refer to how to transfer it when configuring the Java environment above).
Then unzip to /usr/java/mysql:
tar -zxvf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz -C /usr/java/mysql
Check if there is mysql in the user group
groups mysql
If not, add:
# 添加用户组
groupadd mysql
# 添加mysql用户
useradd -r -g mysql mysql
Enter the mysql directory and change the permissions:
chown -R mysql:mysql ./
vi /etc/my.cnf
To modify the configuration file:
[client]
[mysqld]
basedir=/usr/java/mysql
datadir = /usr/java/mysql/data
log-error = /usr/java/mysql/data/error.log </pre>
Enter the bin directory and enter to install mysql:
./mysql_install_db --user=mysql --basedir=/usr/java/mysql --datadir=/usr/java/mysql/data &
Run in the mysql directory to ./support-files/mysql.server start
start the mysql server.
vim /etc/profile
Enter the environment configuration file to add configuration:
# set mysql
export PATH=$PATH:/usr/java/mysql/bin
Enter source /etc/profile
.
Then enter to mysql -uroot -p
log in to mysql, the password is blank, and press Enter directly.
You can change the password after entering.
It can be used normally.
3. Open port 8080
If you do not open the port, the public network cannot access the server, so we need to open a port 8080.
Click on a security group to enter:
Then import a security group rule:
4. Deploy springboot application
After uploading a springboot application to the server, enter the corresponding directory and run it:
If you are just typing java -jar test.jar
, as long as you close the terminal, the application will stop running.
If you want to run in the background, enter the following:
nohup java -jar test.jar > log1.log 2>&1 &
This command is to enable the application to run in the background. And redirect the output to log1.log log file.
Then enter ip:8080/...(你的请求)
it and you can access it anywhere, here is the project interface document page generated by swagger: