As a professional who has been deeply engaged in website operations and has extensively applied AnQiCMS (AnQiCMS), I fully understand the importance of efficiently managing multiple content platforms in an increasingly complex network environment.How to effectively manage the process identifier (PID) of each instance when the business develops to the point where it needs to operate multiple independent sites simultaneously, or to deploy multiple AnQiCMS instances for performance, isolation, and other needs, has become a key factor in ensuring the stable operation and maintenance efficiency of the system.

AnQi CMS, with its high concurrency features of Go language and simple architecture, makes deployment and operation relatively lightweight and efficient.However, unlike the PHP applications in the traditional LAMP/LNMP stack that depend on the web server process, AnQiCMS is an independent Go application that listens on a port and handles requests by itself.This means that each independent AnQiCMS instance will run as a separate Go process on the server, with its own unique PID.anqicmsWhen a process is running, it becomes very difficult to identify and operate on a specific instance just by its default process name.

Understanding the scenarios and challenges of multi-instance deployment.

Before delving into PID management, we need to differentiate between two common multi-site operation models.One is to use the built-in "Multi-site Management" feature of AnQiCMS, which allows you to manage multiple domain sites within a single AnQiCMS application (i.e., a Go process).In this mode, all sites share the same AnQiCMS process, the same port, and distinguish content through domain mapping and site root directory configured in the background.For such a scenario, you do not need to worry about managing the PIDs of multiple AnQiCMS processes, as there is only one main process.

Another situation, which is the focus of our discussion in this article, is deploymentMultiple independent AnQiCMS application instancesThis is usually due to the following considerations:

  • Resource isolation:Each instance can be independently configured with resource limits to avoid one site's high load affecting other sites.
  • Data isolation: Each instance has its own database and file storage, ensuring data security and non-interference.
  • Version control: Different instances can run different versions of AnQiCMS, convenient for testing or gradual upgrades.
  • Team collaboration:Different operation teams can independently manage their own AnQiCMS instances without affecting each other.

In this mode, each AnQiCMS instance will be an independent process on the server, and they may be referred to as by defaultanqicms. If not distinguished, when you try to stop, restart, or monitor a specific instance, you may mistakenly operate on other instances, leading to unnecessary downtime or confusion.

Core strategy: Differentiate processes through unique naming

The key to solving this challenge lies in assigning a unique name to each AnQiCMS instance'sAssign a unique name to the executable fileAdjust the start and stop scripts accordingly.

Firstly, prepare a complete AnQiCMS package for each AnQiCMS instance that needs to run independently. You can place it in different directories on the server (such as/www/wwwroot/site1_anqicms/and/www/wwwroot/site2_anqicms/Place these packages.

Next, perform the following critical steps for each instance:

Configure independent runtime ports

Each AnQiCMS instance needs to listen on a dedicated port. Enter the program directory of each instance, findconfig.jsonthe file. Edit this file, and setportField modified to a different port number. For example, the first instance uses8001, the second uses8002This step is the foundation, ensuring that each instance can start independently without port conflicts.

Assign a unique name to the AnQiCMS executable file.

This is the core of PID management. In each independent AnQiCMS package directory, the defaultanqicmsRename the executable file to a name with high recognition. For example, if an instance is used for a blog, you can rename its executable file toanqicms_blogIf another one is used for e-commerce, rename it toanqicms_shop. After renaming, each running instance will have a unique name in the system process list, which is the premise for subsequent precise process management.

Adjust the start and stop scripts

AnQiCMS providedstart.shandstop.shscripts to assist in process management. You need to create a set of corresponding scripts for each renamed AnQiCMS instance and modify theBINNAMEvariables andgrepCommand, to point to the unique executable file name you have just assigned.

Start withstart.shFor example, assume you have renamed the executable file toanqicms_blogand the program path is/www/wwwroot/blog_anqicms:

#!/bin/bash
BINNAME=anqicms_blog # 修改为新的可执行文件名
BINPATH=/www/wwwroot/blog_anqicms # 修改为该实例的实际路径

exists=`ps -ef | grep '\<'$BINNAME'\>' |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

the correspondingstop.shThe script also needs to be modified similarly:

#!/bin/bash
BINNAME=anqicms_blog # 修改为新的可执行文件名
BINPATH="$( cd "$( dirname "$0"  )" && pwd  )" # 此处可以保持不变,或根据实际情况调整

exists=`ps -ef | grep '\<'$BINNAME'\>' |grep -v grep |awk '{printf $2}'`
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"
else
    echo "$BINNAME is running"
    kill -9 $exists
    echo "$BINNAME is stop"
fi

You also need to configure each instance in the task scheduler (such ascrontab) or service manager (such assystemdConfigure the corresponding start/stop tasks within it, ensuring they can run and manage independently and stably.

Configure reverse proxy to map domain names.

Finally, each independent AnQiCMS instance needs to be reverse proxied through a web server (such as Nginx or Apache) to listen on its private port (such as8001/8002Mapped to a publicly accessible domain (such asblog.example.com/shop.example.com). When users visit the domain, the request will be forwarded to the corresponding AnQiCMS instance by the web server.

Operations practice and process monitoring

After completing the above configuration, you will be able to monitor and manage each AnQiCMS instance more clearly.

Useps -efCommand cooperationgrepYou can easily find the PID of a specific instance:

ps -ef | grep anqicms_blog

This will only display withanqicms_bloginformation related to processes, where the second column is the PID of the process.

You can also uselsof -i:{端口号}Command to verify whether a specific port is occupied by the correct AnQiCMS instance:

lsof -i:8001

This will display the occupancy8001Process information of the port, to confirm whether it is youranqicms_bloginstance.

It is strongly recommended to use for production environmentssystemdProfessional service managers to manage these AnQiCMS instances. By creating an independent.serviceA file, you can define the startup command, environment variables, restart policy, log output, and so on for each instance to realize more robust and automated process management.

Summary

By assigning a unique name to each independent AnQiCMS executable file and coordinating with the corresponding startup script and reverse proxy configuration, we can effectively manage the PIDs of multiple AnQiCMS instances on the same server.This strategy not only brings clear process isolation and convenient independent management, but also lays a solid foundation for the scalability and stability of website operations.As a website operator, mastering these refined management skills will undoubtedly greatly improve our work efficiency and ability to deal with complex scenarios.


Frequently Asked Questions

**An