WO2021082081A1 - 动态修改Nginx配置参数的方法、系统、装置及存储介质 - Google Patents

动态修改Nginx配置参数的方法、系统、装置及存储介质 Download PDF

Info

Publication number
WO2021082081A1
WO2021082081A1 PCT/CN2019/118290 CN2019118290W WO2021082081A1 WO 2021082081 A1 WO2021082081 A1 WO 2021082081A1 CN 2019118290 W CN2019118290 W CN 2019118290W WO 2021082081 A1 WO2021082081 A1 WO 2021082081A1
Authority
WO
WIPO (PCT)
Prior art keywords
configuration file
configuration
version number
nginx
parsed
Prior art date
Application number
PCT/CN2019/118290
Other languages
English (en)
French (fr)
Inventor
雷林凯
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2021082081A1 publication Critical patent/WO2021082081A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/2866Architectures; Arrangements
    • H04L67/30Profiles
    • H04L67/303Terminal profiles
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • This application relates to the technical field of server processing, and more specifically, to a method, system, device, and storage medium for dynamically modifying Nginx configuration parameters.
  • Nginx (engine x) is a lightweight open source web server software, as the currently very popular HTTP (Hypertext Transfer Protocol) and reverse proxy Web (World Wide Web, Internet) server, and also an IMAP (Internet Mail Access Protocol) , Interactive Mail Access Protocol), POP3 (Post Office Protocol 3, the third version of Post Office Protocol), SMTP (Simple Mail Transfer Protocol, Simple Mail Transfer Protocol) proxy server, rich and flexible parameter configuration mechanism to ensure that Nginx is extremely Powerful module expandability and functions.
  • HTTP Hypertext Transfer Protocol
  • reverse proxy Web World Wide Web, Internet
  • IMAP Internet Mail Access Protocol
  • POP3 Post Office Protocol 3
  • SMTP Simple Mail Transfer Protocol
  • Simple Mail Transfer Protocol Simple Mail Transfer Protocol
  • Nginx is a multi-process architecture.
  • the nginx process on a single host has a management process and multiple independent work processes. Generally, the number of work processes is equal to the number of cores of the cpu.
  • the management process accepts client requests and transfers them to the work process for processing. , So as to make good use of the computing power of the cpu.
  • the management process does not process the client network request, the client network request is processed by the worker process, only one of the worker processes may handle the request, and the management process is responsible for managing these worker processes, such as when a worker process exits (abnormal Circumstances), responsible for starting new work processes, and for example, notifying all work processes to exit smoothly.
  • Nginx configuration file Every time you change the Nginx configuration, you must manually modify the Nginx configuration file. After the configuration file is replaced, reload the configuration file, and configure Nginx according to the new configuration file, that is, the management process is determined according to the configuration information in the original configuration file. When the business service of the created original work process ends, then according to the configuration information in the new configuration file, a new work process is created, the new work process is activated, and the original work process is closed.
  • the management process does not stop in most scenarios in the process of Nginx reloading the configuration file, the client request will not be missed.
  • the applicant realizes that there are still the following problems: 1. After each configuration change, the management process must recreate the work process based on the new configuration file and close the original work process. This process is more cumbersome and time-consuming, which increases management. The workload of the process. 2. To edit the Nginx configuration file, you need to be familiar with Nginx development and operation personnel to modify it, you need to have certain professional knowledge, and directly modify the Nginx configuration file, it is easy to cause grammatical and textual errors, and the configuration file is unavailable.
  • the purpose of this application is to provide a method, system, device and storage medium for dynamically modifying Nginx configuration parameters. Realize the dynamic modification of Nginx configuration parameters without restarting the work process.
  • a method for dynamically modifying Nginx configuration parameters includes the following steps:
  • Nginx periodically initiates a configuration file obtaining http request to the Tomcat, obtains the configuration file and extracts its version number, compares the extracted version number with the version number of the configuration file in the shared memory, if the extracted version If the number is larger than the version number of the configuration file in the shared memory, the configuration file is parsed, and the parsed configuration file and its version number are updated to the shared memory;
  • the Nginx work process periodically extracts the version number of the parsed configuration file from the shared memory, and compares the version number of the parsed configuration file with the version of the configuration file inside the work process If the version number of the parsed configuration file is greater than the version of the configuration file inside the working process, the working process extracts the parsed configuration file and its version number in the shared memory to update all Describe the corresponding configuration information variables within the working process.
  • a system for dynamically modifying Nginx configuration parameters including:
  • Web configuration interface unit used to generate configuration parameters
  • the Tomcat unit is used to obtain the configuration parameters generated by the Web configuration interface unit, generate a configuration file according to the configuration parameters, and compare the configuration file with the original configuration file in the Tomcat unit. If some configuration files are inconsistent, the configuration file replaces the original configuration file, a unique version number is generated for the configuration file, and the version number is associated with the corresponding configuration file;
  • the database unit is used to store the version number and the corresponding configuration file
  • the Nginx unit is used for every set cycle time, a work process of the Nginx unit initiates a configuration file acquisition http request to the Tomcat unit. After the work process extracts the version number of the configuration file, it shares memory with Compare the version numbers of the configuration files already in the unit. If the version number of the configuration file is larger than the version number of the configuration file already in the shared memory unit, then the configuration file is parsed, and the parsed configuration file is compared with The version number is updated to the shared memory unit; the work process periodically extracts the version number of the parsed configuration file from the shared memory unit, and compares the version number of the parsed configuration file with the version number of the work process. Configuration file version number. If the version number of the parsed configuration file is greater than the version of the configuration file inside the working process, the working process extracts the parsed configuration file and its version number in the shared memory to update Configuration information variables inside the work process;
  • the shared memory unit is used to store the latest parsed configuration file and its version number.
  • the present application also provides an electronic device, including a memory and a processor, and a computer program is stored in the memory.
  • a computer program is stored in the memory.
  • This application also provides a computer-readable storage medium that includes a program for dynamically modifying Nginx configuration parameters, and when the program for dynamically modifying Nginx configuration parameters is executed by a processor, the above-mentioned dynamic modification of Nginx configuration is realized The steps of the parametric method.
  • each configuration file is assigned a version number, the latest configuration file and its version number are stored in the shared memory, and each worker process actively obtains the latest in the shared memory periodically.
  • the version number of the configuration file and by comparing the size of the version number, determine whether to update the configuration file. If the configuration needs to be updated, the information in the shared memory is assigned to the corresponding configuration information variable in the working process. Realizes the dynamic modification of Nginx configuration parameters, and realizes that the work process does not need to be recreated and restarted to make the new configuration parameters take effect.
  • the whole process is efficient and reliable, and has zero impact on the client's business. It is suitable for business scenarios with large traffic and high reliability requirements.
  • Figure 1 shows a flowchart of a method for dynamically modifying Nginx configuration parameters according to Embodiment 1 of the present application
  • Figure 2 shows a schematic diagram of the logical structure of a system for dynamically modifying Nginx configuration parameters according to Embodiment 2 of the present application;
  • FIG. 3 shows a schematic diagram of a logical structure of an electronic device according to Embodiment 3 of the present application
  • Figure 4 shows a Web configuration interface for bucket current limiting parameter setting according to Embodiment 1 of the present application
  • FIG. 5 shows a Web configuration interface for current limiting parameter setting of an IP address according to Embodiment 1 of the present application
  • Figure 6 shows a web configuration interface for bucket cache settings according to Embodiment 1 of the present application.
  • Tomcat is a web container based on java servlet (a small application running on the server in the Java language). Tomcat itself can be used as a separate web server to obtain dynamic resources. It is lightweight application server. Tomcat of this application is the back-end service process of the Web configuration interface, which is used to persistently receive the configuration parameters of the Web configuration interface, and receive and respond to http requests (request messages from the client to the server).
  • the Nginx process has a mutex (mutual exclusion lock), that is, each worker process of Nginx needs to acquire a mutex before executing an http request to ensure that only one worker process initiates an http request at the same time. If a worker process obtains the mutex lock, the worker process initiates an http request; the worker process that cannot obtain the mutex lock gives up executing the HTTP request, so that it is guaranteed that only one worker process initiates the http request at the same time , So as not to block the sending request.
  • mutex partial exclusion lock
  • Fig. 1 shows a flowchart of a method for dynamically modifying Nginx configuration parameters according to Embodiment 1 of the present application.
  • the method for dynamically modifying Nginx configuration parameters includes the following steps:
  • Nginx periodically obtains the http request (the request message from the client to the server) for the configuration file initiated by Tomcat, obtains the configuration file and extracts its version number, compares the version number with the version number of the configuration file in the shared memory, if If the version number of the configuration file is larger than the version number of the configuration file in the shared memory, the configuration file is parsed, and the parsed configuration file and its version number are updated to the shared memory.
  • the Nginx worker process periodically extracts the version number of the parsed configuration file from the shared memory, and compares the version number of the parsed configuration file with the version number of the configuration file inside the worker process.
  • the version number is larger than the version of the configuration file inside the working process, and the working process extracts the parsed configuration file and its version number in the shared memory to update the corresponding configuration information variable inside the working process.
  • the configuration file when the configuration parameters are changed, the configuration file is given an incremental version number.
  • the latest configuration file is parsed and placed into the shared memory, and each work process directly extracts the shared memory periodically.
  • the configuration file it is not necessary for the management process to recreate all the work processes based on the new configuration file after each configuration change as in the prior art, and then parse the configuration file.
  • step S110 the configuration parameters generated by the Web configuration interface are the configuration parameters that have changed on the Web configuration interface and the configuration parameters that have not changed.
  • the original configuration file in Tomcat is the configuration file generated during the last configuration.
  • Tomcat receives the changed configuration parameters of the Web configuration interface and the original unchanged configuration parameters, and generates a configuration file together; Tomcat will compare each generated configuration file with the original configuration file. If the configuration file is consistent, the version number will not be generated; if it is inconsistent with the original configuration file, a unique version number corresponding to the configuration file will be incrementally generated. This version number will replace the original configuration file and other configuration files in Tomcat together with the configuration file. The corresponding version number.
  • the configuration file that is inconsistent with the original configuration file is the new configuration file and the version number is stored in the database by Tomcat, so that the configuration content is not lost, and the configuration file consistent with the original configuration file is not stored in the database.
  • the types of configuration parameters include at least 3 types (1) Current limit settings for buckets (storage space).
  • the parameters corresponding to this type include download rate settings, file size settings, maximum connections, maximum concurrent settings, and token buckets. Size setting, etc.; (2) For the current limit setting of the IP address, the corresponding parameters of this type include download rate setting, maximum connection number setting, maximum concurrent number setting, token bucket size setting, etc.; (3) bucket cache setting , The parameters corresponding to this type include cache file size setting, cache expiration time setting, etc.
  • the web configuration interface for the bucket's current-limiting parameter settings is shown in Figure 4
  • the web configuration interface for the IP address's current-limiting parameter settings is shown in Figure 5
  • the Web configuration interface for the bucket's cache settings is shown in Figure 6.
  • the web configuration interface can be a visual Nginx parameter configuration interface, and each type of configuration parameter has a Chinese description.
  • the visual web configuration interface can be customized according to configuration requirements. Detailed parameter descriptions are provided on the interface.
  • the parameter range and format can be set. Nginx related parameters can also be set without professional Nginx operation and maintenance personnel.
  • Operation and maintenance personnel can select the type of configuration parameter according to the needs of the business, and change the parameter corresponding to the type according to the type of configuration parameter.
  • step S120 Nginx periodically initiates a configuration file acquisition http request to Tomcat, obtains the configuration file and extracts its version number.
  • a working process of Nginx initiates a configuration file acquisition http request to Tomcat Request. After Tomcat receives the http request, it sends the configuration file and its version number to the worker process, and the worker process extracts the version number.
  • the above period can be flexibly set according to specific business requirements, for example, the period setting time can be set to 10s.
  • the working process extracts the version number of the configuration file, it is compared with the version number of the configuration file already in the shared memory. If the version number of the configuration file is greater than the version number of the configuration file already in the shared memory, the configuration file will be parsed The later configuration file and its version number are updated to the shared memory, replacing the existing configuration file and its version number in the shared memory; if the version number of the configuration file is not larger than the version number of the existing configuration file in the shared memory, the configuration is not resolved File, the configuration file and its version number are not updated to the shared memory.
  • Nginx periodically initiates a configuration file acquisition http request to Tomcat, and compares the version number to determine whether the acquired configuration file is a new configuration file. If it is a new configuration file, it is analyzed and stored in shared memory. This prevents if the web configuration interface has not been modified for a long time, and Tomcat has not received new configuration parameters sent by the web configuration interface for multiple cycles, the configuration file obtained by Nginx is the same as the previous cycle, and redundant analysis work is performed without replacement. Configuration files in shared memory.
  • step S130 all work processes are independent of each other, each work process of Nginx has a cycle time for extracting the version number of the parsed configuration file from the shared memory, and each work process is set at a set cycle time. , The version number of the parsed configuration file will be extracted from the shared memory, and the version number of the parsed configuration file will be compared with the version number of the configuration file inside the working process.
  • the working process extracts the parsed configuration file and its version number in the shared memory to update the corresponding configuration information variables in the working process; if the version number of the parsed configuration file is no greater than the configuration file inside the working process If the version number is large, the work process does not extract the parsed configuration file in the shared memory, and continues to run with the original configuration information.
  • the set cycle time can be set to 5s, that is, every 5s there will be a work process to extract the configuration file from the shared memory.
  • the process of updating the corresponding configuration information variable in the working process may be: assigning the parsed configuration file in the shared memory extracted by the working process to the corresponding configuration information variable in the working process.
  • Each worker process periodically extracts the version number of the parsed configuration file from the shared memory, and judges whether the configuration file in the shared memory is a new configuration file by comparing the extracted version number with the version number inside the worker process , If it is a new configuration file, update the internal configuration file of the working process. In this way, if the configuration file in the shared memory is not updated for a long time, the work process will not extract the same configuration file as the previous cycle, preventing redundant configuration file replacement work.
  • one of the parameters "maximum number of connections (r)" for the current limiting type of the IP address in the web configuration interface is changed.
  • the changed parameter "maximum number of connections (r)” and the The changed parameters and other types of parameters that have not been changed are input into Tomcat together to form a configuration file.
  • the configuration file has changed from the original configuration file in Tomcat. Therefore, the configuration file is incremented to generate one corresponding to the configuration file.
  • the unique version number x+1 of the configuration file and its version number x+1 replace the original configuration file and its corresponding version number x in Tomcat, and store the configuration file and its version number x+1 in the database. Ensure that the configuration files in Tomcat are all the latest changes.
  • Nginx Every set cycle time 10s, a certain work process of Nginx will initiate a configuration file to obtain http request to Tomcat. After Tomcat receives the http request, it will send the configuration file and its version number x+1 to the work process, and work The process extracts the version number x+1. After the working process extracts the version number x+1 of the configuration file, compare it with the version number x of the configuration file already in the shared memory. The version number x+1 of the configuration file is greater than the version number x of the configuration file in the shared memory. , So the configuration file is parsed, and the parsed configuration file and its version number x+1 are updated to the shared memory, and the existing configuration file and its version number x in the shared memory are replaced;
  • a certain Nginx worker process initiates a configuration file acquisition http request to Tomcat again, and the configuration file in Tomcat is not updated during this period, then the configuration file and its version number x+1 are sent to the job again Process, the working process extracts the version number x+1. After the working process extracts the version number x+1 of the configuration file, compare it with the version number x+1 of the existing configuration file in the shared memory. The version number x+1 of the configuration file is equal to the version number of the existing configuration file in the shared memory.
  • Nginx has not obtained the new configuration file, so there is no need to parse the configuration file, and there is no need to update the configuration file and its version number x+1 to the shared memory. Ensure that Nginx parses the latest configuration file every time.
  • Each Nginx work process will extract the version number x+1 of the parsed configuration file from the shared memory every set cycle time 5s, compare the version number x+1 of the parsed configuration file than the internal work process If the configuration file version number x is large, the worker process extracts the parsed configuration file in the shared memory and its version number x+1 to replace the version number x of the configuration file inside the worker process, and assigns the configuration file x+1 to the worker process Corresponding internal configuration information variables.
  • the parsed configuration file in the shared memory is not updated, and the version number x+1 and the corresponding configuration file are still the version number extracted from the shared memory by the working process is still x+1, compare x+1 If it is equal to the version number x+1 of the configuration file in the working process, the configuration file and its version number x+1 in the working process do not need to be replaced. It is ensured that the configuration file replaced by the work process is the latest.
  • this application also provides a system for dynamically modifying Nginx configuration parameters, including:
  • Web configuration unit used to generate configuration parameters through the Web configuration interface
  • the Tomcat unit is used to obtain the configuration parameters generated by the Web configuration interface unit, generate a configuration file according to the configuration parameters, and compare the configuration file with the original configuration file in the Tomcat unit. If the configuration file is inconsistent with the original configuration file, configure The file replaces the original configuration file, and generates a unique version number for the configuration file, and associates the version number with the corresponding configuration file;
  • the database unit is used to store the version number and the corresponding configuration file
  • the Nginx unit is used for every set cycle time, a worker process of the Nginx unit initiates a configuration file acquisition http request to the Tomcat unit. After the worker process extracts the version number of the configuration file, it shares the existing configuration file version in the memory unit Number comparison, if the version number of the configuration file is larger than the version number of the existing configuration file in the shared memory unit, the configuration file will be parsed, and the parsed configuration file and its version number will be updated to the shared memory unit; the work processes are respectively periodic Extract the version number of the parsed configuration file from the shared memory unit, and compare the version number of the parsed configuration file with the version number of the configuration file inside the working process. If the version number of the parsed configuration file is greater than the configuration file inside the working process If the file version is large, the work process extracts the parsed configuration file and its version number in the shared memory to update the configuration information variables inside the work process;
  • the shared memory unit is used to store the latest parsed configuration file and its version number.
  • the configuration parameters generated by the Web configuration interface include the changed configuration parameters of the Web configuration interface and the original configuration parameters that have not changed.
  • the Web configuration interface is set according to the type of the configuration parameter.
  • each type of configuration parameter is equipped with a Chinese description.
  • the original configuration file in the Tomcat unit is the configuration file generated during the last configuration.
  • the Tomcat unit receives the changed configuration parameters of the Web configuration interface and the original unchanged configuration parameters, and jointly generates a configuration file.
  • the Tomcat unit compares the configuration file generated each time with the original configuration file. If it is consistent with the original configuration file, the version number is not generated; if it is inconsistent with the original configuration file, an incrementally generated one and the configuration file will be generated.
  • the unique version number corresponding to the file which will replace the original configuration file and its corresponding version number in the Tomcat unit together with the configuration file
  • the types of configuration parameters include:
  • the parameters corresponding to the first type include download rate settings, file size settings, maximum number of connections, maximum concurrent number settings, token bucket size settings, etc.;
  • the second type of current limit settings for IP addresses include download rate settings, maximum connections settings, maximum concurrent number settings, token bucket size settings, etc.;
  • the parameters corresponding to the third type include cache file size settings, cache invalidation time settings, and so on.
  • the web configuration interface can be a visual Nginx parameter configuration interface, and each type of configuration parameter has a Chinese description.
  • the visual web configuration interface can be customized according to configuration requirements. Detailed parameter descriptions are provided on the interface.
  • the parameter range and format can be set.
  • Nginx related parameters can also be set without professional Nginx operation and maintenance personnel. Operation and maintenance personnel can also select the type of configuration parameter according to the needs of the business, and change the parameter corresponding to the type according to the type of configuration parameter.
  • the original configuration file in the Tomcat unit is the configuration file generated during the last configuration.
  • the Tomcat unit compares the configuration file generated each time with the original configuration file. If it is consistent with the original configuration file, the version number is not generated. ; If it is inconsistent with the original configuration file, a unique version number corresponding to the configuration file is incrementally generated, and the version number is replaced with the configuration file to replace the original configuration file and its corresponding version number in Tomcat.
  • a work process of the Nginx unit initiates a configuration file acquisition http request to the Tomcat unit. After the Tomcat unit receives the http request, it sends the configuration file and its version number to the work process, so The working process extracts the version number.
  • the above period can be flexibly set according to specific business requirements, for example, the period setting time can be set to 10s.
  • the working process extracts the version number of the configuration file, it is compared with the version number of the configuration file already in the shared memory. If the version number of the configuration file is greater than the version number of the configuration file already in the shared memory If the configuration file is larger, the configuration file is parsed, and the parsed configuration file and its version number are updated to the shared memory, and the existing configuration file and its version number in the shared memory are replaced; if the version number of the configuration file is not greater than that of the shared memory If the version number of the configuration file already in the memory is large, the configuration file is not parsed, and the configuration file and its version number are not updated to the shared memory.
  • all work processes are independent of each other, and each work process has a cycle time for extracting the version number of the parsed configuration file from the shared memory, and each work process every set cycle Time, the version number of the parsed configuration file will be extracted from the shared memory, and the version number of the parsed configuration file will be compared with the version number of the configuration file inside the working process.
  • the working process extracts the parsed configuration file and its version number in the shared memory; if the version of the parsed configuration file is If the number is not greater than the version number of the configuration file in the working process, the working process does not extract the parsed configuration file in the shared memory, and continues to run with the original configuration information.
  • the set cycle time is 5s, that is, every 5s, a working process will extract the configuration file from the shared memory.
  • the Nginx unit assigns the parsed configuration file in the shared memory extracted by the work process to the corresponding configuration information variable inside the work process.
  • Each worker process periodically extracts the version number of the parsed configuration file from the shared memory, and judges whether the configuration file in the shared memory is a new configuration file by comparing the extracted version number with the version number inside the worker process , If it is a new configuration file, update the internal configuration file of the working process. In this way, if the configuration file in the shared memory is not updated for a long time, the work process will not extract the same configuration file as the previous cycle, preventing redundant configuration file replacement work.
  • An electronic device includes a memory and a processor, and a computer program is stored in the memory.
  • the computer program is executed by the processor, the method for dynamically modifying Nginx configuration parameters in Embodiment 1 is implemented.
  • the computer program includes a configuration file associated storage program, a shared memory update program, and a work process update program.
  • a configuration file associated storage program When these programs are executed by the processor, the operations that can be achieved are as follows:
  • the configuration file associated storage program When the configuration file associated storage program is executed by the processor, Tomcat generates a configuration file according to the configuration parameters generated by the Web configuration interface, and compares the configuration file with the original configuration file in Tomcat. If the configuration file is inconsistent with the original configuration file, the original configuration file is replaced with the configuration file, and a unique version number is generated for the configuration file, and the version number and the configuration file are combined.
  • the association is stored in the database;
  • Nginx When the shared memory update program is executed by the processor, Nginx periodically initiates a configuration file acquisition http request to the Tomcat, acquires the configuration file and extracts its version number, and compares the extracted version number with the shared memory The version number of the configuration file, if the extracted version number is larger than the version number of the configuration file in the shared memory, the configuration file is parsed, and the parsed configuration file and its version number are updated to the shared RAM;
  • the Nginx work process When the work process update program is executed by the processor, the Nginx work process periodically extracts the version number of the parsed configuration file from the shared memory, and compares the version number of the parsed configuration file The version number and the version number of the configuration file inside the work process. If the version number of the parsed configuration file is greater than the version number of the configuration file inside the work process, the work process extracts the analysis from the shared memory The following configuration file and its version number are used to update the corresponding configuration information variables in the working process.
  • a computer-readable storage medium includes a program for dynamically modifying Nginx configuration parameters.
  • the program for dynamically modifying Nginx configuration parameters is executed by a processor, the steps of the method for dynamically modifying Nginx configuration parameters in Embodiment 1 are implemented.
  • the program for dynamically modifying Nginx configuration parameters may include the above-mentioned configuration file associated storage program, shared memory update program, and work process update program.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Information Transfer Between Computers (AREA)
  • Stored Programmes (AREA)

Abstract

一种动态修改Nginx配置参数的方法,包括步骤:S110:Tomcat获取Web配置界面产生的配置参数,生成配置文件,若所述配置文件与Tomcat中原有的配置文件不一致,则替换原有的配置文件,并生成一个唯一的版本号;S120:Nginx周期性地向Tomcat发起的配置文件及其版本号获取请求,若配置文件的版本号比共享内存里的配置文件的版本号大,将解析后的配置文件和其版本号更新至共享内存;S130:Nginx的工作进程分别周期性地从共享内存提取解析后的配置文件的版本号,若解析后的配置文件的版本号比工作进程内部的配置文件版本号大,则更新工作进程内部配置信息。实现了nginx配置参数的动态修改,并无需重启工作进程。

Description

动态修改Nginx配置参数的方法、系统、装置及存储介质
本申请要求申请号为201911037110.4,申请日为2019年10月29日,发明创造名称为“动态修改Nginx配置参数的方法、装置及存储介质”的专利申请的优先权。
技术领域
本申请涉及服务器处理技术领域,更为具体地,涉及一种动态修改Nginx配置参数的方法、系统、装置及存储介质。
背景技术
Nginx(engine x)是一个轻量级开源Web服务器软件,作为当前非常流行的HTTP(超文本传输协议)和反向代理Web(World Wide Web,互联网)服务器,同时也是一个IMAP(Internet Mail Access Protocol,交互式邮件存取协议)、POP3(Post Office Protocol 3,邮局协议的第3个版本)、SMTP(Simple Mail Transfer Protocol,简单邮件传输协议)代理服务器,丰富灵活的参数配置机制保证了Nginx极其强大的模块可扩展性及功能。
Nginx是多进程架构,单台主机上的nginx进程有1个管理进程和多个相互独立的工作进程,一般工作进程个数等于cpu的核数,管理进程接受客户端请求,转交给工作进程处理,从而很好地利用cpu的计算能力。管理进程并不处理客户端网络请求,客户端网络请求是由工作进程来处理,只有其中一个工作进程有可能来处理这个请求,而管理进程负责管理这些工作进程,比如当一个工作进程退出(异常情况下),负责启动新的工作进程,又比如通知所有的工作进程平滑的退出等。
每次更改Nginx配置,都必须先手动修改Nginx配置文件,配置文件替换后,再重新加载配置文件,根据新的配置文件对Nginx进行配置,即管理进程在确定根据原有配置文件中的配置信息创建的原有工作进程业务服务结束时,然后根据新的配置文件中的配置信息,创建新的工作进程,启用新的 工作进程,并关闭原有工作进程。
尽管Nginx重新加载配置文件过程中大部分场景下管理进程没有停止,不会发生漏掉客户端请求的情况。但申请人意识到,还存在以下问题:1、每次更改配置后,管理进程都要基于新的配置文件重新创建工作进程,关闭原有工作进程,这个过程较为繁琐复杂、耗时,增加管理进程的工作量。2、编辑Nginx配置文件,需要熟悉Nginx的开发运维人员才能修改,需要具备一定的专业知识,且直接修改Nginx配置文件,容易带来语法、文字上的错误,造成配置文件不可用。
发明内容
鉴于上述问题,本申请的目的是提供一种动态修改Nginx配置参数的方法、系统、装置及存储介质。实现了Nginx配置参数的动态修改,并无需重启工作进程。
根据本申请的一个方面,提供了一种动态修改Nginx配置参数的方法,包括如下步骤:
S110:Tomcat根据Web配置界面产生的配置参数生成配置文件,并将所述配置文件与Tomcat中原有的配置文件进行对比,若所述配置文件与所述原有的配置文件不一致,则以所述配置文件替换所述原有的配置文件,并为所述配置文件生成一个唯一的版本号,将所述版本号和所述配置文件关联存入数据库;
S120:Nginx周期性地向所述Tomcat发起配置文件获取http请求,获取所述配置文件并提取其版本号,比较所提取的版本号与共享内存中的配置文件的版本号,若所提取的版本号比所述共享内存里的配置文件的版本号大,则解析所述配置文件,并将解析后的所述配置文件和其版本号更新至共享内存;
S130:所述Nginx的工作进程周期性地从所述共享内存提取所述解析后的配置文件的版本号,并比较所述解析后的配置文件的版本号与所述工作进程内部的配置文件版本号,若所述解析后的配置文件的版本号比所述工作进程内部的配置文件版本大,则工作进程提取所述共享内存中的所述解析后的配置文件及其版本号,以更新所述工作进程内部对应的配置信息变量。
根据本申请的另一方面,提供了一种动态修改Nginx配置参数的系统,包括:
Web配置界面单元,用于产生配置参数;
Tomcat单元,用于获取Web配置界面单元产生的配置参数,根据所述配置参数生成配置文件,并将所述配置文件与Tomcat单元中原有的配置文件进行对比,若所述配置文件与所述原有的配置文件不一致,则所述配置文件替换原有的配置文件,并为所述配置文件生成一个唯一的版本号,将所述版本号和对应的配置文件关联;
数据库单元,用于存储所述版本号和对应的配置文件;
Nginx单元,用于每隔设定的周期时间,所述Nginx单元的一个工作进程向所述Tomcat单元发起配置文件获取http请求,所述工作进程提取所述配置文件的版本号后,与共享内存单元中已有的配置文件版本号比较,若所述配置文件的版本号比共享内存单元中已有的配置文件版本号大,则解析所述配置文件,并将所述解析后的配置文件和其版本号更新至共享内存单元;工作进程分别周期性地从共享内存单元提取所述解析后的配置文件的版本号,并比较所述解析后的配置文件的版本号与所述工作进程内部的配置文件版本号,若所述解析后的配置文件的版本号比所述工作进程内部的配置文件版本大,则工作进程提取共享内存中的所述解析后的配置文件及其版本号,以更新工作进程内部的配置信息变量;
共享内存单元,用于存储最新的解析后的配置文件及其版本号。
本申请还提供了一种电子装置,包括存储器和处理器,所述存储器中存储有计算机程序,所述计算机程序被处理器执行时实现上述的动态修改Nginx配置参数的方法。
本申请还提供了一种计算机可读存储介质,所述计算机可读存储介质中包括动态修改Nginx配置参数程序,所述动态修改Nginx配置参数程序被处理器执行时,实现上述的动态修改Nginx配置参数方法的步骤。
利用上述根据本申请的动态修改Nginx配置参数的方法,将每个配置文件赋予一个版本号,共享内存中存放最新的配置文件和其版本号,各个工作进程周期性地主动获取共享内存中的最新配置文件的版本号,并通过比较版 本号大小,判断是否进行配置文件更新,若需要更新配置,将共享内存里的信息赋值给工作进程内部对应的配置信息变量。实现了Nginx配置参数的动态修改,实现了工作进程无需重新创建和重启,就能使新配置参数生效。整个过程高效、可靠性高,对客户端业务零影响,适用于访问量大且可靠性要求高的业务场景。
具有易于理解的配置界面、使参数配置更加简单化,参数内容正确性得到了保证,不会带来配置文件语法、内容上的错误;且配置参数保存到了数据库,配置内容尽管没有写入Nginx的配置文件,但内容同样不会丢失。
为了实现上述以及相关目的,本申请的一个或多个方面包括后面将详细说明并在权利要求中特别指出的特征。下面的说明以及附图详细说明了本申请的某些示例性方面。然而,这些方面指示的仅仅是可使用本申请的原理的各种方式中的一些方式。此外,本申请旨在包括所有这些方面以及它们的等同物。
附图说明
通过参考以下结合附图的说明及权利要求书的内容,并且随着对本申请的更全面理解,本申请的其它目的及结果将更加明白及易于理解。在附图中:
图1示出了根据本申请实施例1的动态修改Nginx配置参数的方法的流程图;
图2示出了根据本申请实施例2的动态修改Nginx配置参数的系统的逻辑结构示意图;
图3示出了根据本申请实施例3的电子装置的逻辑结构示意图;
图4示出了根据本申请实施例1的针对bucket的限流参数设置的Web配置界面;
图5示出了根据本申请实施例1的针对IP地址的限流参数设置的Web配置界面;
图6示出了根据本申请实施例1的针对bucket的缓存设置的Web配置界面。
在所有附图中相同的标号指示相似或相应的特征或功能。
具体实施方式
在下面的描述中,出于说明的目的,为了提供对一个或多个实施例的全面理解,阐述了许多具体细节。然而,很明显,也可以在没有这些具体细节的情况下实现这些实施例。在其它例子中,为了便于描述一个或多个实施例,公知的结构和设备以方框图的形式示出。
名词解释:Tomcat(Apache Tomcat)是基于java servlet(Java语言中在服务器上运行的小型应用程序)的web容器,Tomcat本身可作为一个单独的Web服务器使用,用于获取动态资源,属于轻量级应用服务器。本申请Tomcat为Web配置界面的后端服务进程,用于持久化接收Web配置界面的配置参数、接收和响应http请求(从客户端到服务器端的请求消息)。
Nginx进程具有mutex(互斥锁),即Nginx的每个工作进程在执行http请求之前都需要先获取互斥锁,以确保同一时刻就只会有一个工作进程发起http请求。如果某个工作进程获取到互斥锁,这个工作进程就发起http请求;获取不到互斥锁的工作进程就放弃执行发起http请求,这样,保证同一时刻就只会有一个工作进程发起http请求,以免发送请求阻塞。
以下将结合附图对本申请的具体实施例进行详细描述。
实施例1
图1示出了根据本申请实施例1的动态修改Nginx配置参数的方法的流程图。
如图1所示,本实施例提供的动态修改Nginx配置参数的方法,包括如下步骤:
S110:Tomcat获取Web配置界面产生的配置参数,根据配置参数生成配置文件,并将配置文件与Tomcat中原有的配置文件进行对比,若配置文件与原有的配置文件不一致,则配置文件替换原有的配置文件,并为配置文件生成一个唯一的版本号,将版本号和对应的配置文件关联存入数据库。
S120:Nginx周期性地向Tomcat发起的配置文件获取http请求(从客户端到服务器端的请求消息),获取配置文件并提取其版本号,比较版本号与共享内存中的配置文件的版本号,若配置文件的版本号比共享内存里的配置 文件的版本号大,则解析配置文件,并将解析后的配置文件和其版本号更新至共享内存。
S130:Nginx的工作进程分别周期性地从共享内存提取解析后的配置文件的版本号,并比较解析后的配置文件的版本号与工作进程内部的配置文件版本号,若解析后的配置文件的版本号比工作进程内部的配置文件版本大,则工作进程提取共享内存中的解析后的配置文件及其版本号,以更新工作进程内部对应的配置信息变量。
本申请中当配置参数改变后,赋予配置文件一个递增的版本号,通过比较配置文件的版本号,将最新的配置文件解析后放入共享内存,每个工作进程直接周期性的提取共享内存中的配置文件;不需像现有技术一样每次更改配置后,管理进程都要基于新的配置文件重新创建所有的工作进程,然后解析配置文件。
在步骤S110中,Web配置界面产生的配置参数为Web配置界面发生改变的配置参数和未发生改变的配置参数。Tomcat中原有的配置文件为上一次配置时生成的配置文件。
Tomcat接收Web配置界面发生改变的配置参数和原有的未发生变化的配置参数,共同生成一个配置文件;Tomcat会对每一次生成的配置文件与原有的配置文件进行对比,如果与原有的配置文件一致,则不生成版本号;如果与原有的配置文件不一致,则递增生成一个和该配置文件对应的唯一的版本号,该版本号会同配置文件一同替换Tomcat中原有的配置文件和其对应的版本号。
在Web配置界面新修改的配置参数与上次配置相同时,可判断新生成的配置文件与Tomcat中的原有配置文件一致,不用替换Tomcat中原有的配置文件,保证了Tomcat中的配置文件都是最新发生改变的,也不用赋予版本号,可以忽略本次配置参数,无需重新配置Nginx,防止nginx做多余的解析工作。
与原有的配置文件不一致的配置文件也就是新的配置文件连同版本号由Tomcat存入数据库,以使配置的内容不丢失,与原有的配置文件进一致的配置文件不存入数据库。
Web配置界面,根据配置参数的类型设置,每种类型的配置参数均采用中文说明。
配置参数的类型,至少包括3种(1)针对bucket(存储空间)的限流设置,此类型对应的参数有下载速率设置、文件大小设置、最大连接数设置、最大并发数设置、令牌桶大小设置等;(2)针对IP地址的限流设置,此类型对应的参数有下载速率设置、最大连接数设置、最大并发数设置、令牌桶大小设置等;(3)针对bucket的缓存设置,此类型对应的参数有缓存文件大小设置、缓存失效时间设置等。
针对bucket的限流参数设置的Web配置界面如图4所示,针对IP地址的限流参数设置的Web配置界面如图5所示,针对bucket的缓存设置的Web配置界面如图6所示。
为了便于运维人员操作,Web配置界面可以为可视化的Nginx参数配置界面,每种类型的配置参数均具有中文说明。可根据配置需求,定制可视化的Web配置界面,界面上提供详细的参数说明,可设定参数内容范围、格式等,无需专业的Nginx运维人员也可设置Nginx相关参数。
运维人员可以根据业务的需求选择配置参数的类型,根据配置参数的类型更改与该类型对应的参数。
在步骤S120中:Nginx周期性的向Tomcat发起配置文件获取http请求,获取配置文件并提取其版本号,过程中:每隔设定的周期时间,Nginx的一个工作进程向Tomcat发起配置文件获取http请求,Tomcat接收到http请求后,将配置文件和其版本号发送到工作进程,工作进程提取版本号。
上述周期可以根据具体的业务需求灵活设定,比如,可以将周期的设定时间设定为10s。
设置一个共享内存用于放置最新的解析后的配置文件及其版本号。
工作进程提取配置文件的版本号后,与共享内存中已有的配置文件版本号比较,若配置文件的版本号比共享内存中已有的配置文件版本号大,则解析配置文件,并将解析后的配置文件和其版本号更新至共享内存,替换共享内存中已有的配置文件和其版本号;若配置文件的版本号不比共享内存中已有的配置文件版本号大,则不解析配置文件,不将配置文件和其版本号更新至共享内存。
Nginx周期性向Tomcat发起配置文件获取http请求,通过比较版本号,来判断获取的配置文件是否是新的配置文件,如果是新的配置文件才进行解 析并存入共享内存。这样防止如果Web配置界面长时间没有被修改,Tomcat多个周期内没有接收Web配置界面发送的新的配置参数时,Nginx获取到的配置文件与上周期相同,做多余的解析工作,也不用替换共享内存中配置文件。
在步骤S130中:所有工作进程都是相互独立的,Nginx的每个工作进程都具有向共享内存提取解析后的配置文件的版本号的周期时间,每个工作进程分别每隔设定的周期时间,就会分别向共享内存提取解析后的配置文件的版本号,比较解析后的配置文件的版本号与工作进程内部的配置文件版本号,若解析后的配置文件的版本号比工作进程内部的配置文件版本大,则工作进程提取共享内存中的解析后的配置文件和其版本号,以更新工作进程内部对应的配置信息变量;若解析后的配置文件的版本号不比工作进程内部的配置文件版本号大,则工作进程不提取共享内存中的解析后的配置文件,以原有的配置信息继续运行。
设定的周期时间可以设定为5s,即每隔5s就会有工作进程向共享内存提取配置文件。
更新工作进程内部对应的配置信息变量的过程可为:将工作进程提取的共享内存中解析后配置文件赋值给工作进程内部对应的配置信息变量。
每个工作进程分别周期性的向共享内存提取解析后的配置文件的版本号,通过比较提取的版本号和工作进程内部的版本号大小,来判断共享内存中的配置文件是否是新的配置文件,如果是新的配置文件才进行工作进程内部配置文件更新。这样如果共享内存中的配置文件长时间内没有更新,工作进程不会提取到与上周期相同的配置文件,防止做多余的配置文件替换工作。
应用本申请的工作过程举例如下:
例如,Web配置界面的针对IP地址的限流类型的其中一个参数“最大连接数(r)”被更改,点击了确定键后,那么被更改的参数“最大连接数(r)”和未被更改的参数以及其他类型的未被更改的参数,共同输入Tomcat中,形成一个配置文件,该配置文件相对Tomcat中原有的配置文件有所改变,因此对该配置文件递增生成一个和该配置文件对应的唯一的版本号x+1,该配置文件和其版本号x+1替换Tomcat中原有的配置文件和其对应的版本号x,并将该配置文件和其版本号x+1存入数据库。保证了Tomcat中的配置文件都是最新发生改变的。
每隔设定的周期时间10s,Nginx的某一个工作进程就会向Tomcat发起配置文件获取http请求,Tomcat接收到http请求后,将该配置文件和其版本号x+1发送到工作进程,工作进程提取版本号x+1。工作进程提取该配置文件的版本号x+1后,与共享内存中已有的配置文件版本号x比较,该配置文件的版本号x+1比共享内存中已有的配置文件版本号x大,因此解析该配置文件,并将解析后的该配置文件和其版本号x+1更新至共享内存,替换共享内存中已有的配置文件和其版本号x;
如果又隔了若干周期,Nginx的某一个工作进程再次向Tomcat发起配置文件获取http请求,Tomcat内的配置文件在这期间没有更新,则将该配置文件和其版本号x+1又发送到工作进程,工作进程提取版本号x+1。工作进程提取该配置文件的版本号x+1后,与共享内存中已有的配置文件版本号x+1比较,该配置文件的版本号x+1等于共享内存中已有的配置文件版本号x+1,说明Nginx没有获取到新的配置文件,则不用解析该配置文件,不用将该配置文件和其版本号x+1更新至共享内存。保证了Nginx每次解析的都是最新的配置文件。
Nginx的每个工作进程每隔设定的周期时间5s,就会向共享内存提取解析后的配置文件的版本号x+1,比较解析后的配置文件的版本号x+1比工作进程内部的配置文件版本号x大,则工作进程提取共享内存中的解析后的配置文件及其版本号x+1来替换工作进程内部的配置文件的版本号x,将配置文件x+1赋值给工作进程内部对应的配置信息变量。
如果又隔了若干周期,共享内存内的解析后的配置文件没有更新,还是版本号x+1和对应的配置文件,工作进程向共享内存中提取的版本号还是x+1,比较x+1与工作进程内部的配置文件版本号x+1相等,则工作进程中的配置文件及其版本号x+1不用替换。保证了工作进程每次替换的配置文件都是最新的。
实施例2
与上述实施例1中的动态修改Nginx配置参数的方法相对应,本申请还提供一种动态修改Nginx配置参数的系统,包括:
Web配置单元,用于通过Web配置界面产生配置参数;
Tomcat单元,用于获取Web配置界面单元产生的配置参数,根据配置参 数生成配置文件,并将配置文件与Tomcat单元中原有的配置文件进行对比,若配置文件与原有的配置文件不一致,则配置文件替换原有的配置文件,并为配置文件生成一个唯一的版本号,将版本号和对应的配置文件关联;
数据库单元,用于存储版本号和对应的配置文件;
Nginx单元,用于每隔设定的周期时间,Nginx单元的一个工作进程向Tomcat单元发起配置文件获取http请求,工作进程提取配置文件的版本号后,与共享内存单元中已有的配置文件版本号比较,若配置文件的版本号比共享内存单元中已有的配置文件版本号大,则解析配置文件,并将解析后的配置文件和其版本号更新至共享内存单元;工作进程分别周期性地从共享内存单元提取解析后的配置文件的版本号,并比较解析后的配置文件的版本号与工作进程内部的配置文件版本号,若解析后的配置文件的版本号比工作进程内部的配置文件版本大,则工作进程提取共享内存中的解析后的配置文件及其版本号,以更新工作进程内部的配置信息变量;
共享内存单元,用于存储最新的解析后的配置文件及其版本号。
具体的,作为示例,在Web配置单元中,Web配置界面产生的配置参数包括Web配置界面发生改变的配置参数和原有的未发生改变的配置参数,Web配置界面为根据配置参数的类型设置的Web配置界面,每种类型的配置参数均配有中文说明。Tomcat单元中原有的配置文件为上一次配置时生成的配置文件。
Tomcat单元接收Web配置界面发生改变的配置参数和原有的未发生变化的配置参数,共同生成一个配置文件。Tomcat单元会对每一次生成的配置文件与原有的配置文件进行对比,如果与原有的配置文件一致,则不生成版本号;如果与原有的配置文件不一致,则递增生成一个和该配置文件对应的唯一的版本号,该版本号会同配置文件一同替换Tomcat单元中原有的配置文件和其对应的版本号
其中,配置参数的类型的包括:
针对存储空间的限流设置的第一类型,该第一类型对应的参数包括下载速率设置、文件大小设置、最大连接数设置、最大并发数设置、令牌桶大小设置等;
针对IP地址的限流设置的第二类型,该第二类型对应的参数包括下载速 率设置、最大连接数设置、最大并发数设置、令牌桶大小设置等;
针对bucket的缓存设置的第三类型,该第三类型对应的参数包括缓存文件大小设置、缓存失效时间设置等。
针对上述三种配置参数的类型设置的配置界面分别如图4、图5和图6所示。为了便于运维人员操作,Web配置界面可以为可视化的Nginx参数配置界面,每种类型的配置参数均具有中文说明。可根据配置需求,定制可视化的Web配置界面,界面上提供详细的参数说明,可设定参数内容范围、格式等,无需专业的Nginx运维人员也可设置Nginx相关参数。运维人员也可以根据业务的需求选择配置参数的类型,根据配置参数的类型更改与该类型对应的参数。
Tomcat单元中原有的配置文件为上一次配置时生成的配置文件,Tomcat单元会对每一次生成的配置文件与原有的配置文件进行对比,如果与原有的配置文件一致,则不生成版本号;如果与原有的配置文件不一致,则递增生成一个和该配置文件对应的唯一的版本号,将版本号会同配置文件一同替换Tomcat中原有的配置文件和其对应的版本号。
每隔设定的周期时间,Nginx单元的一个工作进程向Tomcat单元发起配置文件获取http请求,Tomcat单元接收到述http请求后,将所述配置文件和其版本号发送到所述工作进程,所述工作进程提取所述版本号。
上述周期可以根据具体的业务需求灵活设定,比如,可以将周期的设定时间设定为10s。
优选的,在Nginx单元中,工作进程提取所述配置文件的版本号后,与共享内存中已有的配置文件版本号比较,若配置文件的版本号比共享内存中已有的配置文件版本号大,则解析该配置文件,并将所述解析后的配置文件和其版本号更新至共享内存,替换共享内存中已有的配置文件和其版本号;若所述配置文件的版本号不比共享内存中已有的配置文件版本号大,则不解析所述配置文件,不将所述配置文件和其版本号更新至共享内存。
此外,在Nginx单元中,所有工作进程都是相互独立的,每个工作进程都具有向所述共享内存提取解析后的配置文件的版本号的周期时间,每个工作进程每隔设定的周期时间,就会分别向所述共享内存提取所述解析后的配置文件的版本号,比较所述解析后的配置文件的版本号与所述工作进程内部 的配置文件版本号,若所述解析后的配置文件的版本号比所述工作进程内部的配置文件版本大,则工作进程提取所述共享内存中的所述解析后的配置文件和其版本号;若所述解析后的配置文件的版本号不比所述工作进程内部的配置文件版本号大,则工作进程不提取所述共享内存中的所述解析后的配置文件,以原有的配置信息继续运行。
在本实施例的一个具体实施方式中,设定的周期时间为5s,即每隔5s就会有工作进程向共享内存提取配置文件。
并且,Nginx单元将所述工作进程提取的所述共享内存中所述解析后配置文件赋值给工作进程内部对应的配置信息变量。
每个工作进程分别周期性的向共享内存提取解析后的配置文件的版本号,通过比较提取的版本号和工作进程内部的版本号大小,来判断共享内存中的配置文件是否是新的配置文件,如果是新的配置文件才进行工作进程内部配置文件更新。这样如果共享内存中的配置文件长时间内没有更新,工作进程不会提取到与上周期相同的配置文件,防止做多余的配置文件替换工作。
应当明了,上述实施方式并非本实施例2的所有实施方式,本实施例2的具体实施方式与上述实施例1的动态修改Nginx配置参数的方法的具体实施方式大致相同,在此不再赘述。实施例3
一种电子装置,包括存储器和处理器,存储器中存储有计算机程序,计算机程序被处理器执行时实现上述实施例1中的动态修改Nginx配置参数的方法。
其中的计算机程序包括配置文件关联存储程序、共享内存更新程序以及工作进程更新程序。这些程序被处理器执行时,所能够实现的操作如下:
配置文件关联存储程序,该配置文件关联存储程序被处理器执行时,Tomcat根据Web配置界面产生的配置参数生成配置文件,并将所述配置文件与Tomcat中原有的配置文件进行对比,若所述配置文件与所述原有的配置文件不一致,则以所述配置文件替换所述原有的配置文件,并为所述配置文件生成一个唯一的版本号,将所述版本号和所述配置文件关联存入数据库;
共享内存更新程序,该共享内存更新程序被处理器执行时,Nginx周期性地向所述Tomcat发起配置文件获取http请求,获取配置文件并提取其版本号,比较所提取的版本号与共享内存中的配置文件的版本号,若所提取的版 本号比所述共享内存里的配置文件的版本号大,则解析所述配置文件,并将解析后的所述配置文件和其版本号更新至共享内存;
工作进程更新程序,该工作进程更新程序被处理器执行时,Nginx的工作进程周期性地从所述共享内存提取所述解析后的配置文件的版本号,并比较所述解析后的配置文件的版本号与所述工作进程内部的配置文件版本号,若所述解析后的配置文件的版本号比所述工作进程内部的配置文件版本大,则工作进程提取所述共享内存中的所述解析后的配置文件及其版本号,以更新所述工作进程内部对应的配置信息变量。
实施例4
一种计算机可读存储介质,计算机可读存储介质中包括动态修改Nginx配置参数程序,动态修改Nginx配置参数程序被处理器执行时,实现实施例1中的动态修改Nginx配置参数方法的步骤。该动态修改Nginx配置参数程序可以包括上述配置文件关联存储程序、共享内存更新程序以及工作进程更新程序。
如上参照附图以示例的方式描述根据本申请的动态修改Nginx配置参数方法及装置。但是,本领域技术人员应当理解,对于上述本申请所提出的动态修改Nginx配置参数方法及装置,还可以在不脱离本申请内容的基础上做出各种改进。因此,本申请的保护范围应当由所附的权利要求书的内容确定。

Claims (20)

  1. 一种动态修改Nginx配置参数的方法,其特征在于,包括如下步骤:
    S110:Tomcat根据Web配置界面产生的配置参数生成配置文件,并将所述配置文件与Tomcat中原有的配置文件进行对比,若所述配置文件与所述原有的配置文件不一致,则以所述配置文件替换所述原有的配置文件,并为所述配置文件生成一个唯一的版本号,将所述版本号和所述配置文件关联存入数据库;
    S120:Nginx周期性地向所述Tomcat发起配置文件获取http请求,获取所述配置文件并提取其版本号,比较所提取的版本号与共享内存中的配置文件的版本号,若所提取的版本号比所述共享内存里的配置文件的版本号大,则解析所述配置文件,并将解析后的所述配置文件和其版本号更新至共享内存;
    S130:所述Nginx的工作进程周期性地从所述共享内存提取所述解析后的配置文件的版本号,并比较所述解析后的配置文件的版本号与所述工作进程内部的配置文件版本号,若所述解析后的配置文件的版本号比所述工作进程内部的配置文件版本大,则工作进程提取所述共享内存中的所述解析后的配置文件及其版本号,以更新所述工作进程内部对应的配置信息变量。
  2. 如权利要求1所述的动态修改Nginx配置参数的方法,其特征在于,
    所述Web配置界面产生的配置参数包括所述Web配置界面发生改变的配置参数和原有的未发生改变的配置参数,所述Web配置界面为根据配置参数的类型设置的Web配置界面,每种类型的配置参数均配有中文说明;
    所述Tomcat接收所述Web配置界面发生改变的配置参数和原有的未发生变化的配置参数,共同生成一个配置文件。
  3. 如权利要求2所述的动态修改Nginx配置参数的方法,其特征在于,所述配置参数的类型的包括:
    针对存储空间的限流设置的第一类型,所述第一类型对应的参数包括下载速率设置、文件大小设置、最大连接数设置、最大并发数设置、令牌桶大小设置;
    针对IP地址的限流设置的第二类型,所述第二类型对应的参数包括下载 速率设置、最大连接数设置、最大并发数设置、令牌桶大小设置;
    针对bucket的缓存设置的第三类型,所述第三类型对应的参数包括缓存文件大小设置、缓存失效时间设置。
  4. 如权利要求3所述的动态修改Nginx配置参数的方法,其特征在于,所述Web配置界面为可视化的Nginx参数配置界面。
  5. 如权利要求1所述的动态修改Nginx配置参数的方法,其特征在于,在S110中,
    所述Tomcat中原有的配置文件为上一次配置时生成的配置文件,Tomcat会对每一次生成的配置文件与原有的配置文件进行对比,如果与原有的配置文件一致,则不生成版本号;如果与原有的配置文件不一致,则递增生成一个和该配置文件对应的唯一的版本号,将所述版本号会同配置文件一同替换Tomcat中原有的配置文件和其对应的版本号。
  6. 如权利要求1所述的动态修改Nginx配置参数的方法,其特征在于,在S120中,
    每隔设定的周期时间,所述Nginx的一个工作进程向所述Tomcat发起配置文件获取http请求,所述Tomcat接收到所述http请求后,将所述配置文件和其版本号发送到所述工作进程,所述工作进程提取所述版本号。
  7. 如权利要求6所述的动态修改Nginx配置参数的方法,其特征在于,在S120中,
    所述工作进程提取所述配置文件的版本号后,与所述共享内存中已有的配置文件版本号比较,若所述配置文件的版本号比所述共享内存中已有的配置文件版本号大,则解析所述配置文件,并将所述解析后的配置文件和其版本号更新至共享内存,替换共享内存中已有的配置文件和其版本号;若所述配置文件的版本号不比共享内存中已有的配置文件版本号大,则不解析所述配置文件,不将所述配置文件和其版本号更新至共享内存。
  8. 如权利要求1所述的动态修改Nginx配置参数的方法,其特征在于,在S130中,
    所有工作进程都是相互独立的,每个工作进程都具有向所述共享内存提取解析后的配置文件的版本号的周期时间,每个工作进程每隔设定的周期时间,就会分别向所述共享内存提取所述解析后的配置文件的版本号,比较所 述解析后的配置文件的版本号与所述工作进程内部的配置文件版本号,若所述解析后的配置文件的版本号比所述工作进程内部的配置文件版本大,则工作进程提取所述共享内存中的所述解析后的配置文件和其版本号;若所述解析后的配置文件的版本号不比所述工作进程内部的配置文件版本号大,则工作进程不提取所述共享内存中的所述解析后的配置文件,以原有的配置信息继续运行。
  9. 如权利要求1所述的动态修改Nginx配置参数的方法,其特征在于,所述S130中更新所述工作进程内部对应的配置信息变量的方法包括:将所述工作进程提取的所述共享内存中所述解析后配置文件赋值给工作进程内部对应的配置信息变量。
  10. 一种动态修改Nginx配置参数的系统,其特征在于,包括:
    Web配置单元,用于通过Web配置界面产生配置参数;
    Tomcat单元,用于获取Web配置界面单元产生的配置参数,根据所述配置参数生成配置文件,并将所述配置文件与所述Tomcat单元中原有的配置文件进行对比,若所述配置文件与所述原有的配置文件不一致,则所述配置文件替换原有的配置文件,并为所述配置文件生成一个唯一的版本号,将所述版本号和对应的配置文件关联;
    数据库单元,用于存储所述版本号和对应的配置文件;
    Nginx单元,用于每隔设定的周期时间,所述Nginx单元的一个工作进程向所述Tomcat单元发起配置文件获取http请求,所述工作进程提取所述配置文件的版本号后,与共享内存单元中已有的配置文件版本号比较,若所述配置文件的版本号比共享内存单元中已有的配置文件版本号大,则解析所述配置文件,并将所述解析后的配置文件和其版本号更新至共享内存单元;工作进程分别周期性地从共享内存单元提取所述解析后的配置文件的版本号,并比较所述解析后的配置文件的版本号与所述工作进程内部的配置文件版本号,若所述解析后的配置文件的版本号比所述工作进程内部的配置文件版本大,则工作进程提取共享内存中的所述解析后的配置文件及其版本号,以更新工作进程内部的配置信息变量;
    共享内存单元,用于存储最新的解析后的配置文件及其版本号。
  11. 如权利要求10所述的动态修改Nginx配置参数的系统,其特征在于, 在所述Web配置单元中,
    所述Web配置界面产生的配置参数包括所述Web配置界面发生改变的配置参数和原有的未发生改变的配置参数,所述Web配置界面为根据配置参数的类型设置的Web配置界面,每种类型的配置参数均配有中文说明;
    所述Tomcat单元接收所述Web配置界面发生改变的配置参数和原有的未发生变化的配置参数,共同生成一个配置文件。
  12. 如权利要求11所述的动态修改Nginx配置参数的系统,其特征在于,所述配置参数的类型的包括:
    针对存储空间的限流设置的第一类型,所述第一类型对应的参数包括下载速率设置、文件大小设置、最大连接数设置、最大并发数设置、令牌桶大小设置;
    针对IP地址的限流设置的第二类型,所述第二类型对应的参数包括下载速率设置、最大连接数设置、最大并发数设置、令牌桶大小设置;
    针对bucket的缓存设置的第三类型,所述第三类型对应的参数包括缓存文件大小设置、缓存失效时间设置。
  13. 如权利要求12所述的动态修改Nginx配置参数的方法,其特征在于,所述Web配置界面为可视化的Nginx参数配置界面。
  14. 如权利要求10所述的动态修改Nginx配置参数的系统,其特征在于,
    所述Tomcat单元中原有的配置文件为上一次配置时生成的配置文件,所述Tomcat单元会对每一次生成的配置文件与原有的配置文件进行对比,如果与原有的配置文件一致,则不生成版本号;如果与原有的配置文件不一致,则递增生成一个和该配置文件对应的唯一的版本号,将所述版本号会同配置文件一同替换Tomcat中原有的配置文件和其对应的版本号。
  15. 如权利要求10所述的动态修改Nginx配置参数的系统,其特征在于,每隔设定的周期时间,所述Nginx单元的一个工作进程向所述Tomcat单元发起配置文件获取http请求,所述Tomcat单元接收到所述http请求后,将所述配置文件和其版本号发送到所述工作进程,所述工作进程提取所述版本号。
  16. 如权利要求15所述的动态修改Nginx配置参数的系统,其特征在于,在所述Nginx单元中,
    所述工作进程提取所述配置文件的版本号后,与所述共享内存中已有的配置文件版本号比较,若所述配置文件的版本号比所述共享内存中已有的配置文件版本号大,则解析所述配置文件,并将所述解析后的配置文件和其版本号更新至共享内存,替换共享内存中已有的配置文件和其版本号;若所述配置文件的版本号不比共享内存中已有的配置文件版本号大,则不解析所述配置文件,不将所述配置文件和其版本号更新至共享内存。
  17. 如权利要求10所述的动态修改Nginx配置参数的方法,其特征在于,在所述Nginx单元中,
    所有工作进程都是相互独立的,每个工作进程都具有向所述共享内存提取解析后的配置文件的版本号的周期时间,每个工作进程每隔设定的周期时间,就会分别向所述共享内存提取所述解析后的配置文件的版本号,比较所述解析后的配置文件的版本号与所述工作进程内部的配置文件版本号,若所述解析后的配置文件的版本号比所述工作进程内部的配置文件版本大,则工作进程提取所述共享内存中的所述解析后的配置文件和其版本号;若所述解析后的配置文件的版本号不比所述工作进程内部的配置文件版本号大,则工作进程不提取所述共享内存中的所述解析后的配置文件,以原有的配置信息继续运行。
  18. 如权利要求10所述的动态修改Nginx配置参数的方法,其特征在于,所述Nginx单元将所述工作进程提取的所述共享内存中所述解析后配置文件赋值给工作进程内部对应的配置信息变量。
  19. 一种电子装置,其特征在于,包括存储器和处理器,所述存储器中存储有计算机程序,所述计算机程序被处理器执行时实现如权利要求1至9任意一项所述的动态修改Nginx配置参数的方法。
  20. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中包括动态修改Nginx配置参数程序,所述动态修改Nginx配置参数程序被处理器执行时,实现如权利要求1至9中任一项所述的动态修改Nginx配置参数方法的步骤。
PCT/CN2019/118290 2019-10-29 2019-11-14 动态修改Nginx配置参数的方法、系统、装置及存储介质 WO2021082081A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201911037110.4 2019-10-29
CN201911037110.4A CN111045721B (zh) 2019-10-29 2019-10-29 动态修改Nginx配置参数的方法、装置及存储介质

Publications (1)

Publication Number Publication Date
WO2021082081A1 true WO2021082081A1 (zh) 2021-05-06

Family

ID=70232598

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/118290 WO2021082081A1 (zh) 2019-10-29 2019-11-14 动态修改Nginx配置参数的方法、系统、装置及存储介质

Country Status (2)

Country Link
CN (1) CN111045721B (zh)
WO (1) WO2021082081A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113485766A (zh) * 2021-07-07 2021-10-08 上海中通吉网络技术有限公司 基于salt和nginx反向代理集群管理方法和系统

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112346761B (zh) * 2020-10-27 2024-05-17 长沙市到家悠享网络科技有限公司 前端资源上线方法、设备、系统及存储介质
CN112702195A (zh) * 2020-12-18 2021-04-23 深圳奥哲网络科技有限公司 网关配置方法、电子设备及计算机可读存储介质
CN112506585B (zh) * 2020-12-28 2023-07-25 浪潮云信息技术股份公司 一种基于Java动态改变Nginx配置的系统及方法
CN114866413A (zh) * 2021-01-18 2022-08-05 网宿科技股份有限公司 一种动态配置变量的方法及系统
CN114465882A (zh) * 2021-12-24 2022-05-10 天翼云科技有限公司 一种网关配置加载、获取方法、装置及计算机设备
CN114785686A (zh) * 2022-04-22 2022-07-22 北京金山云网络技术有限公司 配置更新方法、装置和电子设备

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7457846B2 (en) * 2001-10-05 2008-11-25 International Business Machines Corporation Storage area network methods and apparatus for communication and interfacing with multiple platforms
CN106599085A (zh) * 2016-11-25 2017-04-26 努比亚技术有限公司 web系统配置文件的自动刷新方法及装置
CN108829459A (zh) * 2018-05-31 2018-11-16 康键信息技术(深圳)有限公司 基于Nginx服务器的配置方法、装置、计算机设备和存储介质
CN109450708A (zh) * 2018-12-14 2019-03-08 北京明朝万达科技股份有限公司 一种Nginx动态配置方法及系统

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106547576A (zh) * 2015-09-16 2017-03-29 腾讯科技(深圳)有限公司 配置文件的获取方法及装置
CN107357571B (zh) * 2017-06-20 2020-06-30 珠海格力电器股份有限公司 设备组件程序的维护方法及系统
CN108712457B (zh) * 2018-04-03 2022-06-07 苏宁易购集团股份有限公司 基于Nginx反向代理的后端服务器动态负载调整方法及装置
CN109347675B (zh) * 2018-10-31 2022-04-08 新华三大数据技术有限公司 服务器配置方法、装置以及电子设备

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7457846B2 (en) * 2001-10-05 2008-11-25 International Business Machines Corporation Storage area network methods and apparatus for communication and interfacing with multiple platforms
CN106599085A (zh) * 2016-11-25 2017-04-26 努比亚技术有限公司 web系统配置文件的自动刷新方法及装置
CN108829459A (zh) * 2018-05-31 2018-11-16 康键信息技术(深圳)有限公司 基于Nginx服务器的配置方法、装置、计算机设备和存储介质
CN109450708A (zh) * 2018-12-14 2019-03-08 北京明朝万达科技股份有限公司 一种Nginx动态配置方法及系统

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113485766A (zh) * 2021-07-07 2021-10-08 上海中通吉网络技术有限公司 基于salt和nginx反向代理集群管理方法和系统

Also Published As

Publication number Publication date
CN111045721A (zh) 2020-04-21
CN111045721B (zh) 2023-08-18

Similar Documents

Publication Publication Date Title
WO2021082081A1 (zh) 动态修改Nginx配置参数的方法、系统、装置及存储介质
CN108958927B (zh) 容器应用的部署方法、装置、计算机设备和存储介质
US8099720B2 (en) Translating declarative models
WO2019184750A1 (zh) 深度学习作业调度方法、系统和相关设备
WO2019184164A1 (zh) 自动部署Kubernetes从节点的方法、装置、终端设备及可读存储介质
CN111277432A (zh) 配置信息更新方法、装置、电子设备及存储介质
CN112579289B (zh) 一种可智能调度的分布式解析引擎方法及装置
WO2023050706A1 (zh) 一种数据库多写方法、装置及相关设备
CN114553960A (zh) 一种数据缓存方法、装置、设备及存储介质
WO2015167538A2 (en) Migrating objects from a source service to a target service
CN116016702A (zh) 一种应用可观测数据采集处理方法、装置及介质
CN114448895A (zh) 一种应用访问方法、装置、设备及介质
CN112559143A (zh) 任务调度方法、系统及计算设备
CN112702195A (zh) 网关配置方法、电子设备及计算机可读存储介质
CN108521342B (zh) 一种集群的管理方法及装置
CN111198753A (zh) 任务调度方法和装置
CN113268254A (zh) 一种集群系统安装方法、装置、电子设备及存储介质
US11216352B2 (en) Method for automatically analyzing bottleneck in real time and an apparatus for performing the method
US7546313B1 (en) Method and framework for using XML files to modify network resource configurations
CN110968434B (zh) 一种管理机器的方法及相关装置
CN116032796A (zh) 连线状态检测方法及相关设备
CN115766717B (zh) 超融合分布式系统自动化部署方法、装置、设备及介质
CN113297158B (zh) 一种云安全产品管理方法、装置、设备及存储介质
CN114461352B (zh) 一种管理虚拟机集群的实施方法、计算机设备及存储介质
CN113312592B (zh) 软件许可证的调度方法、装置、设备及存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19951142

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19951142

Country of ref document: EP

Kind code of ref document: A1