Deploy the Spring boot project from zero to the cloud server (prepare for work)

Source: Internet
Author: User
Tags install mongodb aliyun

Their blog finally successfully deployed on-line, back to summarize the whole project to record the deployment process!

Test Address: 47.94.154.205:8084

Note: At the end of the article there are benefits!

One, the application of Linux under the shell through SSH connection to the cloud server

// SSH User name @ public IP SSH [email protected] // Enter Password

Second, start to build the operating environment of Springboot

1. Installing the JDK and configuring environment variables

1) Open the JDK website www.oracle.com

2) Find the latest JDK version of the match, download

One of the issues to note here is: Cloud server download JDK must be local to the Oracle official website to download and upload to the cloud server, not directly through the wget way to download, because the download JDK to check the agreement with its Protocol, directly with the wget download link, the default will not agree to the agreement, The result of the download will be an. html file that cannot be unpacked and installed.

The commands to upload the compressed package to the cloud server are:

SCP  /home/josiah/downloads/jdk-9.0. 4_linux_x64_bin. tar. gz [Email Protected]:/home/josiah

3) Unzip the downloaded compressed package to the specified directory

sudo mkdir Java tar -zxvf jdk-9.0. 5..... tar. gz-c./java

4) Configuring the JDK environment variables

① Adding system Environment variables:

sudo VI /etc/environment

Add the following content:

Path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$ Java_home/bin"export CLASSPATH=.: $JAVA _home/lib: $JAVA _home/jre/libexport java_home =/home/josiah/java/jdk1. 8. 0_161

Execute the configuration file, that is, the configuration file takes effect immediately

Source/etc/environment

② Adding user Environment variables

sudo VI /etc/profile

Add the following content:

Export JAVA_HOME=/HOME/JOSIAH/JAVA/JDK1. 8 . 0_161export jre_home= $JAVA _home/jreexport CLASSPATH=.: $JAVA _home/lib: $JRE _home/lib:$ Classpathexport PATH= $JAVA _home/bin: $JRE _home/bin: $PATH

Also execute the configuration file to make the configuration file effective immediately:

Source/etc/profile

③ verifying that the JDK is installed successfully

Java-version

2. Install MySQL

Reference Links:

Https://www.linuxidc.com/Linux/2017-10/147460.htm

3. Install Git

sudo Install  --version

4. Installing MAVEN

1) Download and unzip the MAVEN installation package

wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.2/binaries/ apache-maven-3.5.2-bin.tar.gztar -zxvf apache-maven-3.5. 2-bin. tar. gz
sudo mv Apache-maven-3.5.2/usr/local/maven

2) Configure Environment variables

sudo VI /etc/profile

Add the following content:

Export M2_home=/usr/local/mavenexport M2= $M 2_home/binexport PATH= $M 2: $PATH

Execute the configuration file and let the configuration take effect immediately:

Source/etc/profile

3) Modify MAVEN internal image

To speed up the Maven build, add a mirrored server in the country

① Copy the/home/josiah/apache-maven-3.5.2/conf/settings.xml file to the ~/.M2 directory:

CP /home/josiah/apache-maven-3.5. 2/conf/settings.xml  ~/.m2

② Add the following to the mirrors node:

sudo VI /home/josiah/apache-maven-3.5. 2/conf/settings.xml
<mirror>      <ID>alimaven</ID>      <name>aliyun maven</name>      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>      <mirrorOf>central</mirrorOf></mirror>

③ Verifying the installation is successful

Mvn-version

5. Installing MongoDB

Because my blog project needs to use MongoDB to store pictures, I need to install MongoDB and the installation steps can be viewed in another blog post.

6. Installing Gradle

1) on the http://www.gradle.org/downloads page, download the latest version of the Gradle compression pack and upload it to the cloud server

SCP  /home/josiah/downloads/gradle-4.6-bin. Zip [Email Protected]:/home/josiah

2) Unzip it in the/usr/local directory

sudo Unzip gradle-4.6-bin. Zip sudo mv gradle-4.6 /usr/local/gradle

3) Setting Environment variables

sudo VI /etc/profile

Add the following content:

Export gradle_home=/usr/local/gradleexport PATH= $GRADLE _home/bin: $PATH

Execute the configuration file so that it takes effect immediately:

Source/etc/profile

4) Verify Success

Gradle-version

Three, packaging projects and image server

1. Use MAVEN to package MyBlog projects locally to generate executable jar files

1) Modify the Pom.xml file in the MyBlog project to add the following to the mirrors node

<!--Maven Pack -<Build>        <Defaultgoal>Compile</Defaultgoal>            <Plugins>                    <plugin>                         <groupId>Org.springframework.boot</groupId>                         <Artifactid>Spring-boot-maven-plugin</Artifactid>                          <Configuration>                              <jvmarguments>-dfile.encoding=utf-8</jvmarguments>                            <Fork>True</Fork><!--If this configuration is not possible, devtools may not work -                        </Configuration>                    </plugin>            </Plugins>    </Build>

2) Enter the project root directory, which is the same directory as the Pom.xml, packaged using the MVN package

CD MYBLOGMVN Package

A. jar file is generated under the target/folder and the Java-jar jar package name is executed to start the project

Java-jar blog-0.0. 1-snapshot.jar

3) Upload the packaged jar file to the cloud server

SCP  /home/josiah/blog-0.0.1-snapshot.jar [email Protected]:/home/josiah

4) Note: This is the first time I packed my project, I found that some pages could not be accessed, the template parsing failed, the page could not be found

Later check data found that after packaging and then run, the controller class in the return path can not add "/", as in the following case, to remove the path before the "/":

2. Package Picture Server Project

My blog uses a small open source image server from GitHub, which is written by spring Boot + MongoDB to package it and upload it to the cloud server.

The project was built using the Gradle tool.

1) Modify the Build.gradle file in the project and add the following statement:

Tasks.withtype (javacompile) {     "UTF-8"  }

2) Use the following command to package

Gradle Build

3) A jar file will be generated in the Build/libs directory at this time to execute the boot

CD build/libs/-jar mongodb-file-server-1.0. 0. jar

4) Upload the packaged jar file to the cloud server

SCP  /home/josiah/java/mongodb-file-server/build/libs/mongodb-file-server-1.0 . 0. jar [email protected]47.94. 154.205:/home/josiah

Iv. formally start the deployment of blogs

In the end, the preparation for the previous deployment of the blog is over, then start deploying the Startup Project.

Finally, we recommend a conscience of the public "It Resource Society":

This public number is committed to free sharing of the best video resources, learning materials, interview experience, Front end, Php,java, algorithms, Python, big Data and so on, which you want to have

IT Resources-QQ Exchange Group: 601357554

Search public Number: Itziyuanshe or scan the QR code below direct attention,

Inside basic what information have, base to advanced to project actual combat, if feel enough also can add group with group Main, the most important is all free!

Deploy the Spring boot project from zero to the cloud server (prepare for work)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.