Explain the deployment of springboot application on Alibaba Cloud server from 0 to 1 (install java environment | Mysql environment)

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

13424350-a122f0ddb30d7e73.png

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:

13424350-bed8989028873d46.png

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/profilemake the added environment variable take effect.

Then use to java -versioncheck whether the configuration is successful:

13424350-52208a5d16e69f7e.png

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
13424350-801da1a84d1f0a40.png

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.cnfTo 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 startstart the mysql server.

vim /etc/profileEnter 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 -plog 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:

13424350-3499f7d7cd58a639.png

Then import a security group rule:

13424350-b572a361ba348fdc.png

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:

13424350-feb2a5335f8bf65b.png

Guess you like

Origin blog.csdn.net/qq_14810195/article/details/105307348