AnQiCMS provides powerful support for enterprise content management with its efficient and flexible architecture.Especially when dealing with multi-site requirements, AnQiCMS provides various deployment solutions, one of which is to run multiple independent AnQiCMS instances on the same server to manage different websites.crontabEnsuring stable startup and continuous operation of these different instances through scheduled tasks has become a critical element that website operators need to deeply understand.
This article will delve into this topic, providing a detailed explanation of AnQiCMS multi-instance deployment undercrontabmanagement strategy, aiming to help you build a robust and highly available multi-site environment.
Understanding the multi-site deployment mode of AnQiCMS
In AnQiCMS, there are usually two main ways of multi-site deployment. One isAnQiCMS instance manages multiple websitesYou can configure multiple domains in an AnQiCMS backend and direct different domains to the same AnQiCMS service port (e.g., 8001) through reverse proxy. The system internally resolves to different website content based on the domain. In this mode, there is only one AnQiCMS process running, socrontabOnly pay attention to the startup and maintenance of this process.
However, what we are focusing on today is another deployment method with more isolation:Run multiple independent AnQiCMS instances on a single server..This means that each AnQiCMS instance is an independent Go language executable file along with its配套的数据和配置, and they each listen on different ports while managing one or more websites.crontabThe place where it plays a role.
Of a single AnQiCMS instance.crontabThe startup mechanism.
AnQiCMS provides a concise and efficientstart.shThe script to manage the startup of a single instance.The core logic of this script is to check if the AnQiCMS process is already running, and if not, start it.This is usually achieved by checking the specific executable filename in the process list.
a typicalstart.shThe script content may be as follows:
#!/bin/bash
### check and start AnqiCMS
# author fesion
# the bin name is anqicms
BINNAME=anqicms
BINPATH=/www/wwwroot/anqicms_site1 # 假设这是实例1的路径
# check the pid if exists
exists=`ps -ef | grep '\<anqicms\>' |grep -v grep |wc -l`
echo "$(date +'%Y%m%d %H:%M:%S') $BINNAME PID check: $exists" >> $BINPATH/check.log
echo "PID $BINNAME check: $exists"
if [ $exists -eq 0 ]; then
echo "$BINNAME NOT running"
cd $BINPATH && nohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &
fi
To make this script run automatically in the system background and regularly check the AnQiCMS process, we will configure it tocrontab. For example, set it to run every minute to ensure process stability:
# 编辑 crontab
crontab -e
# 在打开的编辑器中添加一行,指向您的 start.sh 脚本路径
*/1 * * * * /www/wwwroot/anqicms_site1/start.sh
Here/www/wwwroot/anqicms_site1is the deployment directory of your first AnQiCMS instance.
Manage extension to multiple AnQiCMS instances
When you need to run multiple independent AnQiCMS instances on the same server, the core principle of management strategy isProvide a set of independent, distinguishable startup and monitoring mechanisms for each instance. The design of AnQiCMS allows you to achieve this by copying its program code.
Copy instance code and configurationFirstly, you need to create a complete code copy for each independent AnQiCMS instance. For example, if you have
anqicms_site1instance, now you need to addanqicms_site2Then you should create a similar directory on the server./www/wwwroot/anqicms_site2And copy all files of AnQiCMS (including executable files,)config.jsonetc.) to this new directory.Configure an independent portEach AnQiCMS instance must listen to a unique port. Find it in the root directory of each instance,
config.jsonfile and modify the followingportFields have different values. For example,anqicms_site1Use8001,anqicms_site2then it can be modified to8002,anqicms_site3Use8003and so on.Rename the executable file (recommended practice)for convenience
crontabScript and system monitoring can clearly distinguish between different AnQiCMS processes, it is strongly recommended that you rename the AnQiCMS executable files under each instance directory. For example,/www/wwwroot/anqicms_site1/anqicmsRename toanqicms_site1_bin,/www/wwwroot/anqicms_site2/anqicmsRename toanqicms_site2_binThis way, when you executeps -ef | grep anqicmsthe command, you can clearly see the process information of each instance, and avoidgrepincorrectly matching other related processes.Create an independent one for each instance
start.shscriptCreate customized ones for each AnQiCMS instance based on the renamed executable file and their respective installation pathsstart.shScripts. These scripts have logic similar to that of a single instance,BINNAMEandBINPATHvariables will point to the unique information of each instance.For example,
anqicms_site2ofstart.shscript