Sex film, has exposed the problem of Chinese sex, I code farmers at a loss; On the operating system side, the results are also lackluster; Today’s cool Web monitoring tools have robbed many developers of their ability to really deal with the problem.

The closer you get to the bottom, the closer you get to the truth, and the same applies in the computer world.

Our goal, like cast Away, is to find a way to survive in the most brutal environment. It’s a subtle way of saying it: You change companies, your new company is devOps friendly, and you have to deal with it on your own.

It sounds like saving the world, but the articles in this series are not very deep, and many of them have been seen in the operating system of the university, although they don’t arouse your interest in reading the textbook.

If this series piques your interest at all, then it’s done its job. Originally wanted to talk more carefully, but due to the time is limited, and not to write a book, the original rational things do not say more.

content

This article will try to solve the problems of Cpu, Mem, Net, Disk and IO, and then combine various elements to solve some difficult problems, which is the combination of some common commands. Of course we’re Java, so we’ll talk a little bit more about Java. If you are not familiar with the style of writing, you can first read: “Java out-of-heap memory Troubleshooting: Little sister taste”.

Why do Linux systems have these and other problems? The main reason is the uneven speed of the various parts of the computer. The Cpu is waiting for the cache line, the cache is waiting for the memory, and the memory is waiting for the device. It is like setting up a tollbooth at a downhill intersection of a 17-kilometer highway.

There are a variety of devices, usually we contact with the device, is hard disk and network card. The entire business system and operating system are filled with various buffers, and the CPU is responsible for coordinating them through interrupts. In this way, there are many places where bottlenecks can occur.

Monitoring value

Troubleshooting is a process. Generally, when focusing on a hardware resource, such as CPU, we pay attention to the following basic elements: 1) Utilization is generally instantaneous, which belongs to the sampling range and is used to determine whether there is a peak. Saturation usually means that the resource is fully used and new requests are queued in a specific queue. For example, the CPU load is too high. 3) Error information hardware or driver error, such as OOM displayed by dmesg command. 4) Association information. For example, the system response is slow and swap is used a lot

why

Monitoring value is only a kind of appearance, the specific cause is the focus. We usually expect failures caused by pure resource constraints to be easier to locate. Most of the time they’re not so lucky, so sharing information on a broad scale can help a lot. The process is as follows:

1) Information collection problem start time, context 2) Change set list of all changes before the problem occurred 3) Problem abstraction Abstraction of description into a specific resource problem 4) Problem troubleshooting Once the information is sorted out, it’s time for a real wilderness trip

test

This quiz is used to determine if you are the intended audience for this article. If you cannot answer the following questions, it is recommended to read a little basic Linux knowledge first. This will save you time since the article will not cover much about it.

  • What does “I wait” mean?
  • What partition is swap and how to close it?
  • What is special about the/TMP directory?
  • What is a pipe?

Linux distributions

Let’s warm up and see what Linux distributions are available.

I personally use ArchLinux the longest, especially for its rolling upgrade feature. However, because Centos has such a large share of the server market, the following discussion is based on Centos.

According to incomplete statistics, there have been thousands of Linux version, see below (see clearly the figure high distrowatch.com/images/othe…). . You tell me where the red flag and kylin are.

Add common scripts to PATH

Some command combinations are hard to remember, and frequent typing is annoying. You can script these processes and throw them into your path.

Remember the environment variables you added when you first installed the JDK? Linux is similar, but there are multiple shells.

We usually use bash, and shell scripts are bash scripts. But there are plenty of other good shells out there, like CSH, KSH, ZSH, etc.

Look at the /etc/shells file to see what shells you have installed

[root@localhost ~]$ cat /etc/shells
/bin/sh
/bin/bash
/bin/zsh
/sbin/nologin
/bin/dash
Copy the code

In the personal realm, ZSH works best with oh-my-zsh (recommended), but the server generally doesn’t change your shell and can see the shell terminal you’re currently using through an environment variable.

[root@localhost ~]$ echo $SHELL
/bin/bash
Copy the code

For bash, our configuration is in the.bashrc file in the user directory.

Create it in the user directory.bindirectory

mkdir ~/.bin
Copy the code

Add the directory to the environment variable PATH

echo "export PATH=\$PATH:~/.bin/" >> ~/.bashrc
Copy the code

Create a file XJJ in.bin that says echo “Pleasant taste”

cat > ~/.bin/xjj <<EOF
echo "pleasant taste"
EOF
Copy the code

Add executable permissions to XJJ

chmod a+x ~/.bin/xjj 
Copy the code

This way, you can execute XJJ anywhere with your users

[root@localhost ~]$ xjj
pleasant taste
Copy the code

What a pleasant smell