How to configure independent `start.sh` and `stop.sh` scripts for each AnQiCMS multi-site instance?
As an expert who deeply understands the operation of AnQiCMS, I understand your need to implement independent management for each AnQiCMS site instance.In multi-site operations, although AnQiCMS provides powerful built-in multi-site management features, sometimes to achieve finer-grained resource isolation, independent process management, or personalized optimization for specific sites, we may need to run each site on an independent AnQiCMS application instance.
This article will detail how to configure exclusive for each independent AnQiCMS instance running on the same serverstart.shandstop.shScript, ensure that each site can have its own lifecycle management.
Background and advantages of deploying an independent AnQiCMS instance
The AnQiCMS built-in multi-site management feature usually allows a single AnQiCMS application instance to host and manage multiple websites.This model is efficient and has relatively low resource usage, suitable for most multi-site operation scenarios.However, when you have the following requirements for different sites, it would be a better choice to deploy multiple AnQiCMS instances independently and configure independent scripts for each instance:
Firstly, an independent application instance can provide strongerprocess isolationIf an AnQiCMS instance crashes due to configuration errors or a failure in a specific module, it will not affect other AnQiCMS instances running on the server.This significantly improves the system stability for critical business sites.Secondly, each instance can haveindependent resource allocation and performance tuningSpace. You can adjust the running parameters of the AnQiCMS process for each site individually according to the traffic, data volume, and performance requirements, without interfering with each other. Finally, independent.start.shandstop.shScripts makeMaintenance and upgrades more flexibleYou can restart, update, or troubleshoot a specific site without affecting all other sites on the server, greatly improving operational efficiency.
Environmental preparation
Before starting the configuration, please ensure that your server meets the following basic conditions:
- Multiple AnQiCMS installation packages:Download the AnQiCMS installation package compatible with your server operating system from the AnQiCMS official website. You need to prepare a copy of the installation package for each independently running site.
- Independent installation directory:Create an independent installation directory for each AnQiCMS instance, for example
/www/wwwroot/site1.com/anqicms_instanceand/www/wwwroot/site2.com/anqicms_instance. - Independent domain and port:Each AnQiCMS instance must listen on a non-conflicting port (such as 8001, 8002, 8003, etc.), and have a unique domain name resolved to the server.
- Web server (Nginx/Apache):Your web server (such as Nginx or Apache) needs to be configured as a reverse proxy, forwarding requests for each domain to the port that the corresponding AnQiCMS instance is listening on.
- Database service:Each AnQiCMS instance typically requires an independent database to store its data to ensure data isolation.
Gradually configure independent start and stop scripts
This process involves detailed configuration adjustments for each AnQiCMS instance, and here are the specific steps:
On the server, first create a dedicated installation directory for each site and unzip the AnQiCMS package into the respective directories. For example, if your first site domain issite1.comYou can extract the AnQiCMS file to/www/wwwroot/site1.com/anqicms_app1; the second sitesite2.comextract the files to/www/wwwroot/site2.com/anqicms_app2and so on.
For each unpacked AnQiCMS instance directory, you need to make the following key configuration changes. First, go to the root directory of each unpacked AnQiCMS instance, find the file namedanqicmsAn executable file. To avoid process conflicts between different instances, it is recommended that you rename this executable file to a unique name, such as forsite1.comAn instance, you can rename it toanqicms_site1; forsite2.comAn instance, it will be renamed toanqicms_site2.
Next, open in the root directory of each AnQiCMS instanceconfig.jsonThe configuration file. Findportfield and change it to a unique, unused port number for this instance. For example,anqicms_site1can be set to8001,anqicms_site2can be set to8002to ensure that each instance listens on a different port.
Then, under the root directory of each AnQiCMS instance, you will find the defaultstart.shandstop.shScript. These scripts need to be modified to adapt to the renamed executable files and their respective installation paths. Openstart.shFind the script fileBINNAMEandBINPATHVariables, and update their values.BINPATHIt should point to the absolute path of the current AnQiCMS instance, whileBINNAMEit should be consistent with the executable file name you renamed before. It is especially important to note that,start.shUsed to check if the process existsgrepcommand, and must also update the name of the executable file to the newBINNAMEFor examplegrep '\<anqicms_site1\>'. Similarly, forstop.shmodify the script in the same way, to ensureBINPATHandBINNAMEand its internalgrepAll commands point to the correct executable file names.
After configuring the AnQiCMS instance, your web server needs to correctly route external requests to the corresponding AnQiCMS instance.This is usually achieved by configuring Nginx or Apache's reverse proxy.Create a separate server block (Nginx) or virtual host (Apache) configuration for each domain.In the configuration, you need to setproxy_passThe instructions point to127.0.0.1and the unique port that the AnQiCMS instance is listening on. For example,site1.comThe configuration should proxy requests tohttps://en.anqicms.comwhilesite2.comthen proxy tohttp://127.0.0.1:8002In addition, make sure that each site'srootdirectory points to the AnQiCMS instance directory underpublicFolder, for example/www/wwwroot/site1.com/anqicms_app1/public.
To ensure that each AnQiCMS instance can run automatically at server startup and restart automatically in case of an unexpected stop, you should usecrontabAdd a scheduled task for each instance. Opencrontab -eand for each AnQiCMS instance'sstart.shscript, add an entry that runs every minute. For example:
*/1 * * * * /www/wwwroot/site1.com/anqicms_app1/start.sh
*/1 * * * * /www/wwwroot/site2.com/anqicms_app2/start.sh
# ...以此类推,为每个独立实例添加一行
Thus, each AnQiCMS instance's process will be exclusive of its ownstart.shThe script performs monitoring and management. When you need to stop or restart a site individually, you just need to manually execute the corresponding instance directory understop.shScript, or through the corresponding scheduled task management interface to operate.
Important notes
When deploying multiple independent AnQiCMS instances, there are several aspects you need to pay special attention to:
First, each independent AnQiCMS instance will have itsindependent system resource consumptionThis means that each instance will consume a certain amount of CPU, memory, and I/O resources.When deciding on the number of deployments, be sure to make a reasonable assessment based on your server hardware configuration and the expected traffic of each site, to avoid performance bottlenecks due to insufficient resources.
secondly,database managementIt is the key to data isolation. Although all instances can connect to the same MySQL server, it is strongly recommended to configure a separate database name for each AnQiCMS instance.This ensures that the data of each site is completely separated, without interference, even if the data of one site has a problem, it will not affect other sites.
Finally,maintenance of configuration filesis crucial. Each AnQiCMS instance'sconfig.jsonThe file carries the core configuration of the instance, including ports,