Centos 7 install jdk and package service service

I. Overview

There is a Spring Cloud jar package, the file name is: RDS.jar. The jdk1.8 version is required, and it needs to be deployed on the Centos 7.5 server. It is best to set it to start automatically!

Two, install jdk

Turn off the firewall

systemctl stop firewalld.service
systemctl disable firewalld.service

Install jdk

Unzip jdk

mkdir /data
tar zxvf jdk-8u211-linux-x64.tar.gz -C /data/

Add environment variables

vi /etc/profile

The inside is as follows:

set java environment
JAVA_HOME=/data/jdk1.8.0_211/
JRE_HOME=/data/jdk1.8.0_211/jre     
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH

Reload environment variables

source /etc/profile

View java version

# java -version
java version "1.8.0_211"Java(TM) SE Runtime Environment (build 1.8.0_211-b12)Java HotSpot(TM)64-Bit Server VM (build 25.211-b12, mixed mode)

Start java application

Create application directory

mkdir /data/rds/

Upload RDS.jar to this directory

Start the java application

 java -jar /data/rds/RDS.jar

JVM running for 11.918 appears, indicating that the startup is successful.

Three, package service service

Start script

Let's create a startup script first

vim /etc/init.d/rds

The content is as follows:

#! /bin/bash
#
# auditd        Start jar package
#
# chkconfig:23451188
# description: This is rds project
 
####### jar file path
export PROJECT_HOME=/data/rds/export PROJECT_NAME=RDS
#######

####### Start command
export START="source /etc/profile && cd $PROJECT_HOME;nohup java -jar ${PROJECT_HOME}/${PROJECT_NAME}.jar > output.log 2>&1 &"stop_jar(){for i in $(ps -aux|grep $PROJECT_NAME|grep -v grep|awk '{print $2}');do
  kill -9 $i;
 done
} case"$1"in
start)
  echo "Starting $PROJECT_NAME"
  eval $START
        ;;
 
stop)
  echo "Stop $PROJECT_NAME"
  stop_jar
        ;;
restart)
  echo "Stop $PROJECT_NAME..."
  stop_jar
  echo "Starting $PROJECT_NAME"
  eval $START
        ;;
esac

Package centos7 service

Enter the system directory and create a service file

cd /usr/lib/systemd/system/
vim rds.service

The content is as follows:

[ Unit] 
Description=rds - rds web server 
After=network.target remote-fs.target nss-lookup.target

[ Service] 
Type=forking 
ExecStart=/etc/init.d/rds start
ExecStop=/etc/init.d/rds stop
PrivateTmp=true[Install] 
WantedBy=multi-user.target

Description:

After the service script is written in accordance with the above, it is saved in the /usr/lib/systemd/system directory with 754 permissions
Then execute (modify or add files need to execute the following statement to take effect)

Load configuration

systemctl daemon-reload

Test start command

systemctl restart rds

Check if the java process exists

ps -aux|grep RDS

Set up auto start

systemctl enable rds

Reference link for this article:

https://www.cnblogs.com/lamp01/p/8932740.html

https://www.jianshu.com/p/6753bcc72ead

Recommended Posts

Centos 7 install jdk and package service service
CentOS 8 - install and configure NFS service
Centos7 uninstall openJdk, and install JDK1.8
CentOS install jdk
Install centos7 and connect
CentOS 7 install Docker service
Linux Centos7 install jdk1.8
CentOS7 install JDK8, tomcat8
Centos 7 install JDK (Linux install jdk)
CentOS7 uninstall OpenJDK, and then install Oracle JDK
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
centos7 install python3 and ipython
Know Linux and install CentOS
CentOS 7 install JAVA environment (JDK 1.8)
CentOs7.3 compile and install Nginx 1.9.9
CentOS 7 install Mono and MonoDevelop
CentOS6.5 install Java 8 and Tomcat8
Centos compile and install Git
Centos6.5 install and configure mongodb
Tencent Cloud Centos install jdk8
CentOS7 install python3 and pip3
Install Java JDK8 under CentOS6
CentOS7 install OracleJDK and JRE
CentOS6.5 install Java 8 and Tomcat8
CentOS6 install and crack Jira 7
CentOS6.5 install Java 8 and Tomcat8
Centos7 compile and install ntp-4.2.8p11
CentOS 6.9 compile and install python
CentOS6 install and crack confluence
CentOS 6 compile and install python 3
5.1. CentOS@ install JDK1.8 graphic tutorial
CentOS6 install and crack Jira 7
Basic service series-centos7 install JDK
How to install jdk1.8 on centOS7
CentOS7 yum install and start mysql
Install and configure keepalived under CentOS 5.9
Install JDK8 in rpm on CentOS7
CentOS Yum compile and install MySQL 5.6
Compile and install LAMP under Centos 5.2
CentOS 8 install Git and basic configuration
Minimal install JDK 1.8 tutorial in CentOS 7
CentOS8 install jdk8 / java8 tutorial (recommended)
Linux CentOS 7 install JDK detailed steps
CentOS 6.x compile and install Nginx
CentOS7 compile and install L(A|N)MP environment
CentOS7.3 install iptables and detailed use
CentOS quickly install Python3 and pip3
CentOS7 yum install and start mysql
Centos7 and centos8 install mysql5.6 5.7 8.0 so simple
Install Python3 and ansible under CentOS8
Install and use docker under CentOS 6.8
CentOS 7 Tomcat service installation and configuration
1.5 Install Centos7
CentOS7 install and use SQL Server
centos7 .*tar package to install MySQL5.7
CentOS Minimal install and configure TIPS
Install Python3 and Py under CentOS7
Install and configure FreeIPA in Centos7
Linux CentOS6 compile and install Pyt
virtualBox install centos, and build tomcat
Install Mono 3.2 and Jexus 5.4 under CentOS 6.3