This article mainly introduces the detailed explanation of the Spring boot project deployment to cloud server Novice tutorial, and share it with you, as follows:
Test address: 47.94.154.205:8084
1. Application Shell under Linux connects to the cloud server through SSH
//ssh username@public IPssh josiah@ip// Enter password
2. Start building SpringBoot's operating environment
1. Install JDK and configure environment variables
1) Open JDK official website www.oracle.com
2) Find the latest corresponding JDK version and download it
One problem to note here is: when downloading JDK on the cloud server, you must go to the official website of the oracle locally to download it and then upload it to the cloud server. You cannot download it directly through wget, because when downloading JDK, you must check the agreement to agree to it. If you use the wget download link directly, the agreement will not be agreed to by default. The result of the download will be a .html file, which cannot be decompressed and installed.
The command to upload a compressed package to the cloud server is:
The code copy is as follows:
scp -P 22 /home/josiah/Downloads/jdk-9.0.4_Linux_x64_bin.tar.gz josiah@ip:/home/josiah
3) Unzip the downloaded compressed package to the specified directory
sudo mkdir Javatar -zxvf jdk-9.0.5....tar.gz -C ./Java
4) Configure JDK environment variables
① Add system environment variables:
sudo vi /etc/environment
Add the following:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/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, let the configuration file take effect immediately
source /etc/environment
②Add user environment variables
sudo vi /etc/profile
Add the following:
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
Execute the configuration file the same to make the configuration file effective immediately:
source /etc/profile
③Verify whether the JDK is installed successfully
java -version
2. Install Mysql
Reference link: //www.VeVB.COM/article/114262.htm
3. Install Git
sudo apt-get install gitgit --version
4. Install Maven
1) Download the Maven installation package and unzip it
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.gzsudo mv apache-maven-3.5.2 /usr/local/maven
2) Configure environment variables
sudo vi /etc/profile
Add the following:
export M2_HOME=/usr/local/mavenexport M2=$M2_HOME/binexport PATH=$M2:$PATH
Execute the configuration file to make the configuration take effect immediately:
source /etc/profile
3) Modify maven domestic mirror
In order to speed up the construction of maven, add domestic mirror servers
①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 content 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>
③Verify whether the installation is successful
mvn -version
5. Install Mongodb
Since my blog project requires Mongodb to store images, Mongodb needs to be installed. The installation steps can be viewed in another blog.
6. Install gradle
1) Download the latest version of the gradle compression package at http://www.gradle.org/downloads page and upload it to the cloud server.
The code copy is as follows:
scp -P 22 /home/josiah/Downloads/gradle-4.6-bin.zip josiah@ip:/home/josiah
2) Unzip it in /usr/local directory
sudo unzip gradle-4.6-bin.zipsudo mv gradle-4.6 /usr/local/gradle
3) Set 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 to take effect immediately:
source /etc/profile
4) Verify whether it is successful
gradle -version
3. Packaging projects and picture servers
1. Locally use Maven to package MyBlog project to generate executable jar files
1) Modify the pom.xml file in the MyBlog project and add the following content to the mirrors node
<!--maven package--><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 available, devtools may not work--> </configuration> </plugin> </plugins> </build>
2) Enter the project root directory, that is, the directory at the same level as pom.xml, and use mvn package for packaging
cd MyBlogmvn package
At this time, a .jar file will be generated in the target/ folder. Execute the java -jar jar package name to start the project
java -jar blog-0.0.1-SNAPSHOT.jar
3) Upload the packaged jar file to the cloud server
The code copy is as follows:
scp -P 22 /home/josiah/blog-0.0.1-SNAPSHOT.jar josiah@ip:/home/josiah
4) Note: After I first packed it, I found that some pages were inaccessible when I started the project, and the template parsing failed and the page could not be found.
Later, I found that if I packed it and then ran it, the path returned in the Controller class cannot be added with "/". In the following case, the "/" before the path must be removed:
2. Packaging image server project
In my blog, I use an open source small image server on github, written by spring boot + Mongodb, and I want to package and upload it to the cloud server.
The project is built using the gradle tool.
1) Modify the build.gradle file in the project and add the following statements:
tasks.withType(JavaCompile) { options.encoding = "UTF-8" }2) Use the following command to package
gradle build
3) At this time, a jar file will be generated in the build/libs directory and then start it
cd build/libs/java -jar mongodb-file-server-1.0.0.jar
4) Upload the packaged jar file to the cloud server
The code copy is as follows:
scp -P 22 /home/josiah/java/mongodb-file-server/build/libs/mongodb-file-server-1.0.0.jar [email protected]:/home/josiah
4. Officially start deploying blogs
After all, the preparations for deploying the blog have been completed, so start deploying and launching the project.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.