Common Operations and Commands

Last updated: 2020-02-25 12:02:43

PDF

1. What is Linux Server Load Average?

Load is used for measuring the workload of server, i.e. the length of the queue of tasks to be executed by CPU of the computer. The greater the value, the more processes that are currently running or waiting to be executed.

2. How can I check Linux server load?

You can execute the w , top , uptime , procinfo Command, or Access /proc/loadavg To view the file.
Please refer to "Installing Software in Linux Environment" for the instructions on how to install procinfo tool.

3. What can I do when the server load is too high?

The server load (Load/Load Average) is displayed according to the length of the process queue. When there is a high load on the server (it is recommended to take the aPCge of 15 minutes as a reference), it may be due to insufficient CPU resources, read and write bottlenecks, insufficient memory resources, and intensive computing in CPU. Recommended use vmstat , iostat , top Command to determine the cause of the overload, and find a specific process that takes up a lot of resources to optimize.

4. How can I check server memory usage?

You can execute the free , top (after execution, you can pass the shift+m Sort memory), vmstat , procinfo Command, or Access /proc/meminfo To view the file.

5. How can I check the memory occupied by a single process?

You can execute the top -p PID , pmap -x PID , ps aux|grep PID Command, or Access /proc/$process_id(PID of the process)/status View the file, for example, the / proc/7159/status file.

6. How can I check services and ports that are in use?

You can execute the netstat -tunlp , netstat -antup , lsof -i:PORT Command to view.

7. How can I check server process information?

You can execute the ps auxww|grep PID , ps -ef , lsof -p PID , top -p PID Command to view.

8. How can I stop the process?

You can execute the kill -9 PID (PID represents the process number), killall Program name (for example, killall cron) to stop the process.
If you need to stop the zombie process, you need to kill the parent process of the process, with the following command: kill -9 ppid (ppid is the parent process ID number, which can be accessed through the ps -o ppid PID Command to find, for example, ps-o ppid 32535).

9. How can I find a zombie process?

You can execute the top Command to view the total number of zombie process (zombie), by executing ps -ef | grep defunct | grep -v grep Find information about specific zombie processes.

Why can't server port be enabled?

Enabling and listen-in of server port need to be checked from operating system itself and the application.
Port below 1024 can only be enabled by root users on the Linux operating system. This means that you need to run sudo su first to obtain root permission before enabling the server port.
For any problem with application, it is recommended to use application startup log to identify reasons for failure, for example, port conflict (port used by Tencent server system cannot be occupied, such as 36000), configuration problem, etc.

11. What are the commands commonly used for checking the performance of a Linux server?

Command name Description
top Process monitoring commands are used to monitor the overall performance of the system. Can display system load, processes, CPU, memory, paging and other information, commonly used shift+m and shift+p to sort processes by memory and CPU usage.
vmstat System monitoring commands, focusing on virtual memory, can also monitor CPU, processes, memory paging and IO status information. For example, vmstat 3 10 outputs the result every 3 seconds and executes it 10 times.
iostat A tool for outputting CPU status and IO status, which can display the IO information of the system in detail. For example, iostat-dxmt 10 outputs IO details in MB format every 10 seconds.
df Used to check the disk space usage of the system. For example: df-m, which shows the disk usage in units of MB.
lsof Enumerate the files that are opened in the system, because Linux is based on the file system, this command is very helpful in system administration. For example: lsof-iroot 36000 displays the process lsof-u root, using port 36000 shows the program running in root lsof-c php-fpm, shows the file opened by the php-fpm process lsof php.ini, shows the process that opened php.ini.
ps The process view command can be used to display the details of the process. The common combination of command parameters is that ps-ef,ps aux, recommends using ps-A-o to customize the output field. For example: ps-A-o pid,stat,uname,%cpu,%mem,rss,args,lstart,etime\

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

# 12. What can I do when Cron does not work?

The trouble-shooting procedures are as follows:

1) Verify whether crontab is running normally.

  1. Execute crontab -e Command, add the following test entries.
 \*/1 \* \* \* \* /bin/date >> /tmp/crontest 2>&1 &
  1. Observation /tmp/crontest File.
    In case of any problem, it is recommended to use ps aux | grep cron to look for pid of cron and use kill-9 PID to terminate cron process, and then restart cron with / etc/init.d/cron start.

2) Verify whether the script path in the cron entry is an absolute path.
3) Check whether the user account for cron execution is correct, and check whether the account is included in / etc/cron.deny.
4) Check the execution permission of the script, script directory and log file permission.
5) It is recommended to run the script in background. Append a "&" to the script entry, for example, * / 1 * * * * / bin/date > > / tmp/crontest 2 > & 1 &

13. How can I set startup task for CVM?

Linux kernel startup procedure is as follows:

  1. Start /sbin/init Process.
  2. Execute the initial init script in turn.
  3. Run-level script /etc/rc.d/rc\*.d , The * value is equal to the operation mode. You can go to /etc/inittab to view details.
  4. Execute /etc/rc.d/rc.local .

The configuration of startup task can be made in S * * rclocal file under / etc/rc.d/rc *. D, or in / etc/rc.d/rc.local.

Why is server hard drive read-only?

Common reasons for read-only hard disk are as follows:

  • Disk space is full
    You can use df-m command to check the disk usage, and then delete unnecessary files to free disk space (Deletion of non-third party files is not recommended. Please verify it if required);

2) Disk inode resources are all occupied
You can execute the df -i Command to view and confirm the related process.

  • Hardware failure.

If hosting application is still unable to identify the reason using the above methods, please call the hot-line 4009100100 or submit ticket for assistance in locating.

15. How can I view Linux system logs?

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

16. How can I find large files in file system?

You can find it by performing the following steps:

  1. Execute df Command to view disk partition usage, such as df-m.
  2. Execute du Command to view the size of the specific folder. For example, du-sh. / *, du-h-- max-depth=1 |head -10。
  3. Execute ls Command to list files and file sizes, such as ls-lSh.
    In addition, you can also directly check the size of files under specific directory by using find commands, for example, find /-type f-size + 10m-exec ls-lrt (B);

17. How can I check the version of server's operating system?

You can view the system version by executing the following command:

  • Uname-a
  • Cat / proc/version
  • Cat / etc/issue

18. Why does the Linux terminal display Chinese garbled?

The server itself does not impose restrictions on the display language. If the display of Chinese is affected by the terminal software, you can try to adjust OPTIONS -> Session Options -> Appearance (secureCRT settings; please search for relevant settings for software of other versions.)
If the unreadable codes appear in pure Linux shell, please use export command to check settings for user environment variables and such environment variables as LANG and LC_CTYPE.

How to set up time-out for connection to CVM through SecureCRT?

When SecureCRT connects to Cloud Virtual Machine, you can continue to open the connection through the following settings:

  1. Open [SecureCRT option (Options)].
  2. Select [Session option (Session Opetions)], and click "Terminal (Terminal)".
  3. In the Anti-idle box on the right, check [send Protocol NO-OP (Send protocol NO-OP)] and set the time to every 120 seconds (every 120 seconds).

Why isn't disk space freed after a file on Linux server is deleted?

Cause

Log in to the Linux server and execute rm After the command deletes the file, execute df Command to check the hard disk space, you may find that there is no increase in the available hard disk space after deleting the files. The reason is that when passed rm When the command deletes the file, there are other processes in the process of Access the file, if you execute the df Command to view, the deleted files will take up space that is not immediately released.

Solution:

  1. Execute using root Permission lsof |grep deleted Command to view the PID of the process that is using the deleted file.
  2. By command kill -9 PID Just kill the corresponding process.