Foreword
Only the head can become strong.
Text has been included to my GitHub repository, welcome Star: github.com/ZhongFuChen...
Prior he wrote, " in the company doing the project in the school and their own do what's the difference? "Do not know if you do not have the impression, which refers to the job may take on a Linux server, view some of the information (in particular, check the log to find Bug).
I had Linux courses in college, also done during the Linux-related notes:
However, completion of the school, did not ye practice hand (or too dishes), go to the company can be said to forget all the light. This article is mainly to review previous notes, and record it in the work of some of the more commonly used commands.
- I'm sure this is my current dimensions to consider, and I work long relatively short, so there may be a lot of command ignored, please add in the comments area
I. View Log
Online there is a problem, check the log to board machine line is very common in the operation. The first time I boarded the online machine check log, I also remember the following few commands (we assume now called the log file service.log
):
cat service.log
tail -f service.log
vim serivice.log
- (Obviously not enough)
Now log daily output of about the size of 1GB:
If the file is small, then a simple cat
command can still cope with, but if you directly cat
open a 1GB log file command to ensure that you get stuck ( ctrl + c
exit cat
command takes a long time to be cat
a command to stop).
- I usually just use
cat
what to see this small text file is
Likewise, if the file is small, simple vim
command to open a file is manageable, but if you use vim
the command to open a 1GB or even larger files, and can obviously feel the slow and Caton.
I usually like to use vim
to find the corresponding record, I generally operations:
vim service
- Press
G
jump to the end of the file - Press
?
+ keyword search corresponding record - Press
n
up inquiries, pressN
inquiries down
tail -f service.log
This command is used to view the traffic if I generally come in (or when debugging log can be seen directly, then quickly ctrl +c
turn off)
Face relatively large log files, with which we have to grep
play, and such as we now know a phone number can not receive SMS verification code, you want to look at the phone number of the log is kind of how. So we can do this:
cat service.log | grep 13888888888
Such a practice, you can be service.log
all contained 13888888888
records to search out, speed is really fast search of.
Now that we have been able to search based on keywords corresponding to the record, and then I want to see the log context of that record [so that you know about the status of the implementation of this data]
First of all, we need to identify the row number of the corresponding record in the cat
command followed by a -n
parameter just fine. So the command is: cat -n service.log | grep 13888888888
, as shown we can be found in the corresponding line number
Now the number of lines is 29506, we generally just look at the first 10 rows and 10 rows back 29506 of almost know where the problem, so we can do this:
sed -n "29496,29516p" service.log
: Start retrieving the line from 29496 to 29516 end of linecat -n service.log | tail -n +29496 | head -n 20
: From 29496 start retrieving the line, to push forward 20
If the keyword is not accurate (too much of the logging output), we can use the more
command to browse or output to a file and then analysis:
cat service.log | grep 13 |more
: The result of the inquiry referred to more outputcat service.log | grep 13 > /home/sanwai/aa.txt
The result of the query is written/home/sanwai/aa.txt
on the file
Sometimes, we want to count how many rows this log output, we can use this command:
cat service.log | wc -l
References:
Second, the investigation process and port
The investigation process has two commands:
ps -ef
ps aux
These two commands are listed all the processes, or through our |
pipeline and grep
to filter out processes you want to check, for example:ps -ef |grep java
The check out process Why? Know the process ID, we can put him to kill.
kill -9 processId
: Kill a process
Check the port is also a very common operation, common commands: netstat -lntup
:
l:listening n:num t:tcp u:udp p:display PID/Program name for sockets
查看当前所有tcp/udp端口的信息
复制代码
View a port details:lsof -i:4000
Third, view the status of the system
3.1 TOP real-time view of the status process
TOP command to check the status of the process, which has a load average may not be so easy to understand, explain the following:
load average: within a specific time interval run queue (running on the CPU or waiting for how many processes running) the average number of processes .
load average has three values, representing: 1 minute, 5 minutes, 15 minutes The average number of processes running within the process queue.
- The average number of processes running processes + ready and waiting for the process to run at a specific time (1 minute, 5 minutes, 10 minutes) of
Linux process can be divided into three states:
- Blocking process
- The process can be run
- Running processes
For example, the system now has two running processes, three processes can run, then the system load is 5, load average is the number of load within a certain time mean .
3.2free view memory usage
thinking of linux memory management mechanisms include (can not say that) memory utilization is maximized , the kernel will the remaining memory application is cached , and the cached does not belong to free category.
If not enough free memory, the kernel will partially cached in memory recovery , recovered memory reallocation to the application. So for linux system, memory available for allocation is not only free memory, further comprising a cached memory (in fact, further comprising buffers).
- Available memory = free memory + buffers + cached memory
Buffer Cache and Page Cache. The former disk blocks for reading and writing, which read and write file for the inode. These Cache effectively shortening the time I / O system calls (such as read, write, getdents) of. Operation of the disk has a logic level (file system) and a physical level (disk block)
References:
At last
I work for a relatively short length of time, so there may be a lot of command ignored, please add the more commonly used commands in the comments area. If you follow some commands more important, I would like to share ha ~
Willing output of dry cargo of Java technology public number: Java3y . A public number more than 200 original articles technical articles, massive video resources, beautiful mind map, attention can get!
I think the article is well written, points praise !