Java Service Deployment Specification (internal use)

Source: Internet
Author: User

1. Purpose

Java services need to be deployed in grayscale and production environments that reference this document.

2. Environment Preparation 2.1. Installing Java Cryptography Extension (JCE)

The JCE needs to be installed in the JVM for encryption and decryption.

    1. Download JCE from http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html.
    2. Replace the files below the lib/security under the JRE installation path with the Local_policy.jar and Us_export_policy.jar in the package.
2.2. Prepare the Td-config directory 2.2.1 Prepare the key file Tdkeys.jks

Copy the Tdkeys.jks of the production environment to the/usr/local/software/td-config directory

2.2.2. Preparing the enviroments environment variable file

Create the Enviroments file in the/usr/local/software/td-config directory, which is not the same as the grayscale environment and the production environment.
Grayscale Environment:

SERVICE_LOG_FOLDER=/data/logsEUREKA_URL="http://192.168.1.14:21111/eureka"

Production environment:

SERVICE_LOG_FOLDER=/data/logsEUREKA_URL="http://192.168.1.70:21111/eureka,http://192.168.1.71:21111/eureka,http://192.168.1.72:21111/eureka"
2.3. Create a/data/logs directory

If the directory does not exist, you need to create a/data/logs directory to hold the log file

3. Installation package

The installation package has 4 files:

    1. Apply jar packages, such as Financial-manager-core-1.0-snapshot.jar
    2. Service installation files, such as Financial-manager.service
    3. Service Installation Script Install
    4. Project configuration file Override.properties
3.1. Apply Jar Package

Generally provided by the development, later can be obtained from the CI environment.

3.2. Service installation files

Take the Financial-manager project as an example, the file name is Financial-manager.service and the script reads as follows:

[Unit]Description=financial-manager serviceAfter=syslog.target[Service]EnvironmentFile=/usr/local/software/td-config/enviromentsType=simpleExecStart=/usr/local/java/jdk/bin/java -server -Xms1024m -Xmx1024m -XX:+UseG1GC -verbose:gc -Xloggc:/data/logs/financial_manager_gc.log -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/data/logs -jar /usr/local/software/financial-manager/financial-manager-core-1.0-SNAPSHOT.jar --spring.config.location=/usr/local/software/financial-manager/override.propertiesRestart=alwaysRestartSec=10[Install]WantedBy=multi-user.target

Note that the path in this file must be an absolute path. What you need to modify:

    1. /usr/local/java/jdk/bin/java: This is the execution path of the Java command, and the environment and the machine are different, which may cause the command to execute differently.
    2. -Xms1024m -Xmx1024m: Java heap Memory size configuration, maximum memory and minimum memory should be the same, how much configuration depends on business determination.
    3. -Xloggc:/data/logs/financial_manager_gc.log: GC Log file path
    4. /usr/local/software/financial-manager/financial-manager-core-1.0-SNAPSHOT.jar: The path to the jar package.
    5. /usr/local/software/financial-manager/override.properties: Configuration file Override.properties path.
3.3. Service installation Script

Take the Financial-manager project as an example, the pin name is install, the script content is as follows:

#bash/bin!cp financial-manager.service /etc/systemd/system/systemctl enable financial-manager.service
3.4. Start the parameter file override.properties
server.port=9003 #启动端口logging.level.root=INFOlogging.level.com.tuandai=INFOlogging.level.cn.tdw=INFOspring.application.index=0 #实例编号, 具体见下面解释spring.cloud.config.profile=prev #启动环境, prev为灰度环境, prod为生产环境# 加解密相关encrypt.keyStore.location=file:///usr/local/software/td-config/tdkeys.jksencrypt.keyStore.password=4DpeZbUL^Xy%KdHm #需要替换为生产环境passwordencrypt.keyStore.alias=tdkeyencrypt.keyStore.secret=oQ$!3QnXm%&cS%GQ #需要替换为生产环境secret

What you need to modify:

    1. server.port: Modify the boot port
    2. spring.cloud.config.profile: Prev for grayscale environment, prod for production environment
    3. spring.application.index: Spring.application.index represents the instance number, and the instance number needs to be different for the same service. Assuming that integrated banking needs to deploy 4 instances in 192.168.1.70~73, the Spring.application.index needs to be configured for 0, 1, 2, 3 respectively. For example, the Spring.application.index on the 192.168.1.70 machine is set to 0, and the Spring.application.index on the 192.168.1.71 machine is set to 1.
    4. encrypt.keyStore.*: The key configuration for the production environment needs to be modified.
4. Installation Services

Run the install script to complete the installation

5. How to run, stop, and query the running status of the service
systemctl start user-servicesystemctl stop user-servicesystemctl status user-service
6. Sample Files

Sample file Visible Attachment

Java Service Deployment Specification (internal use)

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.