Complete steps for deploying jar package projects using Shell scripts in Linux

Complete steps for deploying jar package projects using Shell scripts in Linux

1. Install JDK

Check the computer's operating digits:
uname -ar

2017 x86_64 x86_64 x86_64 GNU/Linux
If it is shown here as 64-bit, download the corresponding 64-bit package

Download address of jdk, it is recommended to download the tar.gz package
www.oracle.com/technetwork…

Now start the official installation of JDK

1. Upload the jdk installation package to /root

jdk-8u131-linux-x64.tar.gz

2. Confirm whether the system has already installed JDK

rpm -qa|grep jdk
rpm -e --nodeps software name //If it is checked that it is installed, execute the uninstall command

3. Unzip the jdk installation package to the specified directory

tar -xvf jdk-8u131-linux-x64.tar.gz -C /usr/local/

4. Enter the decompression directory

cd /usr/local

5. Modify the jdk folder name

mv jdk1.8.0_131 jdk

6. Configure environment variables

Modify the environment variable configuration file:

vi /etc/profile

Press i to enter edit mode

Jump to the last line and add the following content. Please note that the JDK here should be consistent with the path where you installed JDK.

#java runtime setting
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=$JAVA_HOME/lib:.
export PATH=$JAVA_HOME/bin:$PATH

Press ESC and enter :wq to save and exit

7. Reload environment configuration

source /etc/profile

8. Test whether JDK installation is ok

java -version

9. Write hello.java

vi Hello.java

class Hello{
	public static void main(String[] args){
	System.out.println("hello,java");
	}
}

Then press ESC :wq to exit

vi /etc/profile i write

javac Hello.java

2. Deploy jar package

1. Create data, then create a test directory, and create related folders and files according to the following structure

The directory structure is:


Place the main jar package under app, such as myjar, and the following is the content of the related restart.sh:

#!/bin/bash

base_home='/data/test'
app_name='myjar'

pid=`ps -ef|grep ${app_name}|grep -v grep|grep -v restart|awk '{print$2}'`
if [ -n "${pid}" ] ;then
 kill -9 ${pid}
 sleep 10
fi

gclog_file=$base_home/log/gc.log
dump_dir=$base_home/heapdump
errorlogs_dir=$base_home/log

java -Xmx1g -Xms1g -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:GCLogFileSize=128M -XX:NumberOfGCLogFiles=1 -Xloggc:${gclog_file} -XX:HeapDumpPath=${dump_dir} -jar $base_home/app/${app_name}.jar --spring.config.location=$base_home/config/application.yml >> $base_home/log/${app_name}_$(date +'%Y%m%d').log &

It should be noted here that {app_name}.jar may contain the following errors:

Error: Unable to access jarfile /app/myjar.jar

Here you may need to change to an absolute path, as follows:

/datat/test/app/${app_name}.jar

Access the relevant path: (modify here according to the relevant port of your jar

http://ip:8080/

View the log path:

cd /log
Here, the log file with the name and date of the relevant jar package will be displayed, such as: myjar_20190530.log

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Linux shell script to start jar package
  • Shell script for one-click restart of Jar package and some experience sharing of new server deployment
  • How to start jar package with custom shell script in Linux

<<:  A practical record of restoring a MySQL Slave library

>>:  Vue two same-level components to achieve value transfer

Recommend

Explanation of nginx load balancing and reverse proxy

Table of contents Load Balancing Load balancing c...

JavaScript to achieve dynamic color change of table

This article shares the specific code for JavaScr...

Don't forget to close the HTML tag

Building web pages that comply with Web standards ...

CentOS7 64-bit installation mysql graphic tutorial

Prerequisites for installing MySQL: Install CentO...

Solve the problem of case sensitivity of Linux+Apache server URL

I encountered a problem today. When entering the ...

Detailed code examples of seven methods for vertical centering with CSS

When we edit a layout, we usually use horizontal ...

MySQL server 5.7.20 installation and configuration method graphic tutorial

This article records the installation and configu...

zabbix custom monitoring nginx status implementation process

Table of contents Zabbix custom monitoring nginx ...

What is jQuery used for? jQuery is actually a js framework

Introduction to jQuery The jQuery library can be ...

Detailed explanation of how to introduce custom fonts (font-face) in CSS

Why did I use this? It all started with the makin...

Detailed steps to install Nginx on Linux

1. Nginx installation steps 1.1 Official website ...

Using Apache ab to perform http performance testing

Mac comes with Apache environment Open Terminal a...