Multi-server picture management method and system

By preparing multiple single-server image domain names and full-server image domain names in a multi-server architecture, combined with the Redis subscription message mechanism, the problem of inconsistent image storage in a multi-server environment is solved, unified management and access of image resources is realized, and operation and maintenance costs and technical complexity are reduced.

CN119691207APending Publication Date: 2025-03-25FUJIAN TQ DIGITAL
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411771250.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

In a multi-server architecture, inconsistent image storage leads to access problems and additional resources are required to maintain file servers, increasing operation and maintenance costs and technical complexity.

Method used

By preparing multiple single-server image domain names and one full-server image domain name, combined with the Redis subscription message mechanism, ensure that images are stored and accessed consistently in a multi-server environment.

Benefits of technology

It realizes unified management of image resources in a multi-server environment, reduces storage capacity and operation and maintenance costs, ensures that users can always access the correct image resources, and improves user experience and system stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119691207A_ABST
    Figure CN119691207A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of server picture management, in particular to a multi-server picture management method and system, and the method comprises the steps: preparing a plurality of single-server picture domain names according to the number of website servers, and binding the plurality of single-server picture domain names to picture storage directories of different servers of a website, preparing a full-server picture domain name and binding the full-server picture domain name to all servers of the website; when a website uploads a single server picture, a website program reads a unique identifier of a current server, and after the picture is uploaded and stored successfully, a single server URL containing the picture is returned; when an administrator uploads a full-server picture on a website, returning a full-server URL (Uniform Resource Locator) containing the picture; when the server receives a redis subscription message, the picture address in the intranet is accessed, and the pictures are stored in the picture catalog of the server according to the same catalog and name, so that the cost can be reduced, and a picture access function in a multi-server architecture is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of multi-server image management, and in particular to a multi-server image management method and system. Background Art

[0002] In website systems, there is often a need for administrators to upload background images. However, in a multi-server architecture, if the image is directly stored on one of the servers, an obvious problem will occur: when the administrator uploads an image, the image is only stored on the server that handles the upload request at the time. In this way, when switching access between different servers, you may encounter a situation where the image is sometimes visible and sometimes invisible. To solve this problem, the industry's common practice is to use an independent file server or object storage service to uniformly manage all user-uploaded files. This method can indeed effectively solve the problem of file consistency and provide better scalability and reliability.

[0003] However, this also means that additional resources need to be invested to maintain a new server node, which increases the operation and maintenance costs and technical complexity of the project. For projects with limited budgets or those that are cost-sensitive, applying for such additional services may become an insurmountable obstacle. Summary of the invention

[0004] In order to overcome the problem of high operation and maintenance costs and high technical complexity caused by the need to use additional servers for image management in a multi-server architecture, the purpose of the present invention is to provide a multi-server image management method and system that can reduce costs and realize image access functions in a multi-server architecture.

[0005] The present invention is implemented by the following scheme:

[0006] A multi-server image management method, the method steps are as follows:

[0007] Step 1: Prepare multiple single-server image domain names according to the number of website servers, and bind the multiple single-server image domain names to the image storage directories of different website servers. Then prepare a full-server image domain name and bind it to all the website servers.

[0008] Step 2: When uploading a single-server image on the website, the website program reads the unique identifier of the current server. After the image is successfully uploaded and saved, the single-server URL containing the image will be returned. The single-server URL contains the unique identifier, and the single-server URL will be saved in the image field of the corresponding data record in the database;

[0009] Step 3: When uploading a full-server image on the website, after the current server successfully saves the uploaded image, it will return the full-server URL containing the image, then obtain the intranet IP and port of the current server, and publish a subscription message of the intranet image address to redis. The full-server URL will be saved in the image field of the corresponding data record in the database;

[0010] Step 4: When the server receives the subscription message from redis, it accesses the image address in the intranet and saves the image to the image directory of the server with the same directory and name;

[0011] Step 5: When a website user requests to view data containing images, the front-end page will first obtain the information of the image field from the data record and initiate a request to the address.

[0012] Furthermore, the format of the single-server URL includes a single-server image domain name, a unique identifier, and an image path.

[0013] Furthermore, the format of the full-server URL includes the full-server image domain name and the image path.

[0014] Furthermore, in step 5, if the request returns a status code of 200, indicating that the request is successful, the image is displayed normally; otherwise, if the request fails, a preset safety image or placeholder is displayed by default.

[0015] Furthermore, the information of the picture field includes an address corresponding to the current picture.

[0016] A multi-server image management system, the system comprising: a server binding module, a single-server image processing module, a full-server image processing module, an image saving module and an image viewing module;

[0017] The server binding module is used to prepare multiple single-server image domain names according to the number of website servers, and bind the multiple single-server image domain names to the image storage directories of different servers of the website, and then prepare a full-server image domain name to bind to all servers of the website;

[0018] The single-server image processing module is used for uploading a single-server image on the website. The website program reads the unique identifier of the current server. After the image is successfully uploaded and saved, the single-server URL containing the image will be returned. The single-server URL contains the unique identifier. The single-server URL will be saved in the image field of the corresponding data record in the database;

[0019] The full-server image processing module is used to upload a full-server image on the website. After the current server uploads the image and saves it successfully, it will return the full-server URL containing the image, then obtain the intranet IP and port of the current server, and publish a subscription message of the intranet image address to redis. The full-server URL will be saved in the image field of the corresponding data record in the database;

[0020] The picture saving module is used to access the picture address in the intranet when the server receives the subscription message from redis, and save the picture to the picture directory of the server with the same directory and name;

[0021] The picture viewing module is used for when a website user requests to view data containing pictures, the front-end page will first obtain the information of the picture field from the data record and initiate a request to the address.

[0022] Furthermore, the format of the single-server URL includes a single-server image domain name, a unique identifier, and an image path.

[0023] Furthermore, the format of the full-server URL includes the full-server image domain name and the image path.

[0024] Furthermore, in the picture viewing module, if the request returns a status code of 200, indicating that the request is successful, the picture will be displayed normally; otherwise, if the request fails, a preset safe picture or placeholder will be displayed by default.

[0025] Furthermore, the information of the picture field includes an address corresponding to the current picture.

[0026] The beneficial effects of the present invention are:

[0027] The present invention provides a multi-server image management method and system, which can ensure that even in a multi-server environment, image resources only need to be stored on any one server, which not only saves storage capacity but also reduces operation and maintenance costs. Users can also always access the correct image resources, thereby improving user experience and ensuring system stability. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1 is a flow chart of the method of the present invention;

[0029] Figure 2 It is a structural block diagram of the system of the present invention. DETAILED DESCRIPTION

[0030] The present invention will be further described below in conjunction with the accompanying drawings.

[0031] See also Figure 1 , a multi-server image management method, the method steps are as follows:

[0032] Step 1: Prepare multiple single-server image domain names according to the number of website servers, and bind the multiple single-server image domain names to the image storage directories of different website servers. Then prepare a full-server image domain name and bind it to all the website servers.

[0033] Step 2: When uploading a single-server image on the website, the website program reads the unique identifier of the current server. After the image is successfully uploaded and saved, the single-server URL containing the image will be returned. The single-server URL contains the unique identifier and will be saved in the image field of the corresponding data record in the database.

[0034] Step 3: When uploading a full-server image on the website, after the current server successfully saves the uploaded image, it will return the full-server URL containing the image, then obtain the intranet IP and port of the current server, and publish a subscription message of the intranet image address to redis. The full-server URL will be saved in the image field of the corresponding data record in the database;

[0035] Step 4: When the server receives the subscription message from redis, it accesses the image address in the intranet and saves the image to the image directory of the server with the same directory and name;

[0036] Step 5: When a website user requests to view data containing images, the front-end page will first obtain the information of the image field from the data record and initiate a request to the address.

[0037] The present invention will be further described below in conjunction with a specific embodiment:

[0038] A multi-server image management method, the method comprising the following steps:

[0039] Step 1. Prepare multiple single-server image domain names according to the number of website servers, and bind multiple single-server image domain names to the image storage directories of different servers of the website. These domain names are in the form of "image-flag1.xxx.com", "image-flag2.xxx.com",..., "image-flagn.xxx.com". Then prepare a full-server image domain name and bind it to all servers of the website, such as "image.xxx.com".

[0040] In order to ensure the consistency of image access in a multi-server environment, prepare multiple subdomains dedicated to image services according to the number of website servers. For example, if the current website program is deployed on two servers, then both servers may become the source of user access to image resources. Therefore, it is necessary to prepare two dedicated single-server image domain names, such as "image-flag1.xxx.com" and "image-flag2.xxx.com". These two domain names will be bound to the image directory / data / image on their respective servers through Nginx, thereby ensuring that each single-server domain name only points to its corresponding server image storage location.

[0041] In addition, you should prepare a globally available image domain name, such as "image.xxx.com", and configure load balancing through Nginx so that it can randomly point to the image directory / data / image of any of the two servers. In this way, no matter when the user requests image resources, they can get a consistent access experience through the global image domain name, while reducing the pressure on the single-point server.

[0042] Step 2: When the administrator uploads a single-server image on the website, the website program will read the unique identifier (flag) of the current server. After the image is uploaded and saved successfully, the system will return the single-server URL containing the image in the format of "image-{flag}.xxx.com / {image path}". This image domain name with a specific server identifier will be saved in the image field of the corresponding data record in the database.

[0043] When an administrator uploads an avatar for a user on any website program server, the website program will first read the unique identifier of the current server (for example, "flag2"). Next, the system will randomly generate an image file name (such as "gs8e32m.jpg") and save the image to the image directory / data / image of the current server. After the upload is successful, the system will generate an image access address containing the current server identifier (for example, "https: / / image-flag2.xxx.com / gs8e32m.jpg"). This image domain name with a specific server identifier will be recorded and saved in the corresponding user avatar field of the user table in the database. In this way, each uploaded avatar will be correctly associated with a specific server, and the correct image storage location can be quickly located when the user accesses it.

[0044] The benefit of step 2 is that it can be used for projects with limited budgets or that are cost-sensitive. A single server image address can save image resources.

[0045] Step 3: When the administrator uploads a full-server image on the website, after the current server successfully saves the uploaded image, the system will return the full-server URL containing the image in the format of "image.xxx.com / {image path}". Then obtain the intranet IP and port of the current server, publish a subscription message of the intranet image address to redis, and the full-server URL will be saved in the image field of the corresponding data record in the database.

[0046] When the administrator uploads a product image on the website, it is necessary to ensure that the image can be accessed on all servers. Assume that the current administrator's operation of uploading an image hits the server identified as flag1. At this time, after successfully saving the image on the flag1 server, the system will return a full-server image address (for example: "https: / / image.xxx.com / sk7h3k2.jpg"). Next, the system will obtain the intranet IP address of the current server (for example: 172.168.3.1) and the port where the current program is running (for example: 8010). Subsequently, the system will publish a message composed of the current intranet IP address and the image path (for example: 172.168.3.2:8010 / sk7h3k2.jpg) to Redis so that other servers can synchronize the image data by subscribing to the message. In this way, it can be ensured that the uploaded product images can be consistently synchronized to all servers in a multi-server environment, thereby ensuring the availability and consistency of the images.

[0047] Step 4: When the server receives the subscription message from redis, it accesses the intranet image address and saves the image to the server's image directory with the same directory and name.

[0048] When the flag1 server receives the subscription message from Redis, it obtains the intranet image address of the flag2 server from the message (for example: 172.168.3.2:8010 / sk7h3k2.jpg). Then, the flag1 server will access the address to obtain the image on the flag2 server and save it to its own image directory with the same directory and name. If any failure occurs during the saving process, the flag1 server will rewrite the message back to the Redis subscription message queue for subsequent retries. This ensures that even if the initial attempt fails, the image can still be successfully synchronized to all servers, thereby ensuring the consistency and availability of the image.

[0049] Step 5: When a website user requests to view data containing images, the front-end page will first obtain the information of the image field from the data record and initiate a request to the address. If the request returns a status code of 200 (indicating a successful request), the image will be displayed normally; otherwise, if the request fails, the default safe image or placeholder will be displayed.

[0050] When a website user queries his current user avatar, for example, the user avatar address obtained from the database is the single-server image address https: / / image-flag2.xxx.com / gs8e32m.jpg, the front end will first initiate a request to this address. If the request returns a status code of 200, it indicates that the request is successful and the front end will display the image normally. On the contrary, if the request returns a status code other than 200, it indicates that the image may have an unknown abnormality, and the front end will display the preset default image. In this way, it can ensure that a user-friendly experience is still provided when the image request fails, avoiding display problems caused by missing images.

[0051] See also Figure 2 , a multi-server image management system, the system comprising: a server binding module, a single-server image processing module, a full-server image processing module, an image saving module and an image viewing module;

[0052] The server binding module is used to prepare multiple single-server image domain names according to the number of website servers, and bind the multiple single-server image domain names to the image storage directories of different servers of the website, and then prepare a full-server image domain name to bind to all servers of the website;

[0053] The single-server image processing module is used for uploading a single-server image on the website. The website program reads the unique identifier of the current server. After the image is successfully uploaded and saved, the single-server URL containing the image will be returned. The single-server URL contains the unique identifier. The single-server URL will be saved in the image field of the corresponding data record in the database;

[0054] The full-server image processing module is used to upload a full-server image on the website. After the current server uploads the image and saves it successfully, it will return the full-server URL containing the image, then obtain the intranet IP and port of the current server, and publish a subscription message of the intranet image address to redis. The full-server URL will be saved in the image field of the corresponding data record in the database;

[0055] The picture saving module is used to access the picture address in the intranet when the server receives the subscription message from redis, and save the picture to the picture directory of the server with the same directory and name;

[0056] The picture viewing module is used for when a website user requests to view data containing pictures, the front-end page will first obtain the information of the picture field from the data record and initiate a request to the address.

[0057] In one embodiment of the present invention, the format of the single-server URL includes a single-server image domain name, a unique identifier, and an image path.

[0058] In one embodiment of the present invention, the format of the full-server URL includes a full-server image domain name and an image path.

[0059] In one embodiment of the present invention, if the request returns a status code of 200 in the picture viewing module, indicating that the request is successful, the picture is displayed normally; otherwise, if the request fails, a preset safety picture or placeholder is displayed by default.

[0060] In one embodiment of the present invention, the information of the picture field includes an address corresponding to the current picture.

[0061] The above description is only a preferred embodiment of the present invention. All equivalent changes and modifications made according to the scope of the patent application of the present invention should fall within the scope of the present invention.

Claims

1. A multi-server image management method, characterized in that: The method steps are as follows: Step 1: Prepare multiple single-server image domain names according to the number of website servers, and bind the multiple single-server image domain names to the image storage directories of different website servers. Then prepare a full-server image domain name and bind it to all the website servers. Step 2: When uploading a single-server image on the website, the website program reads the unique identifier of the current server. After the image is successfully uploaded and saved, the single-server URL containing the image will be returned. The single-server URL contains the unique identifier, and the single-server URL will be saved in the image field of the corresponding data record in the database; Step 3: When uploading a full-server image on the website, after the current server successfully saves the uploaded image, it will return the full-server URL containing the image, then obtain the intranet IP and port of the current server, and publish a subscription message of the intranet image address to redis. The full-server URL will be saved in the image field of the corresponding data record in the database; Step 4: When the server receives the subscription message from redis, it accesses the image address in the intranet and saves the image to the image directory of the server with the same directory and name; Step 5: When a website user requests to view data containing images, the front-end page will first obtain the information of the image field from the data record and initiate a request to the address.

2. A multi-server image management method according to claim 1, characterized in that: The format of the single-server URL includes a single-server image domain name, a unique identifier, and an image path.

3. A multi-server image management method according to claim 1, characterized in that: The format of the full-server URL includes the full-server image domain name and the image path.

4. A multi-server image management method according to claim 1, characterized in that: In step 5, if the request returns a status code of 200, indicating that the request is successful, the image is displayed normally; otherwise, if the request fails, the default security image or placeholder is displayed.

5. A multi-server image management method according to claim 1, characterized in that: The information of the picture field includes the address corresponding to the current picture.

6. A multi-server image management system, characterized in that: The system includes: a server binding module, a single-server image processing module, a full-server image processing module, an image saving module and an image viewing module; The server binding module is used to prepare multiple single-server image domain names according to the number of website servers, and bind the multiple single-server image domain names to the image storage directories of different servers of the website, and then prepare a full-server image domain name to bind to all servers of the website; The single-server image processing module is used for uploading a single-server image on the website. The website program reads the unique identifier of the current server. After the image is successfully uploaded and saved, the single-server URL containing the image will be returned. The single-server URL contains the unique identifier. The single-server URL will be saved in the image field of the corresponding data record in the database; The full-server image processing module is used to upload a full-server image on the website. After the current server uploads the image and saves it successfully, it will return the full-server URL containing the image, then obtain the intranet IP and port of the current server, and publish a subscription message of the intranet image address to redis. The full-server URL will be saved in the image field of the corresponding data record in the database; The image saving module is used to access the image address in the intranet when the server receives a subscription message from redis. Save the image to the image directory of the server with the same directory and name; The picture viewing module is used for when a website user requests to view data containing pictures, the front-end page will first obtain the information of the picture field from the data record and initiate a request to the address.

7. A multi-server image management system according to claim 6, characterized in that: The format of the single-server URL includes a single-server image domain name, a unique identifier, and an image path.

8. A multi-server image management system according to claim 6, characterized in that: The format of the full-server URL includes the full-server image domain name and the image path.

9. A multi-server image management system according to claim 6, characterized in that: In the picture viewing module, if the request returns a status code of 200, indicating that the request is successful, the picture will be displayed normally; otherwise, if the request fails, the preset safe picture or placeholder will be displayed by default.

10. A multi-server image management method according to claim 6, characterized in that: The information of the picture field includes the address corresponding to the current picture.