One: Two deployment packages:

Java projects deployed to the server usually use WAR packages, but also useful JAR packages. After the popularity of micro-service Spring-Cloud, most packages are JAR packages. Before deployment, we should first make sure that we need to use WAR packages or JAR packages. Spring Boot can be published as a WAR or as a JAR package. A few differences:

Jar packages: Run directly from the built-in Tomcat, no additional tomcat installation is required. To modify the internal Tomcat configuration, you only need to configure it in the Spring Boot configuration file. Built-in Tomcat does not have its own log output, relying on the JAR package application to output logs. But it’s convenient, it’s fast, it’s easy.

War package: In traditional application delivery mode, You need to install Tomcat and run the WAR package in the Waeapps directory. You can flexibly select the Tomcat version, modify tomcat configurations, output tomcat logs, and configure security policies. Not as fast and convenient as typing into jar packages.

Personally, I prefer to release the application as a JAR package, because Spring Boot already has Tomcat built-in, so no additional configuration is required. In fact, you can search the characteristics of Spring Boot, there is a very important feature is spring Boot market excellent open source technology, all together, convenient and quick application. Technology is neither 100% good nor 100% bad. It is reasonable to exist, but it depends on personal habits and business scenarios.

Two: JAR package deployment (recommended)

The jar package here is the premise of the SpringBoot project, poM file has been set up the entry file and other corresponding Settings, the specific Settings here will not say.

  • Start by uploading the JAR package to the Linux server

Xshell [1] is a powerful secure terminal simulation software that supports SSH1, SSH2, and the TELNET protocol of Microsoft Windows platform. Xshell helps users enjoy their work in a complex network environment through secure Internet connections to remote hosts and its innovative design and features. Xshell can be used in Windows to access servers in different systems on the remote end, so as to better achieve the purpose of remote control terminal. In addition, it has a rich look and feel color scheme and style choices. Xftp is a powerful SFTP and FTP file transfer software based on MS Windows platform. With Xftp, MS Windows users can securely transfer files between UNIX/Linux and Windows PCS. Xftp can accommodate the needs of both beginner and advanced users. It uses standard Windows-style wizards, has a simple interface that works closely with other Windows applications, and offers many powerful features for power users. 2. By installing the above two software, Windows computer can remotely control the Linux server, so that we can transfer the packaged JAR files to the Linux server for project deployment.

Assuming that a loaded JAR package is available on the Linux service, the following are some common deployment methods:

1. Java-jar startup mode.

java -jar *.jar
Copy the code

This method only runs in the current window, and the JAR program ends when the window is closed or the connection is disconnected.

2. Nohup startup mode. (recommended)

# nohup: run command without hanging up
# & : Background run
# >: Log redirects output to
nohup java -jar *.jar >jarLog.txt &
Copy the code

3. Register as a Linux service (recommended)

  • Install the spring-boot-maven-plugin plugin in the poM file. Install the maven-plugin plugin in the POM file. Install the spring-boot-maven-plugin plugin in the POM file.
<! Maven-generated jars can be directly executed./aabb.jar. --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <executable>true</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>
Copy the code
  • Register the service on Linux (register deployment based on init.d here)

Place the jar package in any Linux directory eg: /var/project/

sudo ln -s /varJar /etc/init.d/ ABC (demo indicates the jar package name and ABC indicates the service name)Copy the code

A successful run generates an ABC file in the init.d directory (cyan link format).

You can then start the JAR package with the service XXX start command


Start /stop the service: service ABC start/stop

Check the status: service ABC status

To set automatic startup, run the chkconfig ABC on command


4. Systemctl startup mode.

  • Add ‘abc.service’ to /usr/lib/systemd/system as follows:
[Unit] Description=abc.service Requires=mysql.service mongod.service redis.service Wants=abc.service After=syslog.target  network.target mysql.service mongod.service redis.service abc.service [Service] User=manager Group=manager EnvironmentFile=/home/.bash_profile WorkingDirectory=/home/tomcat ExecStart=/usr/bin/java -Xms512m -Xmx512m -jar Jar --spring.profiles. Active =test [Install] WantedBy=multi-user.targetCopy the code
  • To change the service, run systemctl daemon-reload. Bash_profile = systemctl daemon-reload
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

LOG_PATH=/home/logs
export LOG_PATH
export PATH

Copy the code

Where LOG_PATH above can be referenced in the project, for example:

5. Tomcat startup mode.

Copy the *. Jar file to the tomcat\webapps\ directory, start tomcat, and access localhost: 8080/jar. Nohup./startup.sh & (& can be used in background)

Note: When starting the jar with Tomcat, you need to exclude Tomcat from the package:

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion>  </exclusions> </dependency>Copy the code

6. Docker cloud deployment. www.jianshu.com/p/ec477d84f…

Finally, some general commands:

The command to perform operations on the Linux project is as follows: Temporarily running the background: java-jar /root/yyxx/cloud-yyxx-web-1.0-exec.jar (temporarily running the background) Permanently running the background, you need to kill the background process to stop it: Nohup Java jar/root/yyxx/cloud – yyxx – web – 1.0 – the exec. Jar & process () to check the jar: ps aux | grep cloud – yyxx – web – 1.0 – the exec. Jar to kill process: Kill -9 Indicates the process ID

Three: War package deployment

The simplest and most common deployment method is to simply place the WAR package in tomcat’s Wabapp directory and run Tomcat. The steps are as follows: a. Package the project into the WabApp directory. The following figure