Java process startup method, device, computer equipment and storage medium
The method and device for starting Java processes in microservices ensure accurate startup verification and log integrity by using nohup startup mode and hash-based tamper detection, addressing the inefficiencies and security risks of current methods.
Patent Information
- Application Number
- CN202010623512.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-30
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2040-06-30
AI Technical Summary
In microservice-based architectures, determining whether a Java service process has been successfully started is inaccurate and labor-intensive, and there is no effective method to detect log tampering, posing security risks and operational inefficiencies.
A method and device for starting a Java process that includes checking for process ID, port number, and jps information, using nohup startup mode to log output, and processing log content into hash-based reference data for tamper detection, ensuring accurate startup verification and log integrity.
Enables automated, intelligent, and secure startup verification of Java processes, reducing operational risks and improving efficiency by providing accurate startup information and tamper detection.
Smart Images

Figure CN111782372B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of microservice architecture, and in particular to a method, apparatus, computer device and storage medium for starting a Java process. Background Art
[0002] In the microservice-based architecture, more and more modules are developed or refactored based on Java. Efficient and reasonable start and stop operations on Java service processes (Java processes) during version releases can provide developers with sufficient and accurate information at the first time, which can effectively save start and stop troubleshooting during version releases.
[0003] The current service process startup logic cannot accurately determine whether the service process has been started successfully. After the service process is started, developers need to log in to each machine to determine whether the log is printed normally. This method is very labor-intensive and unintelligent for multiple redundant services in a microservice architecture. Logging in to the machine multiple times increases operational security risks. At the same time, the log content is prone to tampering, and currently it is impossible to provide reference data to detect whether the log has been tampered with. Summary of the invention
[0004] The main purpose of this application is to provide a Java process startup method, device, computer equipment and storage medium, aiming to overcome the current defect that it is impossible to accurately determine whether the service process is successfully started, and to overcome the defect that it is impossible to provide reference data for detecting whether the log has been tampered with.
[0005] To achieve the above purpose, the present application provides a method for starting a java process, comprising the following steps:
[0006] Check whether the process ID, port number, and jps information of the process all exist; wherein the process is a java process;
[0007] If none of them exist, it is determined that the process has not been started, then the process is started in the background using the nohup startup mode, and the nohup log is printed; wherein the console-level log in the log4j2.xml configuration file for printing the nohup log is annotated in advance;
[0008] Within a preset detection time period, detecting whether the port number of the process is listening at preset intervals;
[0009] If monitoring is performed within the preset detection time period, the process ID of the process is printed; the nohup log is saved in a local database, and the port number and process ID of the process are detected from the nohup log;
[0010] Extracting log text content in the nohup log, and adding the log text content to a preset layer to synthesize into a first picture;
[0011] The first image is processed in a preset manner to obtain target data, and the target data is stored; wherein the target data is used as reference data for detecting whether the log has been tampered with.
[0012] Furthermore, the step of processing the first image in a preset manner to obtain target data and storing the target data includes:
[0013] Performing a hash calculation on the first image to obtain a first hash value;
[0014] Combining the first hash value with the port number and the process ID of the process and performing a hash calculation to obtain a second hash value;
[0015] The second hash value and the correspondence between the second hash value and the process ID and the port number are uploaded as the target data to the management server for storage.
[0016] Furthermore, after the step of processing the first image in a preset manner to obtain target data and storing the target data, the method further includes:
[0017] Upon receiving an instruction to analyze the nohup log, calling the nohup log from a local database;
[0018] Detecting the port number and process ID of the process from the nohup log, and searching the management server for a corresponding second hash value according to the port number and process ID of the process;
[0019] Extracting log text content in the nohup log, and adding the log text content to a preset layer to synthesize into a second picture;
[0020] Performing a hash calculation on the second image to obtain a third hash value;
[0021] Combining the third hash value with the port number and the process ID of the process and performing a hash calculation to obtain a fourth hash value;
[0022] Determine whether the fourth Hash value is consistent with the second Hash value;
[0023] If they are consistent, then verify that the nohup log is correct, and analyze the nohup log based on a preset log analysis tool to obtain an analysis result.
[0024] Furthermore, the step of analyzing the nohup log based on a preset log analysis tool includes:
[0025] Obtain the total data volume of the log text content in the nohup log;
[0026] Analyze the log text content in the nohup log line by line to obtain corresponding analysis results, and record the total data volume of the analyzed log text content;
[0027] Create a blank document, add the analyzed log text content line by line to the blank document, create a preset array after each line of log text content in the blank document, and add the analysis result corresponding to each line of log text content to the preset array;
[0028] Determine whether the total data volume of the analyzed log text content is consistent with the total data volume of the log text content in the nohup log;
[0029] If they are consistent, the analysis is terminated, and the blank document with the log text content and the analysis result added is saved in the local database as an analysis result document.
[0030] Furthermore, the step of processing the first image in a preset manner to obtain target data and storing the target data includes:
[0031] Creating a signature layer, combining the port number and the process ID of the process and adding them to the signature layer, and then synthesizing the signature layer onto the first image to obtain a second image;
[0032] Obtaining the total data volume and the number of lines of the log text content in the nohup log, combining the total data volume and the number of lines to obtain an encryption password for encrypting the second image, and using the encrypted second image as target data;
[0033] The encrypted second image is saved in the local database.
[0034] The present application also provides a device for starting a java process, including:
[0035] A first detection unit is used to detect whether the process ID, port number, and jps information of the process all exist; wherein the process is a java process;
[0036] A first printing unit is used for, if none of them exist, determining that the process is not started, triggering to start the process in the background by using the nohup startup mode, and printing the nohup log; wherein the console-level log in the log4j2.xml configuration file for printing the nohup log is pre-annotated;
[0037] A second detection unit is used to detect whether the port number of the process is listening at every preset time interval within a preset detection time period;
[0038] A second printing unit is used to print the process ID of the process if the monitoring is performed within the preset detection time period; save the nohup log in a local database, and detect the port number and process ID of the process from the nohup log;
[0039] An extraction unit, used for extracting log text content in the nohup log, and adding the log text content to a preset layer to synthesize into a first picture;
[0040] A processing unit is used to process the first image in a preset manner to obtain target data, and store the target data; wherein the target data is used as reference data for detecting whether the log has been tampered with.
[0041] Furthermore, the processing unit comprises:
[0042] A first calculation subunit, configured to perform a hash calculation on the first image to obtain a first hash value;
[0043] A second calculation subunit, configured to combine the first hash value with the port number and the process ID of the process and perform hash calculation to obtain a second hash value;
[0044] The first storage subunit is used to upload the second hash value and the correspondence between the second hash value and the process ID and the port number as the target data to the management server for storage.
[0045] Furthermore, it also includes:
[0046] A calling unit, configured to call the nohup log from a local database upon receiving an instruction to analyze the nohup log;
[0047] A search unit, configured to detect the port number and process ID of the process from the nohup log, and search the corresponding second hash value from the management server according to the port number and process ID of the process;
[0048] A synthesis unit, used for extracting log text content in the nohup log, and adding the log text content to a preset layer to synthesize it into a second picture;
[0049] A first hash calculation unit, configured to perform a hash calculation on the second image to obtain a third hash value;
[0050] A second hash calculation unit, configured to combine the third hash value with the port number and the process ID of the process and then perform hash calculation to obtain a fourth hash value;
[0051] a determination unit, configured to determine whether the fourth Hash value is consistent with the second Hash value;
[0052] The analyzing unit is used for verifying that the nohup log is correct if the fourth hash value is consistent with the second hash value, and analyzing the nohup log based on a preset log analysis tool to obtain an analysis result.
[0053] Furthermore, the analysis unit is specifically used for:
[0054] Obtain the total data volume of the log text content in the nohup log;
[0055] Analyze the log text content in the nohup log line by line to obtain corresponding analysis results, and record the total data volume of the analyzed log text content;
[0056] Create a blank document, add the analyzed log text content line by line to the blank document, create a preset array after each line of log text content in the blank document, and add the analysis result corresponding to each line of log text content to the preset array;
[0057] Determine whether the total data volume of the analyzed log text content is consistent with the total data volume of the log text content in the nohup log;
[0058] If they are consistent, the analysis is terminated, and the blank document with the log text content and the analysis result added is saved in the local database as an analysis result document.
[0059] Furthermore, the processing unit comprises:
[0060] A creation subunit is used to create a signature layer, and after combining the port number and process ID of the process, add them to the signature layer, and synthesize the signature layer onto the first picture to obtain a second picture;
[0061] an encryption subunit, used for obtaining the total data volume and the number of lines of the log text content in the nohup log, combining the total data volume and the number of lines to obtain an encryption password, which is used for encrypting the second image, and using the encrypted second image as target data;
[0062] The second storage subunit is used to store the encrypted second image in a local database.
[0063] The present application also provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the above methods when executing the computer program.
[0064] The present application also provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of any of the above-mentioned methods are implemented.
[0065] The method, device, computer equipment and storage medium for starting a java process provided by the present application include: detecting whether the process ID, port number and jps information of the process all exist; if none of them exist, it is determined that the process has not been started, triggering the process to be started in the background using the nohup startup method, and printing the nohup log; within a preset detection time period, detecting whether the port number of the process is monitored at intervals of a preset time; thereby accurately determining whether the service process is successfully started. If it is monitored within the preset detection time period, the process ID of the process is printed; and the nohup log is saved in a local database, and the port number and process ID of the process are detected from the nohup log; the log text content in the nohup log is extracted, and the log text content is added to the preset layer to be synthesized into a first picture; the first picture is processed in a preset manner to obtain target data, and the target data is stored; wherein the target data is used as reference data for detecting whether the log has been tampered with. The log text content in the nohup log is converted into target data for storage, and even if the log is tampered with, it can be compared based on the above target data to verify whether the log has been tampered with. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] Figure 1 This is a schematic diagram of the steps of a method for starting a Java process in an embodiment of the present application;
[0067] Figure 2 It is a structural block diagram of a device for starting a Java process in an embodiment of the present application;
[0068] Figure 3 A schematic block diagram of the structure of a computer device according to an embodiment of the present application.
[0069] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0070] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0071] Reference Figure 1 In one embodiment of the present application, a method for starting a Java process is provided, comprising the following steps:
[0072] Step S1, detecting whether the process ID, port number, and jps information of the process all exist; wherein the process is a java process;
[0073] Step S2, if none of them exist, it is determined that the process has not been started, then triggering the process to be started in the background using the nohup startup mode, and printing the nohup log; wherein the console-level log in the log4j2.xml configuration file for printing the nohup log is pre-annotated;
[0074] Step S3, within a preset detection time period, detecting whether the port number of the process is listening at every preset time interval;
[0075] Step S4, if monitoring is performed within the preset detection time period, printing the process ID of the process; saving the nohup log in a local database, and detecting the port number and process ID of the process from the nohup log;
[0076] Step S5, extracting log text content in the nohup log, and adding the log text content to a preset layer to synthesize into a first picture;
[0077] Step S6, processing the first image in a preset manner to obtain target data, and storing the target data; wherein the target data is used as reference data for detecting whether the log has been tampered with.
[0078] In this embodiment, the above method is applied to the Java process start and stop operation scenario during the application version release in the microservice architecture. In order to provide accurate information for development, it is necessary to determine whether the process is started successfully.
[0079] Specifically, as described in the above step S1, the process ID, port number, and jps information ($JAVA_HOME / bin / jps-l|grep$APP_MAIN) of the detection process are all present. The above parameters are the parameters that a process has when it is running normally. If the above parameters all exist, it indicates that the process is currently in a normal running state and no startup operation is required. If any of the above parameters does not exist, it indicates that the process is not running normally and needs to be started. The above-mentioned abnormal running state includes: not running and an error occurs during running.
[0080] As described in the above step S2, if the process ID, port number, and jps information do not exist, it indicates that the process has not been started and it is necessary to enter the startup logic. In the present embodiment, the process is started by using the nohup startup mode (command operation mode) triggered in the background. When starting the above process, it is also necessary to output the nohup log. When the above nohup starts the process, only error information can be output to the nohup log; the above nohup log can simultaneously realize the recording log and screen output, which is convenient for developers to quickly view the nohup log when the process fails, quickly locate the problem, and reduce the troubleshooting time during the release period. Since the above nohup log capacity is large, in order to avoid a large number of logs when the above process is running, it is necessary to annotate the console-level log in the log4j2.xml configuration file that prints the nohup log in advance to avoid causing disk alarms.
[0081] As described in the above steps S3-S4, a detection time period is pre-set, and within the detection time period, the port number is detected at a preset interval (for example, every 1 second) to see if it is listening. If the port number still fails to listen after exceeding the above preset detection time period, the startup script is automatically exited and a startup failure error is reported; if the port number is normally listened within the above detection time period, it indicates that the process can run normally, then the process ID is printed, and the startup script is exited to complete the startup of the process. At this time, the jps information is also automatically generated.
[0082] As described in the above steps S5-S6, it can be understood that in order to verify whether the above nohup log has been tampered with, it is necessary to save it in a local database; currently, when verifying whether the log has been changed, the method usually adopted is to compare the log with the pre-stored log line by line, and the comparison process is relatively redundant and the comparison efficiency is low. Therefore, in this embodiment, because the log is usually easy to change the format due to different equipment or human error, a first image is generated based on the log text content to solidify the log text content. The above first image is converted to obtain target data, and the target data is used as reference data for detecting whether the log has been tampered with. When it is necessary to verify whether the log has been tampered with, it is only necessary to convert the log into target data in the same way, and then compare the target data, so that it can be quickly detected whether the log has been tampered with.
[0083] In this embodiment, when judging whether a process is started, a comprehensive judgment is made based on multiple parameters, and the judgment is more comprehensive. It can accurately determine whether the process is successfully started, and there is no need to log in to each machine to check the log to confirm whether the process is successfully started. The workload of developers involved in the publishing process is reduced, and the publishing process is automated and intelligent. While outputting the nohup log, the console shields the console output of java after the annotation, reducing the amount of logs. The nohup log can also realize screen output at the same time, and the error can be output directly to the web interface. There is no need to log in to the machine again to check the log and troubleshoot errors, improve the publishing experience, and also reduce the number of ssh logins by development or operation and maintenance personnel, improve operational safety, and enhance the publishing experience. The nohup log is converted into target data, and the target data is used as reference data for detecting whether the log has been tampered with, which is convenient for improving the efficiency of detecting whether the log has been tampered with.
[0084] In one embodiment, the step S6 of processing the first image in a preset manner to obtain target data and storing the target data includes:
[0085] Step S61, performing a hash calculation on the first image to obtain a first hash value;
[0086] Step S62, combining the first hash value with the port number and process ID of the process and performing hash calculation to obtain a second hash value;
[0087] Step S63: Upload the second hash value and the correspondence between the second hash value and the process ID and the port number as the target data to the management server for storage.
[0088] In this embodiment, in order to facilitate subsequent verification / testing, the nohup log needs to be saved in a local database; in order to facilitate users to obtain accurate information from the nohup log, the nohup log should be prevented from being tampered with; and the nohup log saved in the local database is prone to tampering, so the nohup log can usually be saved to the management server, but it will increase the storage pressure of the management server. Therefore, in this embodiment, the nohup log is saved in the local database, and the nohup log will not be saved to the management server, but only the log text content in the nohup log is added to the preset layer to synthesize into a first picture; then the first picture is hashed to obtain a first hash value, and in order to further express the association between the second hash value uploaded to the management server and the port number and process ID of the process, the first hash value is combined with the port number and process ID of the process and then hashed to obtain a second hash value, and finally the second hash value, the corresponding relationship between the second hash value and the process ID and the port number are uploaded to the management server. In this embodiment, only the second hash value and the correspondence between the second hash value and the process ID and the port number are uploaded to the management server, which will not increase the storage pressure of the management server too much, and the above second hash value can be used as strong evidence for subsequent verification of whether the nohup log in the local database is valid.
[0089] In this embodiment, after the step S6 of processing the first image in a preset manner to obtain target data and storing the target data, the method further includes:
[0090] Step S7, when receiving an instruction to analyze the nohup log, calling the nohup log from a local database;
[0091] Step S8, detecting the port number and process ID of the process from the nohup log, and searching the management server for a corresponding second hash value according to the port number and process ID of the process;
[0092] Step S9, extracting log text content in the nohup log, and adding the log text content to a preset layer to synthesize into a second picture;
[0093] Step S10, performing a hash calculation on the second image to obtain a third hash value;
[0094] Step S11, combining the third hash value with the port number and process ID of the process and performing hash calculation to obtain a fourth hash value;
[0095] Step S12, determining whether the fourth Hash value is consistent with the second Hash value;
[0096] Step S13: If they are consistent, verify that the nohup log is correct, and analyze the nohup log based on a preset log analysis tool to obtain an analysis result.
[0097] In this embodiment, when an instruction to analyze the nohup log is received, it is only necessary to extract the nohup log from the local database, and based on the same image generation process, the hash calculation process obtains the fourth hash value, and verifies whether the fourth hash value is consistent with the second hash value. If they are consistent, it is verified that the nohup log is correct. If the nohup log is valid, the preset log analysis tool can be used to analyze the nohup log to obtain a correct analysis result.
[0098] In this embodiment, the step S13 of analyzing the nohup log based on a preset log analysis tool includes:
[0099] Step S131, obtaining the total data volume of the log text content in the nohup log;
[0100] Step S132, analyzing the log text content in the nohup log line by line, obtaining corresponding analysis results, and recording the total data volume of the analyzed log text content;
[0101] Step S133, creating a blank document, adding the analyzed log text content line by line to the blank document, creating a preset array after each line of log text content in the blank document, and adding the analysis result corresponding to each line of log text content to the preset array;
[0102] Step S134, determining whether the total data volume of the analyzed log text content is consistent with the total data volume of the log text content in the nohup log;
[0103] Step S135: if they are consistent, the analysis is terminated, and the blank document with the log text content and the analysis result added is saved in the local database as an analysis result document.
[0104] In this embodiment, when analyzing the above-mentioned nohup log, the log text content is analyzed line by line, and after the line by line analysis, the analyzed log text content is added line by line to the blank document, and in order to strengthen the correlation between the analysis result and each line of log text content, the analysis result is added to a preset array, and the preset array is set after each line of log text content. In this way, the analysis result of the log text content can be found in the same line.
[0105] After all log text contents are analyzed, a blank document with the log text contents and analysis results added thereto is saved in a local database as an analysis result document for easy inspection.
[0106] In another embodiment, the step S6 of processing the first image in a preset manner to obtain target data and storing the target data includes:
[0107] Step S601, creating a signature layer, combining the port number and process ID of the process and adding them to the signature layer, and then synthesizing the signature layer onto the first image to obtain a second image;
[0108] Step S602, obtaining the total data volume and the number of lines of the log text content in the nohup log, combining the total data volume and the number of lines to obtain an encryption password for encrypting the second image, and using the encrypted second image as target data;
[0109] Step S603: save the encrypted second image in a local database.
[0110] In this embodiment, another solution is proposed to prevent the nohup log from being tampered with; the nohup log is saved in a local database for subsequent verification. At the same time, the log text content in the nohup log is added to the preset layer to synthesize into a first picture; then, as described in step S601, a signature layer is created, and the port number and process ID of the process are combined and added to the signature layer, and the signature layer is synthesized onto the first picture to obtain a second picture; that is, the second picture not only includes the log text content, but also is stamped with a signature layer, so that the log text content can be easily identified from the signature layer. Further, as described in step S602, in order to prevent the second picture from being leaked, it needs to be encrypted; the encryption password used in this embodiment is obtained by combining the total data volume and the number of lines of the log text content in the nohup log. The above data volume and the number of lines can truly reflect the properties of the nohup log. If the nohup log is tampered with, its data volume and the number of lines will change accordingly.
[0111] When verifying whether the nohup log in the above-mentioned local database is valid, it is only necessary to obtain the port number and process ID of the process in the nohup log, as well as the total data volume and number of lines of the nohup log in the above-mentioned local database, and combine the total data volume and number of lines to obtain a decryption password; use the decryption password to decrypt the above-mentioned second image. If the decryption is unsuccessful, it indicates that the nohup log in the above-mentioned local database has been tampered with; if the decryption is successful, compare the port number and process ID of the process carried in the signature layer in the above-mentioned second image with the port number and process ID of the process in the nohup log in the above-mentioned local database to see if they are consistent; if they are consistent, it is verified that the nohup log in the above-mentioned local database is valid; if they are inconsistent, it is verified that the nohup log is invalid.
[0112] In the above embodiment, when one of the process ID and port number parameters does not exist, it indicates that the process is in an error state during operation;
[0113] After the step S1 of detecting whether the process ID, port number, and jps information of the process all exist, the method further includes:
[0114] If the process ID exists and the port number does not exist, it is determined that the process is being started or the process is abnormal;
[0115] If the process ID does not exist and the port number exists, the port number is determined to be misconfigured. At this point, it can be shown that the port number is configured to a monitored process, and developers can quickly identify the root cause of the problem based on the log output, without having to use ssh to log in to the machine for secondary troubleshooting, saving time in troubleshooting.
[0116] In one embodiment, the step S6 of processing the first image in a preset manner to obtain target data and storing the target data includes:
[0117] Acquire the storage data volume of the first picture, and determine whether the storage data volume is greater than a threshold;
[0118] If it is greater than, the center of the first picture is detected, and a rectangular frame is made with the center as the geometric center; wherein the length and width of the rectangular frame are preset values;
[0119] Performing image cropping with the border in the rectangular frame to obtain a first sub-image in the rectangular frame and a second sub-image outside the rectangular frame;
[0120] Acquire the amount of stored data of the second sub-image, and determine whether the amount of stored data of the second sub-image is greater than a threshold;
[0121] If the storage data volume of the second sub-image is not greater than a preset value, the first sub-image and the second sub-image are taken together as the target data and uploaded to the management server for storage.
[0122] In this embodiment, if the amount of stored data of the above-mentioned first image is too large, it is easy to cause the inability to upload to the management server. Therefore, it needs to be cropped, and the ordinary cropping method is easy to reduce the quality of the image and affect the subsequent reading. In this embodiment, the geometric center of the above-mentioned first image is used as a rectangular frame, and then the rectangular frame is used as a border for cropping to obtain the first sub-image and the second sub-image. This process can not only reduce the amount of data of the image, but also will not reduce the image's attributes such as pixels and resolution. At the same time, after uploading to the management server, if the above-mentioned first sub-image and the second sub-image need to be spliced, it is only necessary to fill the first sub-image into the blank space in the second sub-image; due to the size of the first sub-image and the limitation of the blank area in the second sub-image, only the first sub-image can be spliced into the above-mentioned second sub-image, and images of other sizes cannot be spliced, so as to avoid confusion between images.
[0123] Reference Figure 2 In one embodiment of the present application, a device for starting a Java process is also provided, including:
[0124] The first detection unit 10 is used to detect whether the process ID, port number, and jps information of the process all exist; wherein the process is a java process;
[0125] The first printing unit 20 is used for, if none of them exist, determining that the process is not started, triggering to start the process in the background by using the nohup startup mode, and printing the nohup log; wherein the console-level log in the log4j2.xml configuration file for printing the nohup log is pre-annotated;
[0126] The second detection unit 30 is used to detect whether the port number of the process is listening at every preset time interval within a preset detection time period;
[0127] The second printing unit 40 is used to print the process ID of the process if the monitoring is performed within the preset detection time period; save the nohup log in a local database, and detect the port number and process ID of the process from the nohup log;
[0128] An extraction unit 50 is used to extract log text content in the nohup log and add the log text content to a preset layer to synthesize it into a first picture;
[0129] The processing unit 60 is used to process the first image in a preset manner to obtain target data, and store the target data; wherein the target data is used as reference data for detecting whether the log has been tampered with.
[0130] In one embodiment, the processing unit 60 includes:
[0131] A first calculation subunit, configured to perform a hash calculation on the first image to obtain a first hash value;
[0132] A second calculation subunit, configured to combine the first hash value with the port number and the process ID of the process and perform hash calculation to obtain a second hash value;
[0133] The first storage subunit is used to upload the second hash value and the correspondence between the second hash value and the process ID and the port number as the target data to the management server for storage.
[0134] In another embodiment, the above device further includes:
[0135] A calling unit, configured to call the nohup log from a local database upon receiving an instruction to analyze the nohup log;
[0136] A search unit, configured to detect the port number and process ID of the process from the nohup log, and search the corresponding second hash value from the management server according to the port number and process ID of the process;
[0137] A synthesis unit, used for extracting log text content in the nohup log, and adding the log text content to a preset layer to synthesize it into a second picture;
[0138] A first hash calculation unit, configured to perform a hash calculation on the second image to obtain a third hash value;
[0139] A second hash calculation unit, configured to combine the third hash value with the port number and the process ID of the process and then perform hash calculation to obtain a fourth hash value;
[0140] a determination unit, configured to determine whether the fourth Hash value is consistent with the second Hash value;
[0141] The analyzing unit is used for verifying that the nohup log is correct if the fourth hash value is consistent with the second hash value, and analyzing the nohup log based on a preset log analysis tool to obtain an analysis result.
[0142] In one embodiment, the analysis unit is specifically used for:
[0143] Obtain the total data volume of the log text content in the nohup log;
[0144] Analyze the log text content in the nohup log line by line to obtain corresponding analysis results, and record the total data volume of the analyzed log text content;
[0145] Create a blank document, add the analyzed log text content line by line to the blank document, create a preset array after each line of log text content in the blank document, and add the analysis result corresponding to each line of log text content to the preset array;
[0146] Determine whether the total data volume of the analyzed log text content is consistent with the total data volume of the log text content in the nohup log;
[0147] If they are consistent, the analysis is terminated, and the blank document with the log text content and the analysis result added is saved in the local database as an analysis result document.
[0148] In another embodiment, the processing unit 60 includes:
[0149] A creation subunit is used to create a signature layer, and after combining the port number and process ID of the process, add them to the signature layer, and synthesize the signature layer onto the first picture to obtain a second picture;
[0150] an encryption subunit, used for obtaining the total data volume and the number of lines of the log text content in the nohup log, combining the total data volume and the number of lines to obtain an encryption password, which is used for encrypting the second image, and using the encrypted second image as target data;
[0151] The second storage subunit is used to store the encrypted second image in a local database.
[0152] In this embodiment, the specific implementation of the above-mentioned units and sub-units please refer to the description in the above-mentioned method embodiment, which will not be repeated here.
[0153] Reference Figure 3 In an embodiment of the present application, a computer device is also provided. The computer device may be a server, and its internal structure may be as follows: Figure 3As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor designed by the computer is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store log data, etc. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for starting a java process is implemented.
[0154] Those skilled in the art will understand that Figure 3 The structure shown in is merely a block diagram of a portion of the structure related to the present application solution and does not constitute a limitation on the computer device to which the present application solution is applied.
[0155] An embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, a method for starting a Java process is implemented. It can be understood that the computer-readable storage medium in this embodiment can be a volatile readable storage medium or a non-volatile readable storage medium.
[0156] In summary, the method, device, computer equipment and storage medium for starting a java process provided in the embodiment of the present application include: detecting whether the process ID, port number and jps information of the process all exist; if none of them exist, it is determined that the process has not been started, then triggering the use of nohup startup mode in the background to start the process, and printing the nohup log; within a preset detection time period, every preset interval to detect whether the port number of the process is listening; in this way, it is accurately determined whether the service process is successfully started. If listening within the preset detection time period, the process ID of the process is printed; and the nohup log is saved in the local database, and the port number and process ID of the process are detected from the nohup log; the log text content in the nohup log is extracted, and the log text content is added to the preset layer to synthesize into a first picture; the first picture is processed in a preset manner to obtain target data, and the target data is stored; wherein the target data is used as reference data for detecting whether the log has been tampered with. The log text content in the nohup log is converted into target data for saving. Even if the log is tampered with, it can be compared based on the above target data to verify whether the log has been tampered with.
[0157] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media provided in this application and used in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0158] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the presence of other identical elements in the process, device, article or method including the element.
[0159] The above description is only a preferred embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly used in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for starting a java process, characterized in that: The following steps are involved: Check whether the process ID, port number, and jps information of the process all exist; wherein the process is a java process; If none of them exist, it is determined that the process has not been started, then the process is started in the background using the nohup startup mode, and the nohup log is printed; wherein the console-level log in the log4j2.xml configuration file for printing the nohup log is annotated in advance; Within a preset detection time period, detecting whether the port number of the process is listening at preset intervals; If monitoring is performed within the preset detection time period, the process ID of the process is printed; the nohup log is saved in a local database, and the port number and process ID of the process are detected from the nohup log; Extracting log text content in the nohup log, and adding the log text content to a preset layer to synthesize into a first picture; Processing the first image in a preset manner to obtain target data, and storing the target data; wherein the target data is used as reference data for detecting whether the log has been tampered with; The step of processing the first image in a preset manner to obtain target data and storing the target data includes: Performing a hash calculation on the first image to obtain a first hash value; Combining the first hash value with the port number and the process ID of the process and performing a hash calculation to obtain a second hash value; Uploading the second hash value and the correspondence between the second hash value and the process ID and the port number as target data to a management server for storage; The step of processing the first image in a preset manner to obtain target data and storing the target data includes: Creating a signature layer, combining the port number and the process ID of the process and adding them to the signature layer, and then synthesizing the signature layer onto the first image to obtain a second image; Obtaining the total data volume and the number of lines of the log text content in the nohup log, combining the total data volume and the number of lines to obtain an encryption password for encrypting the second image, and using the encrypted second image as the target data; The encrypted second image is saved in the local database.
2. The method for starting a Java process according to claim 1, characterized in that: After the step of processing the first image in a preset manner to obtain target data and storing the target data, the method further includes: Upon receiving an instruction to analyze the nohup log, calling the nohup log from a local database; Detecting the port number and process ID of the process from the nohup log, and searching the management server for a corresponding second hash value according to the port number and process ID of the process; Extracting log text content in the nohup log, and adding the log text content to a preset layer to synthesize into a second picture; Performing a hash calculation on the second image to obtain a third hash value; Combining the third hash value with the port number and process ID of the process and performing hash calculation to obtain a fourth hash value; Determine whether the fourth Hash value is consistent with the second Hash value; If they are consistent, then verify that the nohup log is correct, and analyze the nohup log based on a preset log analysis tool to obtain an analysis result.
3. The method for starting a Java process according to claim 2, characterized in that: The step of analyzing the nohup log based on a preset log analysis tool includes: Obtain the total data volume of the log text content in the nohup log; Analyze the log text content in the nohup log line by line to obtain corresponding analysis results, and record the total data volume of the analyzed log text content; Create a blank document, add the analyzed log text content line by line to the blank document, create a preset array after each line of log text content in the blank document, and add the analysis result corresponding to each line of log text content to the preset array; Determine whether the total data volume of the analyzed log text content is consistent with the total data volume of the log text content in the nohup log; If they are consistent, the analysis is terminated, and the blank document with the log text content and the analysis result added is saved in the local database as an analysis result document.
4. A java process startup device, used to execute the method described in any one of claims 1 to 3, characterized in that: include: A first detection unit is used to detect whether the process ID, port number, and jps information of the process all exist; wherein the process is a java process; A first printing unit is used for, if none of them exist, determining that the process is not started, triggering to start the process in the background by using the nohup startup mode, and printing the nohup log; wherein the console-level log in the log4j2.xml configuration file for printing the nohup log is pre-annotated; A second detection unit is used to detect whether the port number of the process is listening at every preset time interval within a preset detection time period; A second printing unit is used to print the process ID of the process if the monitoring is performed within the preset detection time period; save the nohup log in a local database, and detect the port number and process ID of the process from the nohup log; An extraction unit, used for extracting log text content in the nohup log, and adding the log text content to a preset layer to synthesize into a first picture; A processing unit is used to process the first image in a preset manner to obtain target data, and store the target data; wherein the target data is used as reference data for detecting whether the log has been tampered with.
5. The java process startup device according to claim 4, characterized in that: The processing unit comprises: A first calculation subunit, configured to perform a hash calculation on the first image to obtain a first hash value; A second calculation subunit, configured to combine the first hash value with the port number and the process ID of the process and perform hash calculation to obtain a second hash value; The first storage subunit is used to upload the second hash value and the correspondence between the second hash value and the process ID and the port number as the target data to the management server for storage.
6. The device for starting a Java process according to claim 5, characterized in that: Also includes: A calling unit, configured to call the nohup log from a local database upon receiving an instruction to analyze the nohup log; A search unit, configured to detect the port number and process ID of the process from the nohup log, and search the corresponding second hash value from the management server according to the port number and process ID of the process; A synthesis unit, used for extracting log text content in the nohup log, and adding the log text content to a preset layer to synthesize it into a second picture; A first hash calculation unit, configured to perform a hash calculation on the second image to obtain a third hash value; A second hash calculation unit, configured to combine the third hash value with the port number and the process ID of the process and then perform hash calculation to obtain a fourth hash value; a determination unit, configured to determine whether the fourth Hash value is consistent with the second Hash value; The analyzing unit is used for verifying that the nohup log is correct if the fourth hash value is consistent with the second hash value, and analyzing the nohup log based on a preset log analysis tool to obtain an analysis result.
7. A computer device comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 3 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
System and method for remote device registration
CN103152173A
Log data storage method and device based on cassandra database and computer device
CN110188081A
Log storage and reading method and device based on block chain, equipment and medium
CN110839015A
