Common operations and commands of linux server (a must-see for basic posts)

table of Contents

1. What is the load average of linux servers?
2. How to check the linux server load
3. What should I do if the server load is high?
4. How to check the server memory usage?
5. How to check the memory size occupied by a single process?
6. What should I do if I cannot log in to server B from linux server A?
7. How to check the service and port being used?
8. How to view server process information?
9. How to kill the process?
10. How to find zombie processes?
11. How to transfer data between intranet servers?
12. Why can't I start the server port?
13. What are the commonly used commands for viewing Linux server performance?
14. What should I do if Cron does not take effect?
15. How to set up the opensuse server startup task?
16. Why is the server hard disk read-only?
17. How to view the linux system log?
18. How to find large files in the file system?
19. How to check the server operating system version?
20. How to restart the server?
21. Why are there garbled characters in Chinese when the Linux terminal displays?
22. How to set the timeout period for connecting to the CVM server through SecureCRT?
24. How to get root privileges of CVM?
25. Why is the hard disk space not released when deleting files on the linux server?

Attached to the end of the article is the advanced learning materials for Linux server development

1. What is the load average of linux servers?

Load is used to measure the size of the server workload, that is, the length of the computer's cpu task execution queue. The larger the value, the more the number of processes including running and waiting to run.

2. How to check Linux server load

It can be viewed through w, top, uptime, procinfo commands, or through the /proc/loadavg file.

3. What should I do if the server load is high?

Server load (load/load average) is displayed based on the length of the process queue. When the server has a high load (it is recommended to use the 15-minute average as a reference), it may be caused by insufficient CPU resources, I/O read and write bottlenecks, insufficient memory resources, etc., or it may be due to CPU intensive calculations. . It is recommended to use the vmstat -x, iostat, and top commands to determine the cause of the excessive load, and then find the specific process that takes up a lot of resources for optimization.

4. How to check the server memory usage?

You can use free, top (you can sort the memory through shitf+m after execution), vmstat, procinfo commands, or you can view it through the /proc/meminfo file.

5. How to check the memory size occupied by a single process?

You can use the top -p PID, pmap -x PID, ps aux|grep PID commands, or you can view it through the /proc/$process_id (PID of the process)/status file, such as the /proc/7159/status file.

6. What should I do if I cannot log in to server B from linux server A?

Developers should first confirm that servers A and B belong to the same application, and different applications cannot cross login.

  1. When server A cannot log in to server B, you can use the ping IP and telnet IP 36000 commands to confirm whether server B is down and whether the ssh service is normal. If there is an abnormality, log in to the open.qq.com management center to restart the server (for detailed operation instructions, see: CVM_V2 Application and Management#3.2 Server Restart).
  2. If you can directly access server B through the client, but cannot log in to server B from server A, please contact the operation and maintenance support through enterprise QQ to assist in positioning.

7. How to check the service and port being used?

You can use netstat -tunlp, netstat -antup, lsof -i:PORT commands to view.

8. How to view server process information?

You can use ps auxww|grep PID, ps -ef, lsof -p PID, top -p PID commands to view.

9. How to kill the process?

You can use kill -9 PID (process number), killall program name (such as killall cron) to kill the process. If you want to kill a zombie process, you need to kill the parent process of the process to have an effect, the command is: kill -9 ppid (ppid is the parent process ID number, you can find it through ps -o ppid PID, for example, ps -o ppid 32535).

10. How to find zombie processes?

You can use the top command to view the total number of zombie processes, and use ps -ef | grep defunct | grep -v grep to find information about specific zombie processes.

11. How to transfer data between intranet servers?

Different machines under the same application can use the following command to realize file transfer:
scp -P port (using port 36000) /home/user/localfilename (local file path) user (using appid) @serverip:/home/user/removefilename( Target file path)
rsync -e'ssh -p port (using port 36000) -q' /home/user/localfilename (local file path) user (using appid) @serverip:/home/user/removefilename (target file path)

12. Why can't I start the server port?

The startup monitoring of the server port needs to be viewed from the operating system itself and the application. Ports below 1024 in the Linux operating system can only be started by the root user, that is, you need to run sudo su-get root privileges before enabling the service port. For application issues, it is recommended to use the application startup log to troubleshoot the reasons for the failure, such as port conflicts (the port used by the Tencent server system cannot be occupied, such as 36000), configuration issues, etc.

13. What are the commonly used commands for viewing Linux server performance?

Insert picture description here

Other commonly used commands and files, free -m, du, uptime, w, /proc/stat, /proc/cpuinfo, /proc/meminfo.

14. What should I do if Cron does not take effect?

The troubleshooting steps are as follows:

  1. Confirm whether crontab is running normally. You can run the command crontab -e to add the following test entries */1 * * * * /bin/date >> /tmp/crontest 2>&1 &, and then observe the /tmp/crontest file. If there is a problem, it is recommended to use ps aux|grep cron to find the pid of cron, kill -9 PID to end the cron process, and then restart cron through /etc/init.d/cron start.
  2. Confirm that the script path in the cron entry is an absolute path.
  3. Check whether the user account running cron is correct, and check whether this account is included in /etc/cron.deny.
  4. Check the execution permissions of the script, the script directory and the file permissions of the log.
  5. It is recommended to run the script in the background and add "&" after the script entry, for example, */1 * * * * /bin/date >> /tmp/crontest 2>&1 &

15. How to set up the opensuse server startup task?

The boot sequence of the Linux kernel is: /sbin/init process is started, and then the init initial script is executed in turn, the run level script /etc/rc.d/rc*.d, the number value is equal to the run mode, which can be viewed in /etc/inittab, The last is /etc/rc.d/rc.local.
If you need to configure the boot task, you can configure it in
the S**rclocal file in /etc/rc.d/rc.d or in /etc/rc.d/rc.local.

16. Why is the server hard disk read-only?

The common reasons for hard disk read-only are as follows:

  1. If the disk space is full, you can use the df -m command to check the disk usage, and then delete the extra files to free up the disk space (non-third-party files are not recommended to be deleted, if necessary, please contact the enterprise QQ for confirmation);
  2. The disk inode resources can be viewed through the df -i command when the disk inode resources are occupied to confirm the related processes;
  3. hardware malfunction.
    If the hosting application still cannot confirm the reason through the above methods, please contact the operation and maintenance support through the enterprise QQ to assist in the positioning.

17. How to view linux system log?

The storage path of system-level log files is /var/log. The commonly used system log is /var/log/messages.

18. How to find large files in the file system?

You can first check the disk partition usage through the df command, such as df -m; then: check the size of the specific folder through the du command, such as du -sh ./*, du -h --max-depth=1|head -10 ; Use the ls command to list the files and their sizes, such as ls -lSh; in addition, you can also use the find command to directly view the file sizes in a specific directory, such as find / -type f -size +10M -exec ls -lrt {};

19. How to check the server operating system version?

You can check the system version with the following commands: uname -a, cat /proc/version, cat /etc/issue

20. How to restart the server?

Method 1: Log in to the open.qq.com management center to restart the server (for detailed operation instructions, see: CVM_V2 Application and Management#3.2 Server Restart).
Method 2: If method 1 does not take effect, you can try to restart the server by running the reboot command as root.

21. Why are there garbled characters in Chinese when the Linux terminal displays?

The server itself does not have restrictions on the display language. If the terminal software affects the Chinese display, you can try to adjust the option-session option-appearance (secureCRT settings, other versions of software, please find the relevant settings); if it is a pure Linux shell, please use The export command is used to view user environment variables, and to view the environment variable settings such as LANG and LC_CTYPE.

22. How to set the timeout period for connecting to the CVM server through SecureCRT?

The following settings can be used to make SecureCRT connect to the CVM without disconnecting the connection: open the secureCRT option (Options), select the session option (Session Opetions), click on the terminal (Terminal), and tick the Anti-idle box on the right Select Send protocol NO-OP (Send protocol NO-OP), and set the time to every 120 seconds (every 120 seconds).

24. How to get root privileges of CVM?

For details, please refer to: root permission description.

25. Why is the hard disk space not released when deleting files on the linux server?

Phenomenon: Log in to the linux server, execute the rm command to delete the file, and use the df command to check the hard disk space. After deleting the file, the available hard disk space does not increase. Reason: When deleting a file through the rm command, if another process happens to be accessing the file, through the df command, the space occupied by the deleted file is not released immediately. Solution: Execute lsof |grep deleted with root privileges to view the PID of the process that is using the deleted file, and kill the corresponding process with the command kill -9 PID.

Linux background server development technology video:
Insert picture description here

Linux background server development technology e-book:
Insert picture description here
follow a wave and go, friends who need advanced Linux information can add to my group: 832218493
if the reply is not timely, I hope to forgive me!

Guess you like

Origin blog.csdn.net/lingshengxueyuan/article/details/110929932