As an experienced CMS operation personnel in security, I am well aware that ensuring the stable operation of the content management system is crucial in complex server environments.For many users who do not use the Baota panel, manually configuring the process guard for AnQiCMS may seem like a challenge, but with the correct method, it can achieve enterprise-level high reliability.This article will detail how to reliably guard the AnQiCMS process without the environment of Baota Panel.

Understanding the importance of the AnQiCMS process guardian

AnQiCMS is an high-performance content management system developed based on the Go language.Different from traditional CMS that depends on external services such as PHP-FPM, AnQiCMS is compiled into an independent executable binary file. It is itself a web server and usually listens on a specific port (such as the default 8001).This means it does not rely on a web server to start and manage processes like a PHP application.However, a binary program running independently also needs a mechanism to ensure its continuous online status.Once the program crashes or stops for any reason (such as code errors, system resource exhaustion, server restarts, etc.) and if there is no daemon, the website will not be accessible.Therefore, configuring a reliable process guardian for AnQiCMS is a key link to ensure the high availability and stability of the website.

Preparation and initial deployment of AnQiCMS

Before configuring the process guardian, you need to complete the basic deployment of AnQiCMS. First, download the latest installation package suitable for the Linux environment from the AnQiCMS official website, upload it to your server, and unzip it to a suitable directory, such as/opt/anqicmsor/www/wwwroot/您的域名。After extracting, you will get an executable file namedanqicms(or any binary filename you define), as well asconfig.jsonconfiguration files,templateandpublicdirectories.

Ensure that MySQL database is installed and running on your server, and that the database and user with sufficient permissions required by AnQiCMS have been created. When running AnQiCMS for the first time, you need to enter the installation directory of AnQiCMS via the command line and directly execute./anqicmsAfter the program starts, access your server IP address plus port number through the browser (for examplehttp://服务器IP:8001),AnQiCMS will guide you through the database connection, administrator account setup, and site information initialization. After the initialization is complete, you can close the current command line process.

Configure Nginx or Apache reverse proxy

Since AnQiCMS runs on a specific port by default, and users usually access the website through standard HTTP/HTTPS ports (80/443), it is necessary to configure Nginx or Apache as a reverse proxy.Reverse proxy is responsible for forwarding user requests to the port that AnQiCMS is listening on, and returning AnQiCMS's responses to the user.

For Nginx servers, you can add a configuration similar to the following in the site's configuration file:

server {
    listen 80;
    server_name www.yourdomain.com; # 替换为您的域名
    root /www/wwwroot/yourdomain.com/public; # 替换为您的AnQiCMS public目录

    location @AnqiCMS {
        proxy_pass http://127.0.0.1:8001; # AnQiCMS监听的端口
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    error_page 404 =200 @AnqiCMS;
    location / {
       try_files $uri $uri/index.html @AnqiCMS;
    }

    # 其他Nginx配置,例如SSL、日志等
    access_log /var/log/nginx/yourdomain.com_access.log;
    error_log /var/log/nginx/yourdomain.com_error.log warn;
}

If you are using Apache server, you can configure it bymod_proxyAdding the following content to your site's virtual host configuration file:

<VirtualHost *:80>
    ServerName www.yourdomain.com # 替换为您的域名
    DocumentRoot /www/wwwroot/yourdomain.com/public # 替换为您的AnQiCMS public目录

    ProxyRequests Off
    ProxyPreserveHost On
    ProxyVia On

    <Proxy *>
        Require all granted
    </Proxy>

    # 将所有请求转发到AnQiCMS监听的端口
    ProxyPass / http://127.0.0.1:8001/
    ProxyPassReverse / http://127.0.0.1:8001/

    ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log
    CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined
</VirtualHost>

After the configuration is completed, please make sure to restart the Nginx or Apache service to make the configuration take effect.

Several methods to monitor the AnQiCMS process

Now, let's discuss how to reliably protect the AnQiCMS process without the Taota面板.We will introduce several solutions, ranging from simple to complex, suitable for different needs and operation and maintenance experience scenarios.

Plan one: Use Crontab with Shell script (Basic Guardian)

install.mdThe document mentions the use ofcrontabwithstart.shScript to guard AnQiCMS process, which is a simple and easy basic guard method.

  1. Create a startup scriptstart.sh:Create a directory named under the AnQiCMS installation directory,start.shThe file, and give it execution permissions. The script is used to check if the AnQiCMS process is running, and if not, start it. The script content should be similar to:

    #!/bin/bash
    ### check and start AnqiCMS
    # author fesion
    # the bin name is anqicms
    BINNAME=anqicms
    BINPATH=/www/wwwroot/anqicms # 替换为您的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
    

    Please note, thatBINPATHThe variable is replaced with your actual AnQiCMS installation path.

  2. Configure Crontab scheduled tasks:Edit the system's Crontab tasks,start.shThe script runs once every minute.

    crontab -e
    

    Add a line to the open editor:

    */1 * * * * /www/wwwroot/anqicms/start.sh # 替换为您的start.sh脚本的完整路径
    

    Save and exit the editor. The system will check the AnQiCMS process every minute and automatically start it when it stops.

Advantages:Configuration is simple and easy to understand.Disadvantages:Cannot restart immediately when AnQiCMS crashes, there is a delay of about one minute.Log management is relatively simple, and cannot track the process status in detail.For production environments with high availability requirements, this method is not ideal.

Plan two: Use Systemd (recommended production environment guardian solution)

Systemd is a modern Linux distribution (such as CentOS78, Ubuntu 16.04+)中默认的系统和服务管理器,它提供了一套强大且成熟的服务管理机制,能够实现进程的自动启动、崩溃重启、日志管理等功能,是生产环境守护AnQiCMS进程的**选择**。

  1. Create a systemd service file:In/etc/systemd/system/in the directoryanqicms.serviceThe file is used to define the AnQiCMS service.

    sudo vim /etc/systemd/system/anqicms.service
    

    The file content should be similar to:

    ”`ini [Unit] Description=AnqiCMS Service After=network.target # 在网络服务启动后启动

    If AnqiCMS depends on MySQL, you can add After=mysql.service here

    [Service] Type=simple # Process type is simple service WorkingDirectory=/www/wwwroot/anqicms # Replace with your AnQiCMS installation path ExecStart=/www/wwwroot/anqicms/anqicms # Replace with the full path to your AnQiCMS executable file Restart=always # Always restart, regardless of normal exit, abnormal exit, signal exit, etc. RestartSec=3 # Wait for 3 seconds before restarting User=www # It is recommended to run AnqiCMS with a non-root user, such as the www user Group=www