What is the exact step to find port conflict of AnQiCMS process using the `lsof -i:{port number}` command?
As an experienced CMS website operation person in the security industry, I know that the stable operation of the website is of great importance.Port conflicts are often encountered during the initial deployment or multi-site management, which can cause the AnQiCMS service to fail to start or be inaccessible.Understand how to accurately diagnose and resolve such issues, which is crucial for ensuring the normal operation of your website.
common scenarios of port conflict
AnQiCMS default usage8001Port. A port conflict occurs when other services (such as other web applications, database services, test services, etc.) on the server already occupy the port required by AnQiCMS, or when you try to deploy multiple AnQiCMS instances on the same server without assigning different ports to them.This usually manifests as AnQiCMS service startup failure, or even if it shows "Startup successful", the website cannot be accessed through the browser.
steps to identify and resolve AnQiCMS port conflict
To accurately locate and resolve the port conflict of the AnQiCMS process, we need to use the Linux system'slsofcommand.lsof(list open files)is a powerful tool that can list information about the open files of the current system, including network connections.
Determine potential conflicting ports
Firstly, you need to specify the port that AnQiCMS expects to use. In most cases, the default port is8001. If you have manually modified the AnQiCMS configuration file (for exampleconfig.json) Specify other ports or configure the specific port when deploying through tools like Baota panel, 1Panel, etc., and make sure to use the actual port number to query.
ExecutelsofCheck the port usage status of the command
In the SSH terminal, use the following command to check the occupancy status of a specific port:
lsof -i:{端口号}
For example, to check the default:8001Port, you will enter:
lsof -i:8001
The meaning of this command is:
lsof: List the opened files.-i: Filter internet files.:{端口号}: Specify the port number to query.
Analyze the command output result
After the command is executed, if the port is being used, you will see an output similar to the following:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
anqicms 7621 root 3u IPv4 70347 0t0 TCP *:8001 (LISTEN)
The key information in the output includes:
COMMAND: The program name currently using this port. In the AnQiCMS scenario, this will usually display asanqicmsOr another custom service name.PID: The process ID occupying this port. This is the core information you need for your next operation.USER: The user running the process.NAME: Displayed the port number and connection status (for example*:8001 (LISTEN)Indicates that port 8001 is listening
If the output is empty, it means that the port is currently not occupied by any process, and you can safely let AnQiCMS use the port.
Resolve port conflict
After you confirm the process occupying the port required by AnQiCMS, what are the several ways to resolve the conflict:
Terminate the conflicting processIf the port is not occupied by an AnQiCMS process, and the process is not a core system service, you can choose to terminate it. Use
kill -9 {PID}Command to force the termination of a process. For example, if the PID is7621, the command will be:kill -9 7621Note:
kill -9This is a forced termination command, please use it with caution, make sure you understand the effect of the terminated process, and avoid killing important system services. If you are not sure, please seek professional assistance.Change the listening port of AnQiCMS: This is the recommended method, especially when another important service is using the port. You can modify the AnQiCMS configuration file (usually
config.jsonSpecify a new, unused port. For example, to change"port": 8001is modified to"port": 8002. If deployed through Docker, BaotaGo project, or other methods, you need to reconfigure the listening port of AnQiCMS on the deployment interface and make sure that the corresponding reverse proxy is also updated to the new port.Change the listening port of other services: If AnQiCMS must use a specific port (such as for SEO or URL consistency), and another service is using the port, and the service allows port configuration, you can try to change the port of the service.
Verify the solution
After taking the aforementioned measures, restart your AnQiCMS service. Then, use it again.lsof -i:{端口号}Confirm the command to check if AnQiCMS has successfully listened on the target port, and try to access your website through a browser to ensure everything is normal.
Frequently Asked Questions (FAQ)
1.config.jsonWhere is the file? How do I modify the listening port of AnQiCMS?
config.jsonIt is the core configuration file of AnQiCMS, usually located at the root of the AnQiCMS installation directory. You can log in to the server using SSH, and usecd /path/to/anqicmsEnter your AnQiCMS installation directory and then usevi config.jsonornano config.jsona text editor to make changes. Find"port"the field and change its value to an unused port number (for example8002), then save and exit. After modification, AnQiCMS needs to be restarted for the new configuration to take effect.
2. How can I run multiple AnQiCMS instances on the same server without port conflicts?To run multiple AnQiCMS instances on a server, each instance must listen on a unique port. You need to set a unique port for each AnQiCMS instance:
- Allocate an independent installation directoryDeploy AnQiCMS code to a different folder.
- modify
config.jsonIn each instance'sconfig.jsonIn the file, will"port"Change the field to a different, unused port (for example, the first instance uses8001, the second uses8002and so on). - Configure reverse proxyIf you access these AnQiCMS instances through a domain, you need to configure a reverse proxy for each instance on the web server (such as Nginx or Apache), to forward requests to different domains or subdirectories to the different ports that the corresponding AnQiCMS instance is listening on.
What are the consequences if I mistakenly killed the wrong process?
kill -9The command will forcibly terminate a process without giving it a chance to clean up or save data.If an important system service (such as SSH service, database service, or the web server itself) is mistakenly killed, it may cause abnormal system functionality, data loss, or even prevent the server from being remotely connected.Therefore, in usingkill -9Please check carefully before that.COMMANDandPIDMake sure you are terminating the correct and harmless process. If you are not sure, it is best to choose to modify the port of AnQiCMS or seek help from the system administrator.